[Pytorch][Common] Option to Disable 2nd level Scale in NVFP4 - #3297
[Pytorch][Common] Option to Disable 2nd level Scale in NVFP4#3297vthumbe1503 wants to merge 3 commits into
Conversation
Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>
Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>
for more information, see https://pre-commit.ci
Greptile SummaryAdds an option to omit NVFP4 second-level scaling and represent unit global scaling with absent amax buffers.
Confidence Score: 4/5The restricted-max grouped-GEMM scaling defect should be fixed before merging because supported 4over6 NVFP4 configurations can produce incorrectly scaled results. Grouped GEMM accepts operands quantized with an E4M3 maximum of 256, but the changed alpha path always normalizes their amax values using the unrestricted maximum of 448, breaking the encode/decode scaling contract. Files Needing Attention: transformer_engine/common/gemm/cublaslt_grouped_gemm.cu Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart LR
Q["NVFP4Quantizer"] -->|"disable_second_level_scale=false"| A["Allocate and compute amax"]
Q -->|"disable_second_level_scale=true"| N["Leave amax absent"]
A --> K["NVFP4 quantize/dequantize kernels"]
N --> K
K -->|"present amax"| S["Two-level global + block scaling"]
K -->|"null amax"| U["Unit global scale + block scaling"]
S --> G["GEMM alpha correction"]
U --> G
Reviews (1): Last reviewed commit: "[pre-commit.ci] auto fixes from pre-comm..." | Re-trigger Greptile |
| constexpr float kUnitGlobalScaleAmax = | ||
| transformer_engine::nvfp4::unit_global_scale_amax<transformer_engine::fp8e4m3, | ||
| transformer_engine::fp4e2m1>(); |
There was a problem hiding this comment.
Restricted-max GEMM scaling mismatch
When grouped GEMM receives 4over6 NVFP4 operands configured with nvfp4_e4m3_max=256, this path normalizes their amax values using the unrestricted 448*6 maximum instead of the 256*6 value used during quantization, causing numerically mis-scaled GEMM output.
Knowledge Base Used: Common core (transformer_engine/common)
There was a problem hiding this comment.
We dont have have the 4over6 support today for the graph safe path today(group_quantize + grouped_gemm). Do we need that support now @timmoon10 @ptrendx ? I think it would just increase the scope of this PR so it shouldnt be added now.
Description
Please include a brief summary of the changes, relevant motivation and context.
Fixes # (issue)
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: