[Distributed][SmoothQuant] Add distributed activation scale reduction (#2180)#2471
Conversation
Add _reduce_activation_scales() to SmoothQuantModifier to support weight-parallel distributed compression as specified in RFC vllm-project#2180. In a distributed setting, each rank observes a disjoint partition of the calibration dataset and collects local per-channel min/max activation statistics via forward hooks. Before smoothing scales are computed, _reduce_activation_scales() all-reduces these statistics across all ranks using MIN/MAX collective ops, ensuring every rank has global activation statistics. Following the pattern established for AWQ in the RFC: since the scale computation is cheap, it is duplicated across ranks rather than computed on one rank and broadcast, avoiding an extra distributed communication step on the weight tensors. This is a strict no-op in single-GPU mode (guarded by is_distributed()). Also adds: - Unit tests (mock-based, no GPU) verifying the all_reduce call contract - DDP example script for examples/quantization_w8a8_int8/ - Multi-GPU integration tests verifying weight equivalence vs single-GPU Testing: - Unit tests: all 5 passed (pytest -m unit) - DDP example: ran successfully on 2x V100 32GB, both ranks completed in ~698s, peak GPU mem 1.66 GB per rank - ruff: all checks passed Relates to: vllm-project#2180 Signed-off-by: David Zheng <dzheng@apple.com>
|
👋 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. |
Summary of ChangesHello, 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 distributed capabilities to the SmoothQuant quantization process. It enables efficient calibration in a distributed setting by allowing each GPU to process a disjoint subset of the calibration data, then aggregating the activation statistics across all ranks. This ensures that all ranks compute identical smoothing scales, facilitating consistent and scalable W8A8 quantization for large language models. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces distributed support for the SmoothQuantModifier, which is a great enhancement. The core logic for all-reducing activation statistics across ranks is well-implemented and efficient. The addition of comprehensive unit and integration tests, including a multi-GPU correctness test, is excellent and ensures the reliability of the new feature. I have one suggestion for the new DDP example script to prevent a potential race condition during saving.
Prevent race condition where all ranks write to the same save directory. Addresses gemini-code-assist review on PR vllm-project#2471 Signed-off-by: David Zheng <dzheng@apple.com>
dispatch_model and generate require all ranks to participate. Add dist.barrier() before generation and only log output on rank 0. Signed-off-by: David Zheng <dzheng@apple.com>
|
Updated in 6646930:
|
tests/llmcompressor/modifiers/transform/smoothquant/test_smoothquant_distributed.py
Outdated
Show resolved
Hide resolved
tests/llmcompressor/modifiers/transform/smoothquant/test_smoothquant_distributed.py
Outdated
Show resolved
Hide resolved
|
The quality checks have failed. Please run |
Signed-off-by: David Zheng <dqzheng1996@gmail.com>
d2f8f6e to
500a1e2
Compare
|
@kylesayrs all review comments addressed, quality checks passing, 2 approvals. Ready for merge when you have a chance! |
Prevent race condition where all ranks write to the same save directory. Addresses gemini-code-assist review on PR vllm-project#2471 Signed-off-by: David Zheng <dzheng@apple.com>
- Move is_distributed() guard to _apply_smoothing() hotpath so _reduce_activation_scales() only handles the distributed case, improving readability for single-GPU readers - Remove redundant unit tests (subsumed by 2n_calls test; empty scales test unnecessary per reviewer feedback) - Remove test_smoothquant_ddp_script_runs_cleanly (too expensive for CI) - Switch integration test model to nm-testing/tinysmokellama-3.2 (CI-friendly tiny model per HDCharles suggestion) - Switch DDP example model to Qwen/Qwen2-7B-Instruct (DDP more meaningful for larger models) - Fix --nproc arg conflict with torchrun, rename to --num_gpus - Add benchmark_smoothquant_ddp.py for reproducing speedup numbers Distributed speedup on 4x V100 32GB (Qwen2-7B-Instruct, 512 samples): 1 GPU: 94.1 min | 8.93 GB peak mem | 1.00x 2 GPU: 58.7 min | 7.06 GB peak mem | 1.60x 4 GPU: 28.7 min | 7.06 GB peak mem | 3.28x Addresses review comments from HDCharles on PR vllm-project#2471 Signed-off-by: David Zheng <dqzheng1996@gmail.com>
Summary
Implements distributed support for
SmoothQuantModifieras part of theweight-parallel optimization tracked in #2180, assigned to @dzhengAP.
What this PR does
In a distributed calibration run, each rank observes a disjoint partition
of the calibration dataset. Activation statistics (per-channel min/max)
are collected locally via forward hooks. Before smoothing scales are
computed,
_reduce_activation_scales()all-reduces those statisticsacross all ranks so every rank has the global activation profile, then
each rank independently computes identical smoothing scales (cheap op,
no weight broadcast needed).
This follows the AWQ strategy described in #2180. Single-GPU behavior
is completely unchanged — all new code is guarded by
is_distributed().Changes
_reduce_activation_scales(): all-reducesmin/max_channel_valsacross ranks using async MIN/MAX collectives batched with
wait_for_comms_apply_smoothing(): calls_reduce_activation_scales()as first stepexamples/quantization_w8a8_int8/smoothquant_ddp_example.pyTest results
pytest -m unit)in ~698s, peak GPU mem 1.66 GB per rank
Distributed Speedup Benchmarks
Model: Qwen/Qwen2-7B-Instruct, 512 calibration samples, 4x V100 32GB
Benchmark script:
examples/quantization_w8a8_int8/benchmark_smoothquant_ddp.pyCloses part of #2180
cc @kylesayrs