-
Notifications
You must be signed in to change notification settings - Fork 365
feat(recipes): add KV cache cast variants (fp8_cast / nvfp4_cast) #1334
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
Merged
Merged
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
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 |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2024 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. | ||
|
|
||
| metadata: | ||
| recipe_type: ptq | ||
| description: >- | ||
| FP8 per-tensor weight and activation (W8A8), FP8 KV cache with constant amax | ||
| (skips KV calibration; amax hardcoded to FP8 E4M3 max 448.0), max calibration. | ||
| quantize: | ||
| algorithm: max | ||
| quant_cfg: | ||
| - quantizer_name: '*' | ||
| enable: false | ||
| - quantizer_name: '*input_quantizer' | ||
| cfg: | ||
| num_bits: e4m3 | ||
| axis: | ||
| - quantizer_name: '*weight_quantizer' | ||
| cfg: | ||
| num_bits: e4m3 | ||
| axis: | ||
| - quantizer_name: '*[kv]_bmm_quantizer' | ||
| enable: true | ||
| cfg: | ||
| num_bits: e4m3 | ||
| use_constant_amax: true | ||
| - quantizer_name: '*block_sparse_moe.gate*' | ||
| enable: false | ||
| - quantizer_name: '*linear_attn.conv1d*' | ||
| enable: false | ||
| - quantizer_name: '*lm_head*' | ||
| enable: false | ||
| - quantizer_name: '*mixer.conv1d*' | ||
| enable: false | ||
| - quantizer_name: '*mlp.gate.*' | ||
| enable: false | ||
| - quantizer_name: '*mlp.shared_expert_gate.*' | ||
| enable: false | ||
| - quantizer_name: '*output_layer*' | ||
| enable: false | ||
| - quantizer_name: '*proj_out.*' | ||
| enable: false | ||
| - quantizer_name: '*router*' | ||
| enable: false | ||
| - quantizer_name: 'output.*' | ||
| enable: false | ||
| - parent_class: 'nn.BatchNorm1d' | ||
| quantizer_name: '*' | ||
| enable: false | ||
| - parent_class: 'nn.BatchNorm2d' | ||
| quantizer_name: '*' | ||
| enable: false | ||
| - parent_class: 'nn.BatchNorm3d' | ||
| quantizer_name: '*' | ||
| enable: false | ||
| - parent_class: 'nn.LeakyReLU' | ||
| quantizer_name: '*' | ||
| enable: false | ||
78 changes: 78 additions & 0 deletions
78
modelopt_recipes/general/ptq/nvfp4_default-fp8_cast_kv.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,78 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2024 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. | ||
|
|
||
| metadata: | ||
| recipe_type: ptq | ||
| description: >- | ||
| NVFP4 W4A4, FP8 KV cache with constant amax (skips KV calibration; amax | ||
| hardcoded to FP8 E4M3 max 448.0), max calibration. | ||
| quantize: | ||
| algorithm: max | ||
| quant_cfg: | ||
| - quantizer_name: '*' | ||
| enable: false | ||
| - quantizer_name: '*weight_quantizer' | ||
| enable: true | ||
| cfg: | ||
| block_sizes: | ||
| -1: 16 | ||
| type: dynamic | ||
| scale_bits: e4m3 | ||
| num_bits: e2m1 | ||
| - quantizer_name: '*input_quantizer' | ||
| enable: true | ||
| cfg: | ||
| block_sizes: | ||
| -1: 16 | ||
| type: dynamic | ||
| scale_bits: e4m3 | ||
| num_bits: e2m1 | ||
| - quantizer_name: '*[kv]_bmm_quantizer' | ||
| enable: true | ||
| cfg: | ||
| num_bits: e4m3 | ||
| use_constant_amax: true | ||
| - quantizer_name: '*block_sparse_moe.gate*' | ||
| enable: false | ||
| - quantizer_name: '*linear_attn.conv1d*' | ||
| enable: false | ||
| - quantizer_name: '*lm_head*' | ||
| enable: false | ||
| - quantizer_name: '*mixer.conv1d*' | ||
| enable: false | ||
| - quantizer_name: '*mlp.gate.*' | ||
| enable: false | ||
| - quantizer_name: '*mlp.shared_expert_gate.*' | ||
| enable: false | ||
| - quantizer_name: '*output_layer*' | ||
| enable: false | ||
| - quantizer_name: '*proj_out.*' | ||
| enable: false | ||
| - quantizer_name: '*router*' | ||
| enable: false | ||
| - quantizer_name: 'output.*' | ||
| enable: false | ||
| - parent_class: 'nn.BatchNorm1d' | ||
| quantizer_name: '*' | ||
| enable: false | ||
| - parent_class: 'nn.BatchNorm2d' | ||
| quantizer_name: '*' | ||
| enable: false | ||
| - parent_class: 'nn.BatchNorm3d' | ||
| quantizer_name: '*' | ||
| enable: false | ||
| - parent_class: 'nn.LeakyReLU' | ||
| quantizer_name: '*' | ||
| enable: false |
84 changes: 84 additions & 0 deletions
84
modelopt_recipes/general/ptq/nvfp4_default-nvfp4_cast_kv.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,84 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2024 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. | ||
|
|
||
| metadata: | ||
| recipe_type: ptq | ||
| description: >- | ||
| NVFP4 W4A4, NVFP4 KV cache with constant amax (skips KV calibration; amax | ||
| hardcoded to FP8 E4M3 max 448.0 — the deployment kernel upcasts NVFP4 KV | ||
| values to FP8 before attention, so the scale must land in the FP8 range), | ||
| max calibration. | ||
| quantize: | ||
| algorithm: max | ||
| quant_cfg: | ||
| - quantizer_name: '*' | ||
| enable: false | ||
| - quantizer_name: '*weight_quantizer' | ||
| enable: true | ||
| cfg: | ||
| block_sizes: | ||
| -1: 16 | ||
| type: dynamic | ||
| scale_bits: e4m3 | ||
| num_bits: e2m1 | ||
| - quantizer_name: '*input_quantizer' | ||
| enable: true | ||
| cfg: | ||
| block_sizes: | ||
| -1: 16 | ||
| type: dynamic | ||
| scale_bits: e4m3 | ||
| num_bits: e2m1 | ||
| - quantizer_name: '*[kv]_bmm_quantizer' | ||
| enable: true | ||
| cfg: | ||
| block_sizes: | ||
| -1: 16 | ||
| type: dynamic | ||
| scale_bits: e4m3 | ||
| num_bits: e2m1 | ||
| use_constant_amax: true | ||
| - quantizer_name: '*block_sparse_moe.gate*' | ||
| enable: false | ||
| - quantizer_name: '*linear_attn.conv1d*' | ||
| enable: false | ||
| - quantizer_name: '*lm_head*' | ||
| enable: false | ||
| - quantizer_name: '*mixer.conv1d*' | ||
| enable: false | ||
| - quantizer_name: '*mlp.gate.*' | ||
| enable: false | ||
| - quantizer_name: '*mlp.shared_expert_gate.*' | ||
| enable: false | ||
| - quantizer_name: '*output_layer*' | ||
| enable: false | ||
| - quantizer_name: '*proj_out.*' | ||
| enable: false | ||
| - quantizer_name: '*router*' | ||
| enable: false | ||
| - quantizer_name: 'output.*' | ||
| enable: false | ||
| - parent_class: 'nn.BatchNorm1d' | ||
| quantizer_name: '*' | ||
| enable: false | ||
| - parent_class: 'nn.BatchNorm2d' | ||
| quantizer_name: '*' | ||
| enable: false | ||
| - parent_class: 'nn.BatchNorm3d' | ||
| quantizer_name: '*' | ||
| enable: false | ||
| - parent_class: 'nn.LeakyReLU' | ||
| quantizer_name: '*' | ||
| enable: false |
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.
Minor: Copyright year should be 2025 for new files, not 2024 (same applies to the other two new YAML files).