-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: Fix poor generation with FP8 Gemma3 1B checkpoint #6499
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
Conversation
WalkthroughThe updates introduce FP8 quantization support for Gemma 3 models in both code and test infrastructure. Model construction now leverages higher-level configuration objects and quantization configs. Weight mapping is integrated for the VLM variant. Accuracy reference YAMLs and integration tests are extended to include FP8 quantized model variants. Changes
Sequence Diagram(s)sequenceDiagram
participant TestRunner
participant Gemma3_1BInstruct
participant Gemma3_27BInstruct
participant ModelLoader
participant Evaluator
TestRunner->>Gemma3_1BInstruct: test_fp8()
Gemma3_1BInstruct->>ModelLoader: Load FP8 quantized model
ModelLoader-->>Gemma3_1BInstruct: Model instance
Gemma3_1BInstruct->>Evaluator: Evaluate CnnDailymail, MMLU
TestRunner->>Gemma3_27BInstruct: test_fp8()
Gemma3_27BInstruct->>ModelLoader: Load FP8 quantized model
ModelLoader-->>Gemma3_27BInstruct: Model instance
Gemma3_27BInstruct->>Evaluator: Evaluate CnnDailymail, MMLU, GSM8K
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15–25 minutes Suggested reviewers
Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
tensorrt_llm/_torch/models/modeling_gemma3.py(2 hunks)tensorrt_llm/_torch/models/modeling_gemma3vl.py(3 hunks)tests/integration/defs/accuracy/references/cnn_dailymail.yaml(1 hunks)tests/integration/defs/accuracy/references/gsm8k.yaml(1 hunks)tests/integration/defs/accuracy/references/mmlu.yaml(1 hunks)tests/integration/defs/accuracy/test_llm_api_pytorch.py(3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)
**/*.py: The code developed for TensorRT-LLM should conform to Python 3.8+.
Indent Python code with 4 spaces. Do not use tabs.
Always maintain the namespace when importing in Python, even if only one class or function from a module is used.
Python filenames should use snake_case (e.g., some_file.py).
Python classes should use PascalCase (e.g., class SomeClass).
Python functions and methods should use snake_case (e.g., def my_awesome_function():).
Python local variables should use snake_case. Prefix k for variable names that start with a number (e.g., k_99th_percentile).
Python global variables should use upper snake_case and prefix G (e.g., G_MY_GLOBAL).
Python constants should use upper snake_case (e.g., MY_CONSTANT).
Avoid shadowing variables declared in an outer scope in Python.
Initialize all externally visible members of a Python class in the constructor.
For interfaces that may be used outside a file, prefer docstrings over comments in Python.
Comments in Python should be reserved for code within a function, or interfaces that are local to a file.
Use Google style docstrings for Python classes and functions, which can be parsed by Sphinx.
Attributes and variables in Python can be documented inline; attribute docstrings will be rendered under the docstring for the class.
Avoid using reflection in Python when functionality can be easily achieved without reflection.
When using try-except blocks in Python, limit the except to the smallest set of errors possible.
When using try-except blocks to handle multiple possible variable types in Python, keep the body of the try as small as possible, using the else block to implement the logic.
Files:
tensorrt_llm/_torch/models/modeling_gemma3.pytensorrt_llm/_torch/models/modeling_gemma3vl.pytests/integration/defs/accuracy/test_llm_api_pytorch.py
**/*.{cpp,h,cu,py}
📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)
All TensorRT-LLM Open Source Software code should contain an NVIDIA copyright header that includes the current year. This includes .cpp, .h, .cu, .py, and any other source files which are compiled or interpreted.
Files:
tensorrt_llm/_torch/models/modeling_gemma3.pytensorrt_llm/_torch/models/modeling_gemma3vl.pytests/integration/defs/accuracy/test_llm_api_pytorch.py
🧠 Learnings (1)
tests/integration/defs/accuracy/test_llm_api_pytorch.py (1)
Learnt from: moraxu
PR: #6303
File: tests/integration/test_lists/qa/examples_test_list.txt:494-494
Timestamp: 2025-07-28T17:06:08.621Z
Learning: In TensorRT-LLM testing, it's common to have both CLI flow tests (test_cli_flow.py) and PyTorch API tests (test_llm_api_pytorch.py) for the same model. These serve different purposes: CLI flow tests validate the traditional command-line workflow, while PyTorch API tests validate the newer LLM API backend. Both are legitimate and should coexist.
🧬 Code Graph Analysis (1)
tensorrt_llm/_torch/models/modeling_gemma3vl.py (7)
tensorrt_llm/_torch/models/checkpoints/hf/gemma3_weight_mapper.py (1)
Gemma3HfWeightMapper(9-34)tensorrt_llm/_torch/models/modeling_vila.py (2)
config(250-251)load_weights(1196-1201)tensorrt_llm/_torch/models/modeling_gemma3.py (2)
Gemma3ForCausalLM(317-493)load_weights(492-493)tensorrt_llm/_torch/models/checkpoints/base_weight_mapper.py (1)
init_model_and_config(19-36)tensorrt_llm/_torch/models/modeling_siglip.py (1)
load_weights(117-123)tensorrt_llm/_torch/models/modeling_llava_next.py (1)
load_weights(251-254)tensorrt_llm/_torch/models/modeling_hyperclovax.py (1)
load_weights(987-999)
🪛 Ruff (0.12.2)
tests/integration/defs/accuracy/test_llm_api_pytorch.py
544-544: Line too long (127 > 120)
(E501)
586-586: Line too long (127 > 120)
(E501)
592-592: Line too long (122 > 120)
(E501)
🔇 Additional comments (16)
tests/integration/defs/accuracy/references/cnn_dailymail.yaml (2)
3-5: LGTM! FP8 quantization entry follows established pattern.The new FP8 quantization configuration for
google/gemma-3-1b-itcorrectly maintains the same accuracy as the baseline, indicating proper validation of the quantized model.
8-10: LGTM! FP8 quantization entry follows established pattern.The new FP8 quantization configuration for
google/gemma-3-27b-itcorrectly maintains the same accuracy as the baseline, demonstrating consistent quantization quality.tests/integration/defs/accuracy/references/mmlu.yaml (2)
100-104: LGTM! New model entry with FP8 quantization variant added correctly.The entry for
google/gemma-3-1b-itincludes both baseline (39.0) and FP8 quantized variants with preserved accuracy, following the established file structure.
107-109: LGTM! FP8 quantization entry maintains accuracy consistency.The additional FP8 quantization configuration for
google/gemma-3-27b-itpreserves the baseline accuracy (77.80), demonstrating effective quantization implementation.tests/integration/defs/accuracy/references/gsm8k.yaml (2)
116-118: LGTM! FP8 quantization entry preserves baseline accuracy.The FP8 quantization configuration for
google/gemma-3-1b-itmaintains the accuracy of 25.52, consistent with other reference files.
121-123: LGTM! FP8 quantization entry preserves baseline accuracy.The FP8 quantization configuration for
google/gemma-3-27b-itmaintains the high accuracy of 91.66, demonstrating effective quantization for this larger model.tests/integration/defs/accuracy/test_llm_api_pytorch.py (1)
582-583: LGTM! MMLU task evaluation added for comprehensive testing.The addition of MMLU task evaluation to the
test_auto_dtypemethod ensures consistency with the new FP8 test method and provides more comprehensive model validation.tensorrt_llm/_torch/models/modeling_gemma3vl.py (4)
9-10: LGTM - Weight mapper import added correctly.The import of
Gemma3HfWeightMapperis properly added to support FP8 quantization weight loading.
109-110: Weight mapper initialization follows correct pattern.The weight mapper instantiation and initialization with the language model and config follows the expected pattern seen in other models.
151-151: Weight mapper properly passed to load_weights.The updated
load_weightscall correctly passes the weight mapper to enable FP8 quantization support for the language model component.
107-107: Architectures attribute propagation verifiedThe
architecturesfield inmodeling_gemma3vl.pyis being set fromconfig.architecturesjust as in other VLM and LLM model implementations (e.g., Mistral, Phi4, Qwen2VL). The weight mapper logic inbase_checkpoint_loader.pyand model‐selection utilities inmodeling_utils.pyall rely on this pattern and will correctly pick up the first architecture entry for mapping.No changes required.
tensorrt_llm/_torch/models/modeling_gemma3.py (5)
161-161: Correctly updated constructor to accept ModelConfig wrapper.The constructor signature change from
Gemma3TextConfigtoModelConfig[Gemma3TextConfig]enables access to quantization configuration, which is essential for FP8 support.
163-163: Config attribute properly updated to reference pretrained config.The config attribute now correctly references
model_config.pretrained_configto maintain backward compatibility while enabling access to the ModelConfig wrapper.
171-171: Essential fix: quant_config properly passed to Linear layers.Adding
quant_config=model_config.get_quant_config()to all Linear layers (gate_proj, up_proj, down_proj) is the key fix that resolves the gibberish output issue with FP8 checkpoints. This ensures the quantization configuration is properly propagated to the linear operations.Also applies to: 176-176, 181-181
182-182: Activation function access correctly updated.The activation function access is properly updated to use
self.config.hidden_activationfollowing the config attribute change.
208-208: MLP instantiation correctly updated to pass ModelConfig.The MLP instantiation in
Gemma3DecoderLayeris properly updated to pass the fullmodel_configas a keyword argument, enabling the quantization configuration to flow through to the linear layers.
58eed1c to
972b2d6
Compare
5fd27f3 to
1cec903
Compare
|
/bot run |
|
PR_Github #13615 [ run ] triggered by Bot |
|
PR_Github #13615 [ run ] completed with state |
Signed-off-by: Balaram Buddharaju <[email protected]>
1cec903 to
514741c
Compare
|
/bot run |
|
PR_Github #13688 [ run ] triggered by Bot |
|
Thanks for the fix! |
|
PR_Github #13688 [ run ] completed with state |
Signed-off-by: Balaram Buddharaju <[email protected]>
Signed-off-by: Balaram Buddharaju <[email protected]>
fix: Fix poor generation with FP8 Gemma3 1B checkpoint (NVIDIA#6499) Signed-off-by: Balaram Buddharaju <[email protected]> [None][fix] Serialize the window_size in the kv event (NVIDIA#6526) Signed-off-by: richardhuo-nv <[email protected]>
fix: Fix poor generation with FP8 Gemma3 1B checkpoint (NVIDIA#6499) Signed-off-by: Balaram Buddharaju <[email protected]> [None][fix] Serialize the window_size in the kv event (NVIDIA#6526) Signed-off-by: richardhuo-nv <[email protected]> [None][feat] Multi-block mode for Hopper spec dec XQA kernel (NVIDIA#4416) Signed-off-by: Jhao-Ting Chen <[email protected]>
fix: Fix poor generation with FP8 Gemma3 1B checkpoint (NVIDIA#6499) Signed-off-by: Balaram Buddharaju <[email protected]> [None][fix] Serialize the window_size in the kv event (NVIDIA#6526) Signed-off-by: richardhuo-nv <[email protected]> [None][feat] Multi-block mode for Hopper spec dec XQA kernel (NVIDIA#4416) Signed-off-by: Jhao-Ting Chen <[email protected]> [None][feat] Add support for fused gate_up_proj scales for FP8 blockwise (NVIDIA#6496) Signed-off-by: Aurelien Chartier <[email protected]>
Signed-off-by: Balaram Buddharaju <[email protected]> Signed-off-by: Lanyu Liao <[email protected]>
Signed-off-by: Balaram Buddharaju <[email protected]>
Description
This MR fixes Gemma3 1B decoder generating gibberish with FP8 checkpoint.
https://nvbugspro.nvidia.com/bug/5421528
Root cause: Linear layers constituting MLP aren't receiving the
quant_configinformationQuick fix: Pass down the
quant_configinfoClean fix: Replace custom Gemma3MLP with GatedMLP which passes down this info internally. Will happen in this MR: #6371
After the fix:
Test Coverage
GitHub Bot Help
/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...Provide a user friendly way for developers to interact with a Jenkins server.
Run
/bot [-h|--help]to print this help message.See details below for each supported subcommand.
run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]Launch build/test pipelines. All previously running jobs will be killed.
--reuse-test (optional)pipeline-id(OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.--disable-reuse-test(OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.--disable-fail-fast(OPTIONAL) : Disable fail fast on build/tests/infra failures.--skip-test(OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.--stage-list "A10-PyTorch-1, xxx"(OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.--gpu-type "A30, H100_PCIe"(OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.--test-backend "pytorch, cpp"(OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.--only-multi-gpu-test(OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.--disable-multi-gpu-test(OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.--add-multi-gpu-test(OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.--post-merge(OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx"(OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".--detailed-log(OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.--debug(OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in thestage-listparameter to access the appropriate container environment. Note: Does NOT update GitHub check status.For guidance on mapping tests to stage names, see
docs/source/reference/ci-overview.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip testing for latest commit on pull request.
--comment "Reason for skipping build/test"is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.reuse-pipeline
reuse-pipelineReuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor