Skip to content

[#8242][feat] Add int4 GPTQ support for AutoDeploy - #8248

Merged
Fridah-nv merged 5 commits into
NVIDIA:mainfrom
nv-auto-deploy:user/fridah/gptq
Jan 31, 2026
Merged

[#8242][feat] Add int4 GPTQ support for AutoDeploy#8248
Fridah-nv merged 5 commits into
NVIDIA:mainfrom
nv-auto-deploy:user/fridah/gptq

Conversation

@Fridah-nv

@Fridah-nv Fridah-nv commented Oct 9, 2025

Copy link
Copy Markdown
Collaborator

closes #8242

Output for Qwen/Qwen2.5-0.5B-Instruct-GPTQ-Int4:

[01/26/2026-16:16:25] [TRT-LLM AUTO-DEPLOY] [I] [PROMPT 0] How big is the universe? : 100 billion light years?
Is there a way to calculate the size of the universe?
Do those questions have the same meaning?
Pick your answer from:
a). no
b). yes
a). no
The question "How big is the universe? 100 billion light years?" is asking about the size of the universe in terms of light years. The question "Is there a way to calculate the size of the universe? " is asking about the size of the universe in
[01/26/2026-16:16:25] [TRT-LLM AUTO-DEPLOY] [I] [PROMPT 1] In simple words and a single sentence, explain the concept of gravity: :  Gravity is the force that pulls objects towards the center of the Earth. It is the attraction between masses, and it is what gives us the ability to lift objects up to the sky. The force of gravity is what keeps us on the ground and keeps us on the ground. It is what makes the moon and the planets orbit the sun. It is what gives us the ability to lift objects up to the sky. It is what keeps us on the ground and keeps us on the ground. It is

Output for Qwen/Qwen2.5-0.5B-Instruct:

[01/26/2026-16:18:01] [TRT-LLM AUTO-DEPLOY] [I] [PROMPT 0] How big is the universe? : 1. What is the size of the universe?
2. How big is the universe?
3. How big is the universe?
4. How big is the universe?
5. How big is the universe?
6. How big is the universe?
7. How big is the universe?
8. How big is the universe?
9. How big is the universe?
10. How big is the universe?
11. How big is the universe?
12. How big is the universe
[01/26/2026-16:18:01] [TRT-LLM AUTO-DEPLOY] [I] [PROMPT 1] In simple words and a single sentence, explain the concept of gravity: :  Gravity is a force that attracts objects towards each other. It is the force that keeps planets and stars in orbit around the sun, and it is responsible for the movement of objects in our solar system. It is also responsible for the movement of objects in the universe, including the movement of comets and asteroids. Gravity is a fundamental force of nature and is responsible for the motion of all objects in the universe. It is a force that is always present and is responsible for the movement of objects in our

Testing with:

args:
  mode: graph
  world_size: 1
  runtime: trtllm
  compile_backend: torch-simple
  model_factory: AutoModelForCausalLM
  skip_loading_weights: false
  disable_overlap_scheduler: true
  kv_cache_config:
    enable_block_reuse: false
  model_kwargs:
    torch_dtype: bfloat16
benchmark:
  enabled: false
prompt:
  sp_kwargs:
    top_k: 0
    temperature: 0
dry_run: false

Summary by CodeRabbit

  • New Features

    • Added GPTQ-based INT4 quantization support with configurable scaling and zero-point handling.
    • Extended quantization framework to recognize and process GPTQ quantization methods alongside existing approaches.
    • Improved model configuration restoration during quantization export workflows.
  • Tests

    • Added comprehensive test suite validating GPTQ and ModelOpt quantization implementations for numerical consistency.

✏️ Tip: You can customize this high-level summary in your review settings.

Description

Test Coverage

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

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.

Details

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 the stage-list parameter 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.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip 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-pipeline

Reuse 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.

