-
Notifications
You must be signed in to change notification settings - Fork 625
MSE Observer Enhancement #2950
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
MSE Observer Enhancement #2950
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
10a566d
Add expand parameter to MSE observers and nvfp4_expanded variants
Roderick-Wu c338535
move arg update to grid search
Roderick-Wu 7cf9978
linting
Roderick-Wu bacbbc9
remove new imatrix observer
28306fc
Merge branch 'main' into Roderick-Wu/big-grid
Roderick-Wu e75c862
Update examples/quantization_w4a16_fp4/nvfp4/llama3_nvfp4_expanded_ms…
Roderick-Wu 0ccd765
lint
06ee434
Merge branch 'main' into Roderick-Wu/big-grid
kylesayrs 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
41 changes: 41 additions & 0 deletions
41
examples/quantization_w4a16_fp4/nvfp4/llama3_nvfp4_expanded_mse_example.py
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,41 @@ | ||
| """NVFP4 quantization with expanded MSE observer. | ||
|
|
||
| The ``nvfp4_expanded_mse`` observer searches over a range of per-group | ||
| scale expansions (1.8x down to 0.8x of the observed range) to find the | ||
| scale that minimizes quantization error. This typically gives better | ||
| quality than the default minmax observer at the cost of a longer | ||
| calibration pass. | ||
|
|
||
| Usage:: | ||
|
|
||
| python llama3_nvfp4_expanded_mse_example.py | ||
| """ | ||
|
|
||
| from transformers import AutoModelForCausalLM, AutoTokenizer | ||
|
|
||
| from llmcompressor import oneshot | ||
| from llmcompressor.modifiers.quantization import QuantizationModifier | ||
|
|
||
| MODEL_ID = "meta-llama/Llama-3.1-8B-Instruct" | ||
|
|
||
| model = AutoModelForCausalLM.from_pretrained(MODEL_ID) | ||
| tokenizer = AutoTokenizer.from_pretrained(MODEL_ID) | ||
|
|
||
| recipe = QuantizationModifier( | ||
| scheme="NVFP4", | ||
| weight_observer="nvfp4_expanded_mse", | ||
| ignore=["lm_head"], | ||
| ) | ||
|
|
||
| oneshot( | ||
| model=model, | ||
| recipe=recipe, | ||
| dataset="ultrachat_200k", | ||
| splits="train_sft", | ||
| num_calibration_samples=512, | ||
| max_seq_length=2048, | ||
| ) | ||
|
|
||
| SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-NVFP4-expanded-mse" | ||
| model.save_pretrained(SAVE_DIR, save_compressed=True) | ||
| tokenizer.save_pretrained(SAVE_DIR) | ||
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.
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.