-
Notifications
You must be signed in to change notification settings - Fork 581
Add NVFP4 PTQ recipes for zai-org/GLM-5.3-Flash (experts-only and experts + dense MLP) #2312
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
shengliangxu
wants to merge
3
commits into
main
Choose a base branch
from
shengliangx/glm-5.3-flash-recipe
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.
+195
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
105 changes: 105 additions & 0 deletions
105
modelopt_recipes/models/zai-org/GLM-5.3-Flash/ptq/nvfp4_experts_dense_mlp-kv_fp8_cast.yaml
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,105 @@ | ||
| # 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. | ||
|
|
||
| # Recipe for zai-org/GLM-5.3-Flash: NVFP4 on the routed experts and the dense MLP, FP8 KV cache. | ||
| # | ||
| # The wider sibling of `nvfp4_experts_only-kv_fp8_cast`. GLM-5.3-Flash is a `glm5_next` VLM | ||
| # MoE -- 45 decoder layers, 288 routed experts, and HYBRID attention: KDA (linear-attention) | ||
| # layers interleaved with NoPE sparse-MLA layers. It needs transformers >= 5.16.1 (earlier | ||
| # releases cannot parse the config). | ||
| # | ||
| # Quantized: the routed experts AND the dense MLP, W4A4 -- both the weight and the input | ||
| # quantizers are NVFP4 -- plus an FP8 KV cache in cast mode. Everything else stays BF16: | ||
| # shared experts, the router gate, both attention families, the vision tower, embeddings | ||
| # and lm_head. | ||
| # | ||
| # How little "dense MLP" adds: `mlp_layer_types` marks layers 0-2 `dense` and 3-44 `sparse`, | ||
| # so only 3 of the 45 layers have a plain MLP -- 9 modules in total (`mlp.gate_proj`, | ||
| # `mlp.up_proj`, `mlp.down_proj` each). The other 42 layers carry `mlp.experts.<i>.*`. | ||
| # | ||
| # The one rule that is not obvious is the trailing `*visual*` disable, and it is load-bearing. | ||
| # The vision tower reuses the same leaf names -- `model.visual.blocks.<N>.mlp.gate_proj` and | ||
| # friends, across 24 blocks -- so the dense-MLP patterns match 144 modules inside it. Entries | ||
| # apply in order, so the disable has to come LAST or the vision tower is quantized by accident. | ||
| # (The experts-only sibling needs no such rule: `*.experts.*` matches nothing under | ||
| # `model.visual.*`.) | ||
| # | ||
| # Two model-specific notes: | ||
| # | ||
| # * `layerwise.enable=false` is required, not incidental. This is a VLM, so the decoder | ||
| # layers nest under `model.language_model.layers` and layerwise_calibrate cannot find | ||
| # them. | ||
| # | ||
| # * The MTP head is inlined as decoder layer 45 and is NOT quantized. The config declares | ||
| # `num_hidden_layers: 45`, so transformers builds layers 0-44 and never instantiates | ||
| # layer 45; no quantizer attaches to it and it stays BF16. | ||
| # | ||
| # Like the sibling, the shared `default_disabled_quantizers` unit is deliberately not imported. | ||
| # Of its patterns only `*visual*` changes anything here; every other one either matches no | ||
| # module in this model or matches a module `base_disable_all` already left off (`lm_head`, the | ||
| # `mlp.gate.` routers), and none of them are re-enabled below. Two patterns that look riskier | ||
| # than they are: `*.experts.*` needs a literal `.experts.`, so `mlp.shared_experts.*` does not | ||
| # match; and `*mlp.gate_proj*` needs `mlp.gate_proj`, which the router `mlp.gate` lacks. | ||
|
|
||
| imports: | ||
| base_disable_all: configs/ptq/units/base_disable_all | ||
| nvfp4: configs/numerics/nvfp4 | ||
| kv_fp8_cast: configs/ptq/units/kv_fp8_cast | ||
|
|
||
| metadata: | ||
| recipe_type: ptq | ||
| description: >- | ||
| GLM-5.3-Flash: NVFP4 (W4A4) on the routed experts and on the dense MLP of layers 0-2, | ||
| plus an FP8 KV cache in cast mode using constant amax; max calibration. Shared experts, | ||
| router gate, KDA and MLA attention, vision tower, embeddings, lm_head and the inlined | ||
| MTP layer all stay BF16. | ||
| quantize: | ||
| algorithm: | ||
| method: max | ||
| # Max calibration is fast and does not typically need checkpointing. | ||
| # layerwise.enable=false required for VLMs where the decoder layers are nested under | ||
| # `model.language_model.layers` (layerwise_calibrate can't find them otherwise). | ||
| layerwise: {enable: false} | ||
| quant_cfg: | ||
| - $import: base_disable_all | ||
| # Routed experts: layers 3-44, 288 per layer. | ||
| - quantizer_name: '*.experts.*weight_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| - quantizer_name: '*.experts.*input_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| # Dense MLP: layers 0-2 -- and, until the last entry undoes it, the vision tower. | ||
| - quantizer_name: '*mlp.gate_proj*weight_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| - quantizer_name: '*mlp.gate_proj*input_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| - quantizer_name: '*mlp.up_proj*weight_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| - quantizer_name: '*mlp.up_proj*input_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| - quantizer_name: '*mlp.down_proj*weight_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| - quantizer_name: '*mlp.down_proj*input_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| - $import: kv_fp8_cast | ||
| # MUST stay last: keeps the vision tower BF16 after the dense-MLP patterns matched it. | ||
| - {quantizer_name: '*visual*', enable: false} |
76 changes: 76 additions & 0 deletions
76
modelopt_recipes/models/zai-org/GLM-5.3-Flash/ptq/nvfp4_experts_only-kv_fp8_cast.yaml
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,76 @@ | ||
| # 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. | ||
|
|
||
| # Recipe for zai-org/GLM-5.3-Flash: NVFP4 on the routed experts only, FP8 KV cache. | ||
| # | ||
| # GLM-5.3-Flash is a `glm5_next` VLM MoE -- 45 decoder layers, 288 routed experts, and | ||
| # HYBRID attention: KDA (linear-attention) layers interleaved with NoPE sparse-MLA | ||
| # layers. It needs transformers >= 5.16.1 (earlier releases cannot parse the config). | ||
| # | ||
| # Quantized: the routed experts only, W4A4 -- both the weight and the input quantizers | ||
| # are NVFP4 -- plus an FP8 KV cache in cast mode. Everything else stays BF16: the dense | ||
| # MLP, shared experts, the router gate, both attention families, the vision tower, | ||
| # embeddings and lm_head. | ||
| # | ||
| # The quant_cfg is deliberately minimal. `base_disable_all` sets every quantizer to | ||
| # `enable: false`, and the only entries after it re-enable the routed experts and the KV | ||
| # cache -- so nothing else needs listing. In particular the shared `default_disabled_quantizers` | ||
| # unit is not imported: every pattern it turns off (router gates, `lm_head`, the linear-attn | ||
| # `conv1d` and `in_proj_a`/`in_proj_b`, ...) is already off and is not matched by | ||
| # `*.experts.*`. Note `*.experts.*` requires a literal `.experts.`, so `mlp.shared_experts.*` | ||
| # does not match it and the shared experts stay BF16. The same literal is why the vision tower | ||
| # needs no explicit disable here: it is a dense ViT whose 224 modules carry no `experts` in any | ||
| # name, so `*.experts.*` cannot reach `model.visual.*`. The wider | ||
| # `nvfp4_experts_dense_mlp-kv_fp8_cast` sibling does need one -- its `*mlp.*_proj*` patterns | ||
| # match the vision tower's identically named `gate_proj`/`up_proj`/`down_proj` leaves. | ||
| # | ||
| # Two model-specific notes: | ||
| # | ||
| # * `layerwise.enable=false` is required, not incidental. This is a VLM, so the decoder | ||
| # layers nest under `model.language_model.layers` and layerwise_calibrate cannot find | ||
| # them. | ||
| # | ||
| # * The MTP head is inlined as decoder layer 45 and is NOT quantized. The config declares | ||
| # `num_hidden_layers: 45`, so transformers builds layers 0-44 and never instantiates | ||
| # layer 45; no quantizer attaches to it and it stays BF16. | ||
|
|
||
| imports: | ||
| base_disable_all: configs/ptq/units/base_disable_all | ||
| nvfp4: configs/numerics/nvfp4 | ||
| kv_fp8_cast: configs/ptq/units/kv_fp8_cast | ||
|
|
||
| metadata: | ||
| recipe_type: ptq | ||
| description: >- | ||
| GLM-5.3-Flash: NVFP4 (W4A4) on the routed experts only, plus an FP8 KV cache in cast | ||
| mode using constant amax; max calibration. The dense MLP, shared experts, router gate, | ||
| KDA and MLA attention, vision tower, embeddings, lm_head and the inlined MTP layer all | ||
| stay BF16. | ||
| quantize: | ||
| algorithm: | ||
| method: max | ||
| # Max calibration is fast and does not typically need checkpointing. | ||
| # layerwise.enable=false required for VLMs where the decoder layers are nested under | ||
| # `model.language_model.layers` (layerwise_calibrate can't find them otherwise). | ||
| layerwise: {enable: false} | ||
| quant_cfg: | ||
| - $import: base_disable_all | ||
| - quantizer_name: '*.experts.*weight_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| - quantizer_name: '*.experts.*input_quantizer' | ||
| cfg: | ||
| $import: nvfp4 | ||
| - $import: kv_fp8_cast | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.