Add LSQ (Learned Scale Quantization) support and recipes#1884
Add LSQ (Learned Scale Quantization) support and recipes#1884realAsma wants to merge 13 commits into
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1884 +/- ##
==========================================
- Coverage 77.64% 77.39% -0.25%
==========================================
Files 516 516
Lines 57465 58761 +1296
==========================================
+ Hits 44618 45481 +863
- Misses 12847 13280 +433
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Fold in the FSDP2 amax dtype fix and LAQ pre-scale quantization control. Signed-off-by: realAsma <akuriparambi@nvidia.com>
Signed-off-by: realAsma <akuriparambi@nvidia.com>
f95fdff to
8b4059c
Compare
|
BB: Can you write a good PR description for this PR? Summarize the changes in this PR - address it to external reviewers, not me. |
There was a problem hiding this comment.
BB: rename this to qad_scale_only.yaml
There was a problem hiding this comment.
🤖 Bot comment.
🐝 I’ll prepare this rename in the PR worktree and report back here before any commit or push.
There was a problem hiding this comment.
🤖 Bot comment.
Prepared the rename locally:
examples/llm_qat/configs/train/qad_laq_scales.yaml → examples/llm_qat/configs/train/qad_scale_only.yaml
It is a content-preserving move. The renamed YAML parses successfully, git diff --check passes, and there are no references that need updating. I have not committed or pushed it; reply commit and push if you want me to publish the rename to this PR.
There was a problem hiding this comment.
okay commit and push.
realAsma
left a comment
There was a problem hiding this comment.
BB: Can you add one more train yaml file for full parameter QAD. Lets use LR 1e-5 for all parameters except amax. for learnable amax -> use 1e-4 LR.
🐝 I’m drafting a reviewer-facing summary of the PR now. |
I prepared the following reviewer-facing PR description. I have not changed the PR body because this request did not authorize publishing; reply apply if you want me to update it. SummaryThis PR adds Learnable Amax Quantization (LAQ) support to Model Optimizer and provides focused NVFP4 Quantization-Aware Distillation (QAD) recipes for learning quantization scales. LAQ represents quantization with separate pre-quantization and post-dequantization amax values. Those values can be learned independently (Dual Scale) or tied to one shared parameter (LSQ), allowing scale parameters to be optimized during QAD while the quantized model weights remain fixed. What changed
Validation
|
🐝 Got it — I’ll add a full-parameter QAD train config with LR |
Prepared the full-parameter QAD config locally.
The training config and LR mapping parse successfully, their exact LR values/patterns were checked, the YAML formatting hooks pass, and |
|
BB: Please update the PR description to be external facing. |
🐝 I’ll update the PR description to be external-facing now. |
Updated the PR description to be external-facing, with a reviewer-oriented summary, the LAQ/LSQ and QAD changes, and validation results. I also verified the published body on the live PR. No source code or branch changes were made. Requested in: #1884 (comment) |
|
BB: Please do this #1884 (comment) |
🐝 Got it — I’ll publish the prepared QAD config updates and report back here with the commit and validation results. |
Signed-off-by: realAsma <akuriparambi@nvidia.com>
Published in
Validated config parsing and exact LR mappings; YAML hooks and |
Signed-off-by: realAsma <akuriparambi@nvidia.com>
Signed-off-by: realAsma <akuriparambi@nvidia.com>
LAQ was a temporary name; LSQ is the established community term for learned-scale quantization (amax is learned and scale is derived as amax / max_bound). Renames the method string "laq" -> "lsq" (mode lsq_calibrate), LSQConfig, enable_lsq, and all related identifiers, recipes, and tests. Recipe variants: nvfp4_lsq (tied amax) and nvfp4_dual_lsq (separate pre/post amax). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: realAsma <akuriparambi@nvidia.com>
|
BB: This PR add two algorithms actually -> LSQ and Dual-LSQ -> can we update PR description and and the modelopt/torch/quantization/config.py with this information. LSQ: Refer to the original https://arxiv.org/pdf/1902.08153 paper (we call it learnt scale quantization instead of learnt step size quantization - both are similar); Dual-LSQ: We learn separate pre quantization scale and post quantization scale. Then add a note that we actually do a reparameterized version of LSQ, learn amax instead of scale directly. scale is computed as scale = amax/max_bound. |
🐝 Got it — I’ll update the PR description and quantization config to clearly distinguish LSQ from Dual-LSQ and document the learned- |
Signed-off-by: realAsma <akuriparambi@nvidia.com>
Done 🐝 Updated the PR description and
Published as signed/DCO commit |
Signed-off-by: realAsma <akuriparambi@nvidia.com>
Signed-off-by: realAsma <akuriparambi@nvidia.com>
Signed-off-by: realAsma <akuriparambi@nvidia.com>
Signed-off-by: realAsma <akuriparambi@nvidia.com>
Signed-off-by: realAsma <akuriparambi@nvidia.com>
|
BB: please investigate and fix the CICD errors - you can restart pipelines as needed. If there are any major design changes notify me via slack for approval. Minor changes are approved - keep a summary and commits diff I can review later. |
🐝 I’m on it. I’ll inspect the failing CI/CD checks, fix and publish minor issues as needed, restart pipelines where useful, and report back with the validation and commit diff. I’ll pause and message you privately before any major design change. |
|
BB: Can you launch these NVFP4 PTQ+QAD jobs from this feature branch folder:
Model: Dataset: Use local GPUs (may be 4 GPU job) Create BeeBot timers to monitor each job, once everything is done, update the PR description with train and eval loss (2 column 1 row). Solid lines - each variant in a distinct color. Notify me in slack once done. |
Signed-off-by: realAsma <akuriparambi@nvidia.com>
🐝 I’ve verified this request and queued the four Qwen3 1.7B NVFP4 PTQ+QAD variants with the active PR work. I’ll monitor them, add the train/eval loss plots to the PR description, and notify you in Slack when everything is complete. |
🐝 I’ve got the four-run experiment request too. I’ll launch the specified Qwen3 1.7B NVFP4 PTQ+QAD variants on local GPUs with captured launch evidence, monitor them through completion, add the train/eval loss curves to the PR description, and notify you on Slack. |
|
|
BB: Make sure you launch one job at a time on the local a8 server. Otherwise they might go OOM. |
🐝 Got it. I’ll keep the local a8 workload strictly serialized—one job at a time—and verify the active launch plan follows that limit to avoid OOM. |
Outcome: the local a8 OOM-safety constraint is recorded on the active experiment task: no more than one job may run at a time. I did not start any duplicate work from this handler; the existing launcher owner is responsible for serializing the remaining PTQ/QAD stages and verifying the limit before each launch. |
CI/CD fix published in signed/DCO commit
|
CI follow-up: the final multi-version job and aggregate required check are now green. The fresh Unit tests workflow finished with all 19 jobs successful at |
Summary
This PR adds two scale-learning algorithms to Model Optimizer—LSQ and Dual-LSQ—and provides focused NVFP4 Quantization-Aware Distillation (QAD) recipes for them.
ModelOpt implements both algorithms with an
amaxreparameterization: it learnsamaxrather than the scale directly, withscale = amax / max_bound. This allows scale parameters to be optimized during QAD while the quantized model weights remain fixed.What changed
LSQConfigalgorithm and calibration mode with configurable learned pre/post amax values, tied-scale support, and optional pre-scale quantization.TensorQuantizer, tensor quantization, and the FP4 GEMM path so gradients propagate through LSQ scale parameters.Validation
test_lsq_cuda.py6 passed; FSDP2 LSQ test passed.git diff --checkpassed.