Repository navigation
[OMNIML-5899] Add IQ post-training quantization recipes #2449
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
Changes from all commits
f3fca65
b9dfae3
d658c5f
57b7f88
a2849c6
dfec594
6b5d603
eaee227
8020935
3390b98
f11eb63
871d4ee
e707df7
0ec5aa7
b820e47
bcabea8
9a6ce16
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 |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # 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. | ||
|
|
||
| # IQ1_S weight quantizer using the built-in fixed-scale codebook search. | ||
|
|
||
| # modelopt-schema: modelopt.torch.quantization.config.QuantizerAttributeConfig | ||
| num_bits: iq1_s | ||
| # Cost metadata for AutoQuantize's compression estimate only; it drives no packing or | ||
| # numerics. num_bits is the string "iq1_s", so the generic estimator cannot derive the | ||
| # storage cost: 50 packed bytes * 8 / 256 weights. Keep in sync with IQ1_S_BLOCK_BYTES. | ||
| effective_bits: 1.5625 | ||
| block_sizes: | ||
| -1: 256 | ||
|
Comment on lines
+24
to
+25
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. [SUGGESTION]
Why it matters: Suggestion: add a one-line comment mirroring the |
||
| backend: ggml | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # 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. | ||
|
|
||
| # IQ2_XS weight quantizer using the built-in fixed-scale codebook search. | ||
|
|
||
| # modelopt-schema: modelopt.torch.quantization.config.QuantizerAttributeConfig | ||
| num_bits: iq2_xs | ||
| # Cost metadata for AutoQuantize's compression estimate only; it drives no packing or | ||
| # numerics. num_bits is the string "iq2_xs", so the generic estimator cannot derive the | ||
| # storage cost: 74 packed bytes * 8 / 256 weights. Keep in sync with IQ2_XS_BLOCK_BYTES. | ||
| effective_bits: 2.3125 | ||
| block_sizes: | ||
| -1: 256 | ||
| backend: ggml |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # 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. | ||
|
|
||
| # QuantizeConfig preset for IQ1_S weight-only quantization. | ||
|
|
||
| # modelopt-schema: modelopt.torch.quantization.config.QuantizeConfig | ||
| imports: | ||
| base_disable_all: configs/ptq/units/base_disable_all | ||
| default_disabled_quantizers: configs/ptq/units/default_disabled_quantizers | ||
| iq1_s: configs/numerics/iq1_s | ||
|
|
||
| algorithm: | ||
| quant_cfg: | ||
| - $import: base_disable_all | ||
| - quantizer_name: '*weight_quantizer' | ||
| cfg: | ||
| $import: iq1_s | ||
| - quantizer_name: '*input_quantizer' | ||
| enable: false | ||
| - $import: default_disabled_quantizers |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # 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. | ||
|
|
||
| # QuantizeConfig preset for IQ2_XS weight-only quantization. | ||
|
|
||
| # modelopt-schema: modelopt.torch.quantization.config.QuantizeConfig | ||
| imports: | ||
| base_disable_all: configs/ptq/units/base_disable_all | ||
| default_disabled_quantizers: configs/ptq/units/default_disabled_quantizers | ||
| iq2_xs: configs/numerics/iq2_xs | ||
|
|
||
| algorithm: | ||
| quant_cfg: | ||
| - $import: base_disable_all | ||
| - quantizer_name: '*weight_quantizer' | ||
| cfg: | ||
| $import: iq2_xs | ||
| - quantizer_name: '*input_quantizer' | ||
| enable: false | ||
| - $import: default_disabled_quantizers |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
Comment on lines
+1
to
+2
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. [SUGGESTION] All six new YAML files carry only the two-line SPDX header, while every other recipe YAML in the tree ( This won't be caught by CI: |
||
| # | ||
| # 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. | ||
|
|
||
| # IQ1_S weight-only PTQ. | ||
|
|
||
| # modelopt-schema: modelopt.recipe.config.ModelOptPTQRecipe | ||
| imports: | ||
| preset: configs/ptq/presets/model/iq1_s | ||
|
|
||
| metadata: | ||
| description: >- | ||
| Applies uniform GGML-compatible IQ1_S weight-only quantization to eligible linear layers. | ||
| This is not a mixed per-tensor precision preset. No calibration data is required. | ||
| quantize: | ||
| $import: preset | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # 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. | ||
|
|
||
| # IQ2_XS weight-only PTQ. | ||
|
|
||
| # modelopt-schema: modelopt.recipe.config.ModelOptPTQRecipe | ||
| imports: | ||
| preset: configs/ptq/presets/model/iq2_xs | ||
|
|
||
| metadata: | ||
| description: >- | ||
| Applies uniform GGML-compatible IQ2_XS weight-only quantization to eligible linear layers. | ||
| This is not a mixed per-tensor precision preset. No calibration data is required. | ||
| quantize: | ||
| $import: preset |
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 do we need to record this? Is it needed for autoquant?
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.
Yes. effective_bits is cost metadata for AutoQuant/compression estimation; it does not affect packing or numerical quantization. Since num_bits is the string iq1_s, the generic estimator cannot infer its storage cost. This records the actual 50 × 8 / 256 = 1.5625 bits per weight. I’ll clarify the YAML comment.
Model-Optimizer/modelopt/torch/quantization/algorithms.py
Lines 184 to 195 in eaee227
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.
Comment expanded in
871d4ee9fto answer the "is it needed for autoquant?" part directly, since the arithmetic was the only thing it explained: