-
Notifications
You must be signed in to change notification settings - Fork 3.2k
PTQ model support, quant_cfg, and documentation updates #13519
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
22 commits
Select commit
Hold shift + click to select a range
9fe6457
Enable changing quant_cfg via command line in the ptq.py script
janekl 75df622
Add config to HFDeepSeekExporter
janekl 08ed32b
Use MODEL_NAME_TO_TYPE directly from model_utils
janekl 9357650
Merge branch 'main' into jlasek/quant_cfg_overrides
janekl 33a5053
Utility to detect HF DeepSeek version
janekl fedfd64
Apply isort and black reformatting
janekl 65952e6
Update broken links
janekl b2e9a5b
Rename temp var
janekl 968a36c
Give up quant_cfg_overrides param
janekl 058dc4b
Get model_type for HFAutoModelForCausalLM with mte
janekl 0715a40
Merge branch 'main' into jlasek/quant_cfg_overrides
janekl 985a94f
Utils to load quant_cfg from JSON file
janekl aee74f2
Apply isort and black reformatting
janekl 56f1233
Update quantization.rst links
janekl d6fa0cc
Improve load_quant_cfg plus unit test
janekl 890be02
Enable loading quant_cfg from a JSON file
janekl 9d32e32
Bugfix for AWQ methods
janekl 1e788f9
Apply isort and black reformatting
janekl 5c25289
Merge branch 'main' into jlasek/quant_cfg_overrides
janekl 62dd00d
Add copyright headers
janekl 685f8fd
Merge branch 'main' into jlasek/quant_cfg_overrides
janekl eedbfdc
Format error msg
janekl 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
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,58 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import json | ||
| from pathlib import Path | ||
| from typing import Any, Dict, Union | ||
|
|
||
| from nemo.utils.cast_utils import maybe_cast_to_type | ||
|
|
||
|
|
||
| def standardize_json_config(quant_cfg: Dict[str, Any]): | ||
| """Standardize the quantization configuration loaded from a JSON file to | ||
| ensure compatibility with modelopt. Modifiy the input dictionary in place. | ||
| Args: | ||
| quant_cfg (Dict[str, Any]): The quantization config dictionary to standardize. | ||
| """ | ||
| for key, value in quant_cfg.items(): | ||
| if key == "block_sizes": | ||
| value = {maybe_cast_to_type(k, int): v for k, v in value.items()} | ||
janekl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| quant_cfg[key] = value | ||
| elif key in {"num_bits", "scale_bits"} and isinstance(value, list): | ||
| quant_cfg[key] = tuple(value) | ||
| continue # No further processing needed | ||
| if isinstance(value, dict): | ||
| standardize_json_config(value) | ||
| elif isinstance(value, list): | ||
| for x in value: | ||
| if isinstance(x, dict): | ||
| standardize_json_config(x) | ||
|
|
||
|
|
||
| def load_quant_cfg(cfg_path: Union[str, Path]) -> Dict[str, Any]: | ||
| """Load quantization configuration from a JSON file and adjust for | ||
| modelopt standards if necessary. | ||
| Args: | ||
| cfg_path (str): Path to the quantization config JSON file. | ||
| Returns: | ||
| dict: The loaded quantization configuration. | ||
| """ | ||
| with open(cfg_path, "r") as f: | ||
| quant_cfg = json.load(f) | ||
|
|
||
| standardize_json_config(quant_cfg) | ||
| return quant_cfg | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does
HFDeepSeekExporteronly export V3 model?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Today only
DeepseekV3Configis importable fromtransformers==4.52.3so adding other models requires some extra work. I suggest we add them later once they can be imported fromtransformersto avoid workarounds. This can be then easily extended