Skip to content

Conversation

@kylesayrs
Copy link
Collaborator

@kylesayrs kylesayrs commented Dec 14, 2025

Purpose

Changes

  • It seems that any issues with medgemma were on transformer's side and have since been resolved

Testing

  • Ran example to completion and verified sane outputs
Please describe the animal in this image

Certainly! Based on the image, the animal is a **cat**, specifically a **kitten**.

Here are some of its characteristics visible in the photo:

*   **Size:** It appears to be small, suggesting it's a kitten.
*   **Coat:** It has a white coat with some tabby markings (darker stripes) visible on its head and possibly elsewhere.
*   **Posture:** It is lying down comfortably on a computer keyboard.
*   **Features
* ```

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

@kylesayrs kylesayrs changed the title [Examples] [Example] MedGemma Dec 14, 2025
@gemini-code-assist
Copy link
Contributor

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 a new example for quantizing the google/medgemma-27b-it multimodal vision model using GPTQ. It demonstrates the llmcompressor framework's capability to apply efficient quantization techniques to complex models, ensuring proper functionality and sane outputs after compression. The addition confirms the resolution of prior integration challenges with MedGemma, making it a viable target for optimization.

Highlights

  • New Example for MedGemma Quantization: Introduces a new example script (medgemma_example.py) demonstrating how to apply GPTQ quantization (W4A16 scheme) to the google/medgemma-27b-it model using llmcompressor.
  • Multimodal Vision Model Support: The example showcases the quantization and generation process for a multimodal vision model, including image processing and chat template application, verifying sane outputs post-quantization.
  • Resolution of MedGemma Issues: Addresses previous issues with MedGemma, noting that they were related to the transformers library and have since been resolved, allowing for successful integration and example execution.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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 a new example script for quantizing the MedGemma model. The script is well-structured, but it contains a critical issue in how oneshot is called for a multimodal model. The current implementation will fail because it lacks a proper data collator for image and text data, and it passes a tokenizer string instead of the required processor object. I've provided a detailed comment with a code suggestion to fix this, which includes adding a data collator and updating the oneshot parameters. With this change, the example should run correctly.

Comment on lines +33 to +43
# Perform oneshot
oneshot(
model=model,
tokenizer=model_id,
dataset=DATASET_ID,
splits=DATASET_SPLIT,
recipe=recipe,
max_seq_length=MAX_SEQUENCE_LENGTH,
num_calibration_samples=NUM_CALIBRATION_SAMPLES,
trust_remote_code_model=True,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The oneshot call is not correctly configured for this multimodal model and will likely fail during execution. There are two main issues:

  1. Missing data collator: The default data collator only handles text. For a multimodal dataset like flickr30k, a custom data_collator is required to process both images and text.
  2. Incorrect processor handling: The processor object should be passed to oneshot, not a tokenizer string, to ensure both modalities are handled correctly during data loading and calibration.

Below is a suggested change that defines a data collator and corrects the oneshot call.

def data_collator(data):
    images = [sample["images"] for sample in data]
    text = [sample["text"] for sample in data]
    return processor(text=text, images=images, padding=True, return_tensors="pt")

# Perform oneshot
oneshot(
    model=model,
    processor=processor,
    dataset=DATASET_ID,
    splits=DATASET_SPLIT,
    recipe=recipe,
    data_collator=data_collator,
    max_seq_length=MAX_SEQUENCE_LENGTH,
    num_calibration_samples=NUM_CALIBRATION_SAMPLES,
    trust_remote_code_model=True,
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready When a PR is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Failed saving quantized gemma3 27b (MedGemma) with GPTQ (4b works)

2 participants