-
Notifications
You must be signed in to change notification settings - Fork 524
Add LSQ (Learned Scale Quantization) support and recipes #1884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
92f5e74
Add LAQ (Learnable Amax Quantization) algorithm
realAsma 058492f
Add LSQ and Dual-LSQ QAD support and recipes
realAsma 6250837
Document LSQ amax learning rate
realAsma 9b3f8b9
Fix LSQ calibration for multi-weight quantizers
realAsma 2a06b57
Fix static quantizer NVFP4 dispatch
realAsma 66526ba
Refactor LSQ block amax computation
realAsma 61d85a1
docs: add LSQ changelog entry
realAsma 4bac049
docs: add PR 1884 QAD loss curves
realAsma dc1efc0
Add scale calibration config type
realAsma 09bf439
Fix static integer weight calibration finalization
realAsma 1501777
Derive LSQ per-tensor scale from global_amax at runtime
realAsma 1142b23
Unify static block weight quantizer promotion
realAsma 67f4d20
Simplify scale calibration dispatch
realAsma 27da9d6
Move scale calib alias into LSQ config
realAsma 70ba417
Fix LSQ scale calibration config typing
realAsma 0873ad1
Fix static quantizer meta materialization
realAsma 726be8f
Revert quantize recipe rename
realAsma 6133a91
Remove redundant LSQ per-tensor scale property
realAsma 4dd5d67
Remove redundant LSQ amax dtype patch
realAsma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Override the learning rate for LSQ's learnable amax parameters to 1e-4. | ||
| "*weight_quantizer._amax_pre": | ||
| lr: 1e-4 | ||
| "*weight_quantizer._amax_post": | ||
| lr: 1e-4 |
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
|
realAsma marked this conversation as resolved.
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Scale-only QAD for LSQ-quantized checkpoints | ||
|
|
||
| # Model | ||
| model_name_or_path: # e.g., qwen3-8b-lsq-quantized | ||
| output_dir: # e.g., qwen3-8b-lsq-scale-qad | ||
| attn_implementation: flash_attention_2 | ||
|
|
||
| # Distillation | ||
| distill: true | ||
| teacher_model: # e.g., Qwen/Qwen3-8B | ||
|
|
||
| # Dataset | ||
| dataset_config: configs/dataset/blend.yaml | ||
| train_samples: 20000 | ||
| eval_samples: 2000 | ||
|
|
||
| # Train only LSQ amax scale parameters. Tied LSQ exposes only _amax_post. | ||
| trainable_params: | ||
| - "*weight_quantizer._amax_pre" | ||
| - "*weight_quantizer._amax_post" | ||
|
|
||
| # Hyperparameters | ||
| num_train_epochs: 1.0 | ||
| # LSQ amax parameter requires higher learning rate than quantized weights | ||
| learning_rate: 1e-4 | ||
|
realAsma marked this conversation as resolved.
|
||
| weight_decay: 0.0 | ||
| per_device_train_batch_size: 2 | ||
| per_device_eval_batch_size: 2 | ||
| gradient_accumulation_steps: 2 | ||
| model_max_length: 8192 | ||
| warmup_ratio: 0.05 | ||
| lr_scheduler_type: cosine | ||
| use_liger_kernel: true | ||
| manual_gc: true | ||
| seed: 42 | ||
| do_train: true | ||
| do_eval: true | ||
|
|
||
| # Checkpointing | ||
| load_best_model_at_end: true | ||
| save_total_limit: 2 | ||
|
|
||
| # Evaluation | ||
| eval_on_start: true | ||
| eval_strategy: steps | ||
| eval_steps: 50 | ||
|
|
||
| # Logging | ||
| logging_steps: 1 | ||
| report_to: | ||
| - tensorboard | ||
|
realAsma marked this conversation as resolved.
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Full-parameter QAD for LSQ-quantized checkpoints | ||
|
|
||
| # Model | ||
| model_name_or_path: # e.g., qwen3-8b-lsq-quantized | ||
| output_dir: # e.g., qwen3-8b-lsq-full-qad | ||
| attn_implementation: flash_attention_2 | ||
|
|
||
| # Distillation | ||
| distill: true | ||
| teacher_model: # e.g., Qwen/Qwen3-8B | ||
|
|
||
| # Dataset | ||
| dataset_config: configs/dataset/blend.yaml | ||
| train_samples: 20000 | ||
| eval_samples: 2000 | ||
|
|
||
| # Hyperparameters | ||
| num_train_epochs: 1.0 | ||
| learning_rate: 1e-5 | ||
| # Learnable LSQ amax may need a higher learning rate than quantized weights. | ||
| lr_config: configs/train/lr/lr_config_amax.yaml | ||
|
realAsma marked this conversation as resolved.
|
||
| per_device_train_batch_size: 2 | ||
| per_device_eval_batch_size: 2 | ||
| gradient_accumulation_steps: 2 | ||
| model_max_length: 8192 | ||
| warmup_ratio: 0.05 | ||
| lr_scheduler_type: cosine | ||
| use_liger_kernel: true | ||
| manual_gc: true | ||
| seed: 42 | ||
| do_train: true | ||
| do_eval: true | ||
|
|
||
| # Checkpointing | ||
| load_best_model_at_end: true | ||
| save_total_limit: 2 | ||
|
|
||
| # Evaluation | ||
| eval_on_start: true | ||
| eval_strategy: steps | ||
| eval_steps: 50 | ||
|
|
||
| # Logging | ||
| logging_steps: 1 | ||
| report_to: | ||
| - tensorboard | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.