@Fridah-nv Fridah-nv self-assigned this Oct 9, 2025
@Fridah-nv Fridah-nv changed the title [#8242][Autodeploy] Add int4 gptq dequant ref op, unit test to map with existing int4 op [#8242][Autodeploy] Add int4 GPTQ support for AutoDeploy Oct 9, 2025
@lucaslie lucaslie moved this from Backlog to In progress in AutoDeploy Board Nov 10, 2025
@Fridah-nv Fridah-nv changed the title [#8242][Autodeploy] Add int4 GPTQ support for AutoDeploy [#8242][feat] Add int4 GPTQ support for AutoDeploy Jan 26, 2026
@Fridah-nv
Fridah-nv marked this pull request as ready for review January 26, 2026 21:11
@Fridah-nv
Fridah-nv requested a review from a team as a code owner January 26, 2026 21:11
@Fridah-nv
Fridah-nv requested a review from lucaslie January 26, 2026 21:11
@coderabbitai

coderabbitai Bot commented Jan 26, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR adds AutoGPTQ support to AutoDeploy by introducing a GPTQ-based INT4 quantization path. The implementation includes a custom torch operation, quantization transform, configuration handling, export utilities updates, and comprehensive test coverage for GPTQ weight packing and numerical equivalence validation.

Changes

Cohort / File(s) Change Summary
Configuration
tensorrt_llm/_torch/auto_deploy/config/default.yaml
Adds new transform entry quantize_int4_gptq_linear_from_config under transforms with stage pattern_matcher, expanding quantization transform options alongside existing int4 linear quantization.
Custom Operations
tensorrt_llm/_torch/auto_deploy/custom_ops/torch_quant.py
Introduces public custom op auto_deploy::torch_fake_quant_int4_gptq_linear that performs GPTQ-based INT4 linear computation with weight dequantization per-block, scaling, matmul, and bias application. Includes corresponding fake implementation for shape inference.
Quantization Transforms
tensorrt_llm/_torch/auto_deploy/transform/library/quantization.py
Introduces new class INT4GPTQLinearQuantizationFromConfig implementing GPTQ quantization path with placeholder weight packing, per-block scale/qzero handling, checkpoint loading hooks supporting qzero v2 format conversion, and shape validation for K, G, N dimensions.
Model Configuration
tensorrt_llm/_torch/auto_deploy/models/quant_config_reader.py
Adds default module exclusion list, extends quantization method validation to accept both "mxfp4" and "gptq", and improves post_process_model to consistently return the model in all code paths.
Export Utilities
tensorrt_llm/_torch/auto_deploy/export/library/unified_attn.py
Renames torch_attention_hf_wrapper parameter from self to module, adds explicit is_causal derivation from kwargs or module config, and implements patching/restoring of model.config._attn_implementation for unified attention integration.
Test Coverage
tests/unittest/_torch/auto_deploy/unit/singlegpu/custom_ops/test_gptq_op.py
Adds comprehensive test module with GPTQ/ModelOpt weight packing/unpacking utilities, two weight computation helpers for numerical comparison, and parameterized test validating equivalence between GPTQ and ModelOpt implementations.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Config as Configuration<br/>(default.yaml)
    participant Transform as Quantization<br/>Transform
    participant CustomOp as GPTQ Custom Op<br/>(torch_quant.py)
    participant Model as Quantized<br/>Model

    User->>Config: Load GPTQ config
    Config->>Transform: Apply quantize_int4_gptq_linear_from_config
    Transform->>Transform: Validate shapes (K, G, N)
    Transform->>Transform: Generate placeholder qweight<br/>(K/8, N, int32)
    Transform->>Transform: Create scales/qzeros<br/>with GPTQ block structure
    Transform->>CustomOp: Build custom args<br/>(scales, qzeros mapping)
    CustomOp->>CustomOp: Derive G, block_size<br/>from dimensions
    CustomOp->>CustomOp: Dequantize weights<br/>per-G blocks
    CustomOp->>CustomOp: Apply weight scales<br/>and qzeros
    CustomOp->>CustomOp: Compute matmul<br/>(input × weight)
    CustomOp->>CustomOp: Add bias if present
    CustomOp->>Model: Return quantized output
    Model->>User: Provide inference results
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 3
❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description is incomplete. Required sections (Description, Test Coverage) are present but empty, and the Description field is critical for explaining the change. Fill in the Description section explaining what int4 GPTQ support is being added and why, and populate the Test Coverage section listing relevant tests like test_gptq_op.py.
Out of Scope Changes check ❓ Inconclusive The unified_attn.py changes involve renaming a parameter and handling is_causal logic, which appear related to export patching but are not directly tied to GPTQ support objectives from the linked issue. Clarify whether unified_attn.py changes are essential to GPTQ support or should be in a separate PR to keep scope focused.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding int4 GPTQ support to AutoDeploy, directly matching the changeset scope.
Linked Issues check ✅ Passed All code changes directly implement GPTQ support requirements from #8242: custom GPTQ operator added, quantization transform for GPTQ added, and config reader updated for GPTQ format support.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@tensorrt_llm/_torch/auto_deploy/transform/library/quantization.py`:
- Around line 733-739: The deletion unconditionally removes
state_dict[qweight_ckpt] which can equal the newly set state_dict[weight_name];
update the cleanup to only delete the original checkpoint key when it's distinct
and present by checking that qweight_ckpt != weight_name and qweight_ckpt in
state_dict before calling del; this change should be applied around the existing
state_dict assignments (references: weight_name, qweight_ckpt, state_dict,
mod_prefix).
- Around line 669-680: The default_scales function currently hardcodes BLOCK=128
causing failures for GPTQ group sizes !=128; change default_scales to accept an
explicit group_size (or a quantization config object) and use that value instead
of the hardcoded BLOCK, update assertions to use group_size (e.g., assert K %
group_size == 0) and adjust the returned tensor shapes accordingly (use G = K //
group_size), and update any callers (or defer creation) so load_hook can pass
the checkpoint-inferred group_size when initializing scales/qzeros.
🧹 Nitpick comments (1)
tests/unittest/_torch/auto_deploy/unit/singlegpu/custom_ops/test_gptq_op.py (1)

117-121: Consider expanding test parameterization.

The test only covers one configuration (N=896, K=4864, BLOCK_SIZE=128). Consider adding more parameter combinations to improve coverage, such as different group sizes and edge cases.

Suggested parameter expansion
-@pytest.mark.parametrize("N,K,BLOCK_SIZE", [(896, 4864, 128)])
+@pytest.mark.parametrize("N,K,BLOCK_SIZE", [
+    (896, 4864, 128),   # Original test case
+    (256, 1024, 128),   # Smaller dimensions
+    (512, 2048, 64),    # Different group size (if supported)
+])

Comment thread tensorrt_llm/_torch/auto_deploy/transform/library/quantization.py
Comment thread tensorrt_llm/_torch/auto_deploy/transform/library/quantization.py
@Fridah-nv
Fridah-nv requested a review from a team as a code owner January 27, 2026 00:11
Comment thread tensorrt_llm/_torch/auto_deploy/custom_ops/torch_quant.py Outdated
Comment thread tensorrt_llm/_torch/auto_deploy/transform/library/quantization.py
Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
…ort fix for Qwen3

Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
…-GPTQ-Int4

Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>

delete test file

Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>

add unit test and add to dashboard

Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>

revert unified attn fix

Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
@Fridah-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #34266 [ run ] triggered by Bot. Commit: 37acd86

@github-project-automation github-project-automation Bot moved this from In progress to In review in AutoDeploy Board Jan 31, 2026
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #34266 [ run ] completed with state SUCCESS. Commit: 37acd86
/LLM/main/L0_MergeRequest_PR pipeline #26427 completed with status: 'FAILURE'

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

@Fridah-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --reuse-test --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #34281 [ run ] triggered by Bot. Commit: 37acd86

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #34281 [ run ] completed with state SUCCESS. Commit: 37acd86
/LLM/main/L0_MergeRequest_PR pipeline #26437 completed with status: 'SUCCESS'

@Fridah-nv
Fridah-nv merged commit 7910d4d into NVIDIA:main Jan 31, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AutoDeploy Board Jan 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[Feature]: Add AutoGPTQ support for AutoDeploy

5 participants