-
Notifications
You must be signed in to change notification settings - Fork 368
Support NVFP4 W4A16 quantization #1313
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
Open
hychiang-git
wants to merge
10
commits into
main
Choose a base branch
from
hungyueh/modelopt-nvfp4-w4a16
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6e456b0
fix: PTQ 1GPU, export PP divisibility, hidden states conversations key
ChenhanYu 48d0a37
add nvfp4-w4a16 support
hychiang-git f34694b
Merge branch 'main' into hungyueh/modelopt-nvfp4-w4a16
hychiang-git 2ee0825
update CHANGELOG.rst and add test for nvfp4 w4a16
hychiang-git 0e8815d
tiny fix on CHANGELOG.rst
hychiang-git dc506c6
tiny fix on CHANGELOG.rst
hychiang-git d8611e2
f*{mod}*_quantizer -> f*{mod}*.weight_quantizer and f*{mod}*.input_qu…
hychiang-git 4b62138
Merge branch 'main' into hungyueh/modelopt-nvfp4-w4a16
hychiang-git 36ce897
Merge branch 'main' into hungyueh/modelopt-nvfp4-w4a16
hychiang-git 41f9988
Merge branch 'main' into hungyueh/modelopt-nvfp4-w4a16
hychiang-git 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,6 +118,7 @@ def _set_kv_cache_constant_amax(quant_cfg: list) -> None: | |
| "nvfp4_svdquant": mtq.NVFP4_SVDQUANT_DEFAULT_CFG, | ||
| "mxfp8": mtq.MXFP8_DEFAULT_CFG, | ||
| "nvfp4_local_hessian": mtq.NVFP4_W4A4_WEIGHT_LOCAL_HESSIAN_CFG, | ||
| "nvfp4_w4a16": mtq.NVFP4_W4A16_CFG, | ||
| } | ||
|
|
||
| KV_QUANT_CFG_CHOICES = { | ||
|
|
@@ -752,6 +753,12 @@ def export_quantized( | |
| extra_state_dict=mtp_state_dict, | ||
| ) | ||
|
|
||
| if args.qformat == "nvfp4_w4a16": | ||
| warnings.warn( | ||
| "TensorRT-LLM and SGLang do not support this format. " | ||
| "To serve on vLLM, convert the NVFP4 W4A16 checkpoint to compressed-tensors format." | ||
| ) | ||
|
|
||
| # Restore default padding and export the tokenizer as well. | ||
| if tokenizer is not None: | ||
| tokenizer.padding_side = default_padding_side | ||
|
|
@@ -1073,6 +1080,18 @@ def quantize_main( | |
| quant_cfg["quant_cfg"].append({"quantizer_name": pattern, "enable": False}) | ||
| print(f"Excluding MTP layer from quantization: {pattern}") | ||
|
|
||
| # Apply user-requested per-module exclusions (--exclude_modules). | ||
| if args.exclude_modules: | ||
| quant_cfg = copy.deepcopy(quant_cfg) | ||
| for mod in args.exclude_modules: | ||
| quant_cfg["quant_cfg"].append( | ||
| {"quantizer_name": f"*{mod}*.weight_quantizer", "enable": False} | ||
| ) | ||
| quant_cfg["quant_cfg"].append( | ||
| {"quantizer_name": f"*{mod}*.input_quantizer", "enable": False} | ||
| ) | ||
| print(f"Excluding module from quantization: {mod}") | ||
|
|
||
|
hychiang-git marked this conversation as resolved.
|
||
| # Use constant amax for KV quantizers when a cast format is selected. | ||
| # Recipes are authoritative for KV cache config (including use_constant_amax), | ||
| # so skip this post-hoc override when --recipe is used; rely on the YAML instead | ||
|
|
@@ -1242,6 +1261,17 @@ def parse_args() -> argparse.Namespace: | |
| default=False, | ||
| action="store_true", | ||
| ) | ||
| parser.add_argument( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel this is something we want to avoid, and if users want to exclude some modules, they should specify them in the quant_config or recipe. |
||
| "--exclude_modules", | ||
| nargs="+", | ||
| default=[], | ||
| metavar="MODULE", | ||
| help=( | ||
| "Module name patterns to exclude from quantization " | ||
| "(e.g. lm_head backbone.layers.0.mixer). " | ||
| "Appends a disable rule for each pattern's weight and input quantizers." | ||
| ), | ||
| ) | ||
| parser.add_argument( | ||
| "--gpu_max_mem_percentage", | ||
| help=( | ||
|
|
||
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
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.
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.
nvfp4_w4a16is added to choices but still blocked in auto-quantizeAt Line 122 the format is exposed as supported, but
auto_quantize()still rejects it via the hardcoded allowlist (Lines 325-345). This creates a confusing failure mode when users combine--auto_quantize_bitswith--qformat nvfp4_w4a16.Suggested fix
qformat in [ "fp8", "int8_sq", "int8_wo", "int4_awq", "nvfp4", "nvfp4_awq", "nvfp4_mse", + "nvfp4_w4a16", "w4a8_awq", "fp8_pb_wo", "w4a8_mxfp4_fp8", "nvfp4_mlp_only", "nvfp4_experts_only",📝 Committable suggestion
🤖 Prompt for AI Agents