Skip to content

[Autowrapper] Support Gemma3, autowrapper improvements #1693

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

kylesayrs
Copy link
Collaborator

@kylesayrs kylesayrs commented Jul 30, 2025

Purpose

  • Support Gemma3 and models which have similar implementations in their model definitions

Changes

  • Handle source code which uses the walrus operator within if statements
  • Previously, all function decorators were removed from definitions. However, HF uses some function wrappers which have very subtle effects on kwarg passing such as can_return_tuple. These decorators must be kept
  • Improve debugging for autowrapped code
    • Fix tracebacks, now failures within autowrapped code will include which line they failed on
    • Add util function append_autowrap_source_on_fail which appends the entire autowrapped source upon fail
  • Add project_per_layer_inputs to list of ignored functions for tracing

Testing

  • Added gemma3n text and vision tests
  • Added walrus operator test to autowrapping tests

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.

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 primarily focuses on extending model compatibility, specifically for Gemma3, and enhancing the stability and debuggability of the autowrapper. The changes include refining how the autowrapper processes Python code constructs, improving error reporting for tracing failures, and resolving potential conflicts with offloaded modules during graph capture.

Highlights

  • Gemma3 Model Support: I've added support for Gemma3 models and other models with similar implementations by incorporating necessary adjustments to the autowrapper and extending the test suite to include new Gemma3 variants.
  • Autowrapper Robustness and Debugging: I've significantly improved the autowrapper's robustness by correctly handling Python's walrus operator (:=) within conditional statements and preserving specific function decorators (can_return_tuple) that modify function signatures. A new context manager, append_autowrap_source_on_fail, has been introduced to provide more informative tracebacks by including the autowrapped source code and highlighting the failing line, greatly aiding debugging.
  • Tracing Stability Improvements: I've addressed issues related to PyTorch's tracing of wrapped root functions by explicitly unwrapping and re-patching the model's forward method before tracing. Additionally, I've implemented a fix to prevent tracing problems when offloaded modules are also ancestors of sequential targets by temporarily on-loading their parameters during graph capture.
  • Tracing Ignore List Update: I've updated the list of functions to ignore during tracing in dataset_arguments.py to include project_per_layer_inputs, which is likely necessary for the new model support or autowrapper functionality.
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.

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 adds support for Gemma3 and introduces several valuable improvements to the autowrapper functionality, enhancing its robustness and debuggability. The changes are well-structured and thoughtful. I've provided a couple of suggestions to further improve the new error handling logic and code clarity.

Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
@kylesayrs kylesayrs force-pushed the kylesayrs/autowrap-support-gemma3n branch from 1b22d86 to 677614d Compare July 30, 2025 20:29
Signed-off-by: Kyle Sayers <[email protected]>
@kylesayrs kylesayrs marked this pull request as ready for review July 30, 2025 20:42
Copy link
Collaborator

@brian-dellabetta brian-dellabetta left a comment

Choose a reason for hiding this comment

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

i'm curious to try this out on Qwen Omni, as user reported here, errors occur during tracing. When using the thinker portion of the model, it's a different tracing error related to args/kwargs passing, i don't recall the exact log.

Signed-off-by: Kyle Sayers <[email protected]>
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.

2 participants