[#8242][feat] Add int4 GPTQ support for AutoDeploy - #8248
Conversation
1474c40 to
bbbae12
Compare
📝 WalkthroughWalkthroughThis 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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
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) +])
91e6b55 to
4dbf8eb
Compare
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>
4dbf8eb to
63d4605
Compare
Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
|
/bot run --disable-fail-fast |
|
PR_Github #34266 [ run ] triggered by Bot. Commit: |
|
PR_Github #34266 [ run ] completed with state
|
|
/bot run --reuse-test --disable-fail-fast |
|
PR_Github #34281 [ run ] triggered by Bot. Commit: |
|
PR_Github #34281 [ run ] completed with state |
closes #8242
Output for
Qwen/Qwen2.5-0.5B-Instruct-GPTQ-Int4:Output for
Qwen/Qwen2.5-0.5B-Instruct:Testing with:
Summary by CodeRabbit
New Features
Tests
✏️ 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 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.