-
Notifications
You must be signed in to change notification settings - Fork 453
[model_free_ptq] Earlier Shape Validation
#2372
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
9 commits
Select commit
Hold shift + click to select a range
de1f591
[model_free_ptq] inline quantizable-name helper into iterator
kylesayrs 8e6fa15
fix typehints, styles
kylesayrs 4d372e5
do validation in threads
kylesayrs 328ac36
fix tests
kylesayrs 894dbcf
small cleanup
kylesayrs de7858a
add back accidentally deleted file
kylesayrs 49945cd
Merge branch 'main' into codex/investigate-issue-2371-on-github
HDCharles d3bb572
Merge branch 'main' into codex/investigate-issue-2371-on-github
HDCharles 67a89c1
Merge branch 'main' into codex/investigate-issue-2371-on-github
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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| from llmcompressor import model_free_ptq | ||
|
|
||
| MODEL_ID = "Qwen/Qwen3-0.6B" | ||
| SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-FP8-BLOCK" | ||
|
|
||
| # Apply FP8-Block to the model | ||
| # Once quantized, the model is saved | ||
| # using compressed-tensors to the SAVE_DIR. | ||
| model_free_ptq( | ||
| model_stub=MODEL_ID, | ||
| save_directory=SAVE_DIR, | ||
| scheme="FP8_BLOCK", | ||
| ignore=[ | ||
| "model.embed_tokens", | ||
| "lm_head", | ||
| ], | ||
| max_workers=15, | ||
| device="cuda:0", | ||
| ) |
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
39 changes: 39 additions & 0 deletions
39
tests/llmcompressor/pipelines/test_model_free_validation.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,39 @@ | ||
| import pytest | ||
| import torch | ||
| from compressed_tensors.quantization import QuantizationArgs, QuantizationScheme | ||
| from safetensors.torch import save_file | ||
|
|
||
| from llmcompressor.entrypoints.model_free.process import validate_file | ||
|
|
||
|
|
||
| def _get_block_scheme() -> QuantizationScheme: | ||
| return QuantizationScheme( | ||
| targets=["Linear"], | ||
| weights=QuantizationArgs( | ||
| num_bits=8, | ||
| type="float", | ||
| strategy="block", | ||
| symmetric=True, | ||
| dynamic=False, | ||
| block_structure=[16, 16], | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def test_validate_file_raises_for_non_2d_linear_weight(tmp_path): | ||
| path = tmp_path / "bad_shape.safetensors" | ||
| save_file({"model.layers.0.mlp.down_proj.weight": torch.ones(128)}, str(path)) | ||
|
|
||
| with pytest.raises(ValueError, match="model.layers.0.mlp.down_proj.weight"): | ||
| validate_file(path, None, _get_block_scheme(), [], None) | ||
|
|
||
|
|
||
| def test_validate_file_raises_for_block_incompatible_shape(tmp_path): | ||
| path = tmp_path / "bad_block.safetensors" | ||
| save_file( | ||
| {"model.layers.0.mlp.down_proj.weight": torch.ones(17, 16)}, | ||
| str(path), | ||
| ) | ||
|
|
||
| with pytest.raises(ValueError, match="strict division"): | ||
| validate_file(path, None, _get_block_scheme(), [], None) |
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.