-
Notifications
You must be signed in to change notification settings - Fork 553
feat(quantization): PTQ support for Step-3.7 MoE checkpoints #2202
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?
Changes from all 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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # 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. | ||
|
|
||
| # Model-specific PTQ recipe: Step-3.7 routed-experts-only NVFP4 with FP8 KV-cache cast. | ||
| # | ||
| # Step's remote code names the MoE block `moe` (not `experts` / `block_sparse_moe`), so the | ||
| # general experts-only recipe matches nothing on this architecture. The routed experts are | ||
| # `moe.{gate,up,down}_proj`, the router is `moe.gate`, and each MoE layer also has a dense | ||
| # `share_expert` that stays in BF16. | ||
|
|
||
| imports: | ||
| base_disable_all: configs/ptq/units/base_disable_all | ||
| default_disabled_quantizers: configs/ptq/units/default_disabled_quantizers | ||
| nvfp4: configs/numerics/nvfp4 | ||
| kv_fp8_cast: configs/ptq/units/kv_fp8_cast | ||
|
|
||
| metadata: | ||
| recipe_type: ptq | ||
| description: >- | ||
| Applies dynamic NVFP4 to Step-3.7 routed-expert weight and input quantizers, plus FP8 | ||
| KV-cache cast mode using constant amax; the router, the shared expert and the dense MLPs | ||
| stay unquantized. Uses max calibration. | ||
|
|
||
| quantize: | ||
| algorithm: | ||
| method: max | ||
| layerwise: false | ||
| quant_cfg: | ||
| - $import: base_disable_all | ||
| - quantizer_name: '*moe*weight_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| - quantizer_name: '*moe*input_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| - $import: kv_fp8_cast | ||
| - $import: default_disabled_quantizers | ||
| # Router and shared expert are matched by `*moe*` above; disable them last (later wins). | ||
| - quantizer_name: '*moe.gate.*' | ||
| enable: false | ||
| - quantizer_name: '*share_expert*' | ||
| enable: false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # 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. | ||
|
|
||
| # Model-specific PTQ recipe: Step-3.7 MLP/MoE NVFP4 with calibrated FP8 KV cache. | ||
| # | ||
| # Same module-naming caveat as the experts-only recipe: Step's MoE block is `moe`, so the | ||
| # general `*mlp*` / `*.experts.*` patterns reach only the dense layers' `mlp` submodules and | ||
| # leave the routed experts — the bulk of the model — in BF16. | ||
|
|
||
| imports: | ||
| base_disable_all: configs/ptq/units/base_disable_all | ||
| default_disabled_quantizers: configs/ptq/units/default_disabled_quantizers | ||
| nvfp4: configs/numerics/nvfp4 | ||
| kv_fp8: configs/ptq/units/kv_fp8 | ||
|
|
||
| metadata: | ||
| recipe_type: ptq | ||
| description: >- | ||
| Applies dynamic NVFP4 to Step-3.7 routed-expert and dense-MLP weight and input | ||
| quantizers, plus calibrated FP8 KV-cache quantization; the router and the shared expert | ||
| stay unquantized. Uses max calibration. | ||
|
|
||
| quantize: | ||
| algorithm: | ||
| method: max | ||
| layerwise: false | ||
| quant_cfg: | ||
| - $import: base_disable_all | ||
| - quantizer_name: '*moe*weight_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| - quantizer_name: '*moe*input_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| - quantizer_name: '*mlp*weight_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| - quantizer_name: '*mlp*input_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| - $import: kv_fp8 | ||
| - $import: default_disabled_quantizers | ||
| # Router and shared expert are matched by `*moe*` above; disable them last (later wins). | ||
| - quantizer_name: '*moe.gate.*' | ||
| enable: false | ||
| - quantizer_name: '*share_expert*' | ||
| enable: false | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -295,6 +295,15 @@ A lighter case: **`step3p5/Step3.5-Flash/ptq/nvfp4-mlp-only`** is close to | |||||||||||||
| to one released checkpoint and carrying instance-specific disables | ||||||||||||||
| (`share_expert`, `moe.gate`, the conv1d branches). | ||||||||||||||
|
|
||||||||||||||
| **`step3p7/ptq/{nvfp4_experts_only-kv_fp8_cast,nvfp4_mlp_only-kv_fp8}`** are the | ||||||||||||||
| Step-3.7 equivalents, and the reason they exist is **module naming**: Step calls | ||||||||||||||
| the MoE block `moe` and the dense sibling `share_expert`, so the general | ||||||||||||||
| recipes' `*.experts.*`, `*block_sparse_moe*` and `*mlp*` patterns match nothing | ||||||||||||||
| on the routed experts — the general recipe would quantize *nothing* and export a | ||||||||||||||
| checkpoint with `quant_algo: null`. These select `*moe*` instead and disable the | ||||||||||||||
| router (`moe.gate`) and `share_expert` on top. Use them, not the general | ||||||||||||||
| recipes, for any Step checkpoint. | ||||||||||||||
|
Comment on lines
+303
to
+305
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. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Scope the recommendation to Step-3.7. The text says to use these recipes "for any Step checkpoint". The preceding paragraph documents a separate 📝 Proposed wording fix-router (`moe.gate`) and `share_expert` on top. Use them, not the general
-recipes, for any Step checkpoint.
+router (`moe.gate`) and `share_expert` on top. Use them, not the general
+recipes, for Step-3.7 checkpoints; Step-3.5 has its own recipe above.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| ### Algorithm overrides — `gemma`, `gemma4`, `mpt` | ||||||||||||||
|
|
||||||||||||||
| These quantize the **same layers** as the general recipes; only the | ||||||||||||||
|
|
||||||||||||||
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Both recipes carry the same inaccurate comment about
*share_expert*. The comment claims*moe*matches the shared expert, but Step's shared expert path islayers.N.share_expert.*and contains nomoesegment. The disable entry remains a valid guard; only the stated reason is wrong.modelopt_recipes/huggingface/step3p7/ptq/nvfp4_mlp_only-kv_fp8.yaml#L55-L59: restrict the "matched by*moe*" claim to the router and describeshare_expertas an explicit guard.modelopt_recipes/huggingface/step3p7/ptq/nvfp4_experts_only-kv_fp8_cast.yaml#L50-L54: apply the identical comment fix.📍 Affects 2 files
modelopt_recipes/huggingface/step3p7/ptq/nvfp4_mlp_only-kv_fp8.yaml#L55-L59(this comment)modelopt_recipes/huggingface/step3p7/ptq/nvfp4_experts_only-kv_fp8_cast.yaml#L50-L54🤖 Prompt for AI Agents