-
Notifications
You must be signed in to change notification settings - Fork 213
Kimi-k2 calib+export #655
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
base: main
Are you sure you want to change the base?
Kimi-k2 calib+export #655
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,9 +131,21 @@ Please reference our [framework scripts](#framework-scripts) and our [docs](http | |
| | QwQ | ✅ | - | - | - | ✅ | | ||
| | T5 | ✅ | ✅ | ✅ | ✅ | - | | ||
| | Whisper | ✅ | ❌ | ❌ | ❌ | - | | ||
| | Kimi-K2-Thinking-BF16 | ✅ | ❌ | ❌ | ❌ | ✅ | | ||
|
|
||
| > *This is a subset of the models supported. For the full list please check the [TensorRT-LLM support matrix](https://nvidia.github.io/TensorRT-LLM/reference/precision.html#support-matrix)* | ||
|
|
||
| > We recommend upcasting Kimi-K2-Thinking from INT4 to BF16 before running quantization. | ||
|
|
||
| ```python | ||
| from transformers import AutoModelForCausalLM | ||
|
Collaborator
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. could you move these to the examples_utils.py like: https://github.com/NVIDIA/TensorRT-Model-Optimizer/blob/main/examples/llm_ptq/example_utils.py#L303 |
||
| from transformers.utils.quantization_config import CompressedTensorsConfig | ||
|
|
||
| model = AutoModelForCausalLM.from_pretrained("moonshotai/Kimi-K2-Thinking", torch_dtype="auto", device_map = "auto", local_files_only = True, trust_remote_code = True, quantization_config = CompressedTensorsConfig(run_compressed=False)) | ||
|
|
||
| # And then save it with save_pretrained | ||
| ``` | ||
|
|
||
| > *<sup>1.</sup>The w4a8_awq is an experimental quantization scheme that may result in a higher accuracy penalty.* \ | ||
| > *<sup>2.</sup>For some models, there is only support for exporting quantized checkpoints.* \ | ||
| > *<sup>3.</sup>W4A8_AWQ is only available on some models but not all* \ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,7 @@ | |
| "w4a8_nvfp4_fp8": mtq.W4A8_NVFP4_FP8_CFG, | ||
| "w4a8_mxfp4_fp8": mtq.W4A8_MXFP4_FP8_CFG, | ||
| "nvfp4_mlp_only": mtq.NVFP4_MLP_ONLY_CFG, | ||
| "nvfp4_mlp_experts_only": mtq.NVFP4_MLP_EXPERTS_ONLY_CFG, | ||
|
||
| } | ||
|
|
||
| KV_QUANT_CFG_CHOICES = { | ||
|
|
@@ -121,6 +122,7 @@ def auto_quantize( | |
| "fp8_pb_wo", | ||
| "w4a8_mxfp4_fp8", | ||
| "nvfp4_mlp_only", | ||
| "nvfp4_mlp_exports_only", | ||
jingyu-ml marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ] | ||
| for qformat in qformat_list | ||
| ), "One or more quantization formats provided are not supported for unified checkpoint export" | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -623,6 +623,25 @@ | |||||||||||||||||||||||||||||||||||||
| "algorithm": "max", | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| NVFP4_MLP_EXPERTS_ONLY_CFG = { | ||||||||||||||||||||||||||||||||||||||
| "quant_cfg": { | ||||||||||||||||||||||||||||||||||||||
| "*mlp.experts*weight_quantizer": { | ||||||||||||||||||||||||||||||||||||||
| "num_bits": (2, 1), | ||||||||||||||||||||||||||||||||||||||
| "block_sizes": {-1: 16, "type": "dynamic", "scale_bits": (4, 3)}, | ||||||||||||||||||||||||||||||||||||||
| "enable": True, | ||||||||||||||||||||||||||||||||||||||
| "pass_through_bwd": True, | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| "*mlp.experts*input_quantizer": { | ||||||||||||||||||||||||||||||||||||||
| "num_bits": (2, 1), | ||||||||||||||||||||||||||||||||||||||
| "block_sizes": {-1: 16, "type": "dynamic", "scale_bits": (4, 3)}, | ||||||||||||||||||||||||||||||||||||||
| "enable": True, | ||||||||||||||||||||||||||||||||||||||
| "pass_through_bwd": True, | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| **_default_disabled_quantizer_cfg, | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| "algorithm": "max", | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| NVFP4_MLP_EXPERTS_ONLY_CFG = { | |
| "quant_cfg": { | |
| "*mlp.experts*weight_quantizer": { | |
| "num_bits": (2, 1), | |
| "block_sizes": {-1: 16, "type": "dynamic", "scale_bits": (4, 3)}, | |
| "enable": True, | |
| "pass_through_bwd": True, | |
| }, | |
| "*mlp.experts*input_quantizer": { | |
| "num_bits": (2, 1), | |
| "block_sizes": {-1: 16, "type": "dynamic", "scale_bits": (4, 3)}, | |
| "enable": True, | |
| "pass_through_bwd": True, | |
| }, | |
| **_default_disabled_quantizer_cfg, | |
| }, | |
| "algorithm": "max", | |
| } |
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.
that will quantize mlp.shared_experts
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.
this is great. Let's not creating more cfgs
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.
Is it a recommendation or it's something we have to do? An alterantive is to up cast the in4 to BF16 during calibration like we did with DS.
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.
But there’s no INT4 support in PyTorch, as we discussed. People have to use vLLM if they want INT4. Me and Zhiyu are looking into the vLLM calibration of this model