feat: refine quant config arguments#379
Open
RuibinCheung wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR exposes previously hardcoded low-precision (MXFP8/MXFP4) scaling-recipe decisions as user-configurable fields on the quantization config objects, and wires those fields into the FP4/FP8 GEMM operators so users can tune numerical behavior without modifying kernels.
Changes:
- Added scaling-recipe knobs to
Float8QuantConfig/Float4QuantConfig(2D-block weight scaling; FP4 gradient RHT). - Updated FP4 GEMM forward/backward to use the config-driven scaling recipes instead of hardcoded values.
- Updated FP8 MX GEMM to derive
use_2d_blockfrom the config instead of hardcoding it.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
primus_turbo/pytorch/core/low_precision.py |
Adds new config fields controlling scaling recipe behavior. |
primus_turbo/pytorch/ops/gemm_fp4.py |
Threads FP4 weight 2D-block scaling + gradient RHT from config into forward/backward quantization recipes. |
primus_turbo/pytorch/ops/gemm_fp8.py |
Threads FP8 MX weight 2D-block scaling from config into the quantization recipe. |
tests/pytorch/ops/test_gemm_fp4.py |
Updates FP4 GEMM tests to construct configs consistent with the new config-driven recipes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
169
to
+172
| strategy: ScalingStrategy = ScalingStrategy.DYNAMIC | ||
| scale_dtype: ScaleDtype = ScaleDtype.FP32 | ||
| block_size: Optional[int] = None # Default: not used for tensorwise/rowwise | ||
| use_2d_block_weight_scaling: Optional[bool] = None |
Comment on lines
196
to
199
| block_size: int = 32 | ||
| use_2d_block_weight_scaling: bool = False | ||
| use_gradient_rht: bool = False | ||
| use_gradient_sr: bool = 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


Description
This PR exposes the low-precision (FP8/FP4) scaling strategy to users through the quantization config objects. Previously, key scaling behaviors in the MX GEMM forward and backward passes (such as 2D block weight scaling and randomized Hadamard transform on gradients) were hardcoded inside the operators, which prevented users from tuning the numerical recipe for their own training setups. By surfacing these knobs in
Float8QuantConfigandFloat4QuantConfig, users can now control the scaling recipe without modifying internal kernel code.Fixes # (issue)
Type of change
Changes
Please list the changes introduced in this PR:
use_2d_block_weight_scalingfield toFloat8QuantConfiginprimus_turbo/pytorch/core/low_precision.py.use_2d_block_weight_scalinganduse_gradient_rhtfields toFloat4QuantConfiginprimus_turbo/pytorch/core/low_precision.py.FP4GemmMXFunctioninprimus_turbo/pytorch/ops/gemm_fp4.pyto drive the weight 2D-block scaling recipe fromconfig.use_2d_block_weight_scalingand the gradient/weight RHT recipe fromconfig.use_gradient_rhtinstead of hardcoded values, in both the forward and backward passes.FP8GemmMXFunctioninprimus_turbo/pytorch/ops/gemm_fp8.pyto derive the weight scaling recipe'suse_2d_blockfrom the config instead of a hardcodedTrue.Checklist: