feat(quantization): support targeted weight QAT for LoRA - #3904
Draft
hasuoshenyun wants to merge 4 commits into
Draft
hasuoshenyun wants to merge 4 commits into
hasuoshenyun wants to merge 4 commits into
Conversation
Signed-off-by: hasuoshenyun <1225541074@qq.com>
Signed-off-by: hasuoshenyun <1225541074@qq.com>
Signed-off-by: hasuoshenyun <1225541074@qq.com>
Contributor
|
馃尶 Preview your docs: https://nvidia-preview-preview-11c262eff115.docs.buildwithfern.com/nemo/automodel |
Signed-off-by: hasuoshenyun <1225541074@qq.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do ?
Add targeted LoRA QAT for DeepSeek-V4-Flash, GLM-5.3-Flash and Qwen3, with actual training validation and measured improvements in train-to-quantized-reference inference consistency in our tested cases. Existing TorchAO INT4 configuration remains supported.
At a glance: supported examples and measured benefit
glm5_next)Measured in the matched V4/GLM cases: training-eval versus quantized-reference-reload logit RMSE fell from 0.2418 to 0.0000 for V4 and 0.8230 to 0.0000 for GLM. Top-1 agreement between those two execution paths increased from 91.0156% to 100.0000% and 67.5781% to 100.0000%, respectively. This is an improvement in behavioral consistency after merge-and-quantize, not a measured increase in task accuracy or inference throughput.
The full-model experiments used two training steps, synthetic data and FSDP2/EP32 on 4 nodes 脳 8 H100 GPUs, preserving backbone depth, width, vocabulary and expert count; MTP was disabled and GLM evaluation was text-only. They used local checkpoint/data overrides and forced eager execution, rather than running the published HellaSwag YAMLs unchanged. These historical runs precede subsequent refactoring/rebasing; current-SHA CI and sanitized full-run artifacts remain outstanding below. Native serving-engine parity is not claimed.
Why this matters: fine-tuning gains may not survive deployment quantization
A fine-tuning run can look successful in floating point, yet lose part of its learned behavior when its weights are merged and quantized for inference. This PR makes LoRA training account for that final quantization step instead of discovering the mismatch only after deployment.
When a model is fine-tuned in floating point but served with lower-precision weights, training and inference can execute materially different weight computations. This matters for workflows such as DeepSeek and GLM fine-tuning followed by merged FP4/FP8 inference:
The issue is floating-point training followed by a different, quantized inference computation鈥攏ot an inherent inconsistency in all floating-point training. It can affect full-parameter fine-tuning as well as adapters; this PR's new FP8/MXFP4 path specifically addresses merged LoRA weights.
W_eff = W_base + delta_WD(Q(W_eff))D(Q(W_base + delta_W))D(Q(W_base + delta_W))Here
delta_W = (alpha / rank) * B @ Afor a dense linear layer; grouped experts use the corresponding transposed storage layout.Qencodes the weights andDdecodes them for the reference computation. This PR fake-quantizes the combined effective weight, not only the frozen base, and uses a straight-through estimator to update the adapters. The base remains frozen and is not permanently overwritten during training.Why we report train鈥搃nference consistency: the measurements quantify how much a trained model's output changes when it is converted to its quantized reference form. They are intended to expose the gap that floating-point training metrics can hide, and to verify that QAT models the same weight transformation used by the reference inference path.
In the recorded matched full-backbone experiments, ordinary-LoRA versus QAT train-to-reference-reload RMSE was 0.2418 versus 0.0000 for V4-Flash, and 0.8230 versus 0.0000 for GLM-5.3-Flash. The protocol and KL/top-1 results are below. These measurements demonstrate the output mismatch and its removal under the tested QDQ contract; they do not establish that all observed drift is erased learning, or that QAT improves task accuracy. Ordinary-LoRA drift also includes merge rounding and operation-order changes.
The practical objective is to retain useful fine-tuning behavior after quantization. Exact reference alignment is an implementation requirement toward that objective, not a substitute for task-quality evaluation. It requires matched encoding, scales, rounding, dtype and operation order; arbitrary native serving kernels, activation quantizers and KV-cache formats are outside the demonstrated contract.
Changelog
Before your PR is "Ready for review"
Additional Information
Depends on #3902 (ordinary expert LoRA correctness) and #3903 (opt-in typed configuration). Please review those independently; rebase this branch after they land. The QAT-specific commit is
11c262eff. Do not interpret the stacked diff as a request to silently change ordinary training semantics within QAT.Validation
Recorded train-forward versus quantized-reference-reload measurements
Errors are displayed to four decimal places; QAT errors were measured as exact zero, not merely rounded to zero. Raw experimental values are retained separately.
These are bounded two-step experiments using expert-only rank-4/alpha-8 LoRA, BF16, fixed synthetic input and FSDP2/EP32. Each arm is compared against its own decoded reference output, not against the other arm's learned weights. The full-model probe reuses the same distributed model with disk-decoded local expert weights, zeroed adapters and identity quantizers to preserve the reference projection/routing path. It is not a fresh standalone inference engine. Native serving and task-quality gains are unverified, and sanitized reproduction artifacts remain an outstanding draft checklist item.
Important limitations
Please keep this PR as draft until reproducible evidence attachments and upstream CI review are complete.