Skip to content

[Example] [VLM] Gemma3n #1696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

[Example] [VLM] Gemma3n #1696

wants to merge 10 commits into from

Conversation

kylesayrs
Copy link
Collaborator

Will open once a configuration is found that yields best accuracy recovery

kylesayrs added 10 commits July 30, 2025 16:29
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @kylesayrs, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces initial support and an example for the Gemma3n multimodal model, focusing on its quantization capabilities. To facilitate this, I've made several foundational improvements to the internal AST-based auto-wrapping and PyTorch tracing pipeline, enhancing robustness, error reporting, and compatibility with advanced Python features and model architectures.

Highlights

  • New Model Example: I've added a new example script (examples/multimodal_vision/gemma3n_example.py) demonstrating how to quantize the google/gemma-3n-E2B-it multimodal model using GPTQ (W4A16 scheme). This script includes a multimodal data collator and a sample generation to confirm the quantized model's functionality.
  • Improved AST Auto-Wrapping: The internal AST auto-wrapper has been enhanced to handle more complex Python constructs. Specifically, it now correctly preserves the can_return_tuple decorator and forces wrapping of if statements that contain walrus operators (:=), preventing issues during static analysis and tracing.
  • Enhanced Debugging for Autowrapped Code: I've implemented a new context manager (append_autowrap_source_on_fail) that significantly improves debugging for errors occurring within autowrapped code. When an exception is raised, the traceback will now include the specific autowrapped source code snippet, with the failing line annotated, making it much easier to diagnose issues.
  • Refined PyTorch Tracing: The tracing process for PyTorch models has been refined to better handle wrapped root functions. This includes explicitly unwrapping the model's forward method and patching both the instance and class forward attributes, ensuring compatibility with torch.fx.GraphModule.
  • Tracing Ignore List Update: The _TRACING_IGNORED_FUNCTIONS list in src/llmcompressor/args/dataset_arguments.py has been updated to include project_per_layer_inputs, which is likely necessary for successful tracing of new model architectures like Gemma3n.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@kylesayrs kylesayrs changed the title [Example] Gemma3n [Example] [VLM] Gemma3n Jul 31, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for the Gemma3n model, including a new example script for one-shot quantization. To support this new model, the core sequential pipeline logic has been enhanced. Key improvements include more robust AST wrapping to handle new Python syntax (like the walrus operator) and specific decorators, and significantly better error reporting for dynamically generated code during tracing. The tests have been updated to cover these new capabilities. The changes improve the framework's robustness and debuggability.

Copy link

👋 Hi! Thank you for contributing to llm-compressor. Please add the ready label when the PR is ready for review.

Note: This is required to complete the testing suite, please only add the label once the PR is code complete and local testing has been performed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant