[BugFix][Quant] Guard scale tails and FP32 absmax#15
Open
JayceSu98 wants to merge 1 commit into
Open
Conversation
The full H100/CuTeDSL correctness run covers token and hidden sizes that do not land exactly on the kernel tile, scaling-factor block, or E5M6 packing granularity. Those edge tiles exposed two independent quantization issues. First, cast-back and lossless/per-token cast kernels could load or store scaling factors for padded token/channel blocks. The same edge condition also applied to packed E5M6 output rows and columns, where the final tile may not contain a full logical token row or hidden group. Second, per-token scale generation used in_config.dtype as the absmax fragment dtype. That dtype describes the input tensor storage, not the reduction accumulator. For BF16 and narrow quantization paths, keeping absmax in the input dtype can round or overflow the scale path before the final output cast, producing byte mismatches against the PyTorch reference. Guard scale loads/stores and packed E5M6 stores with the real token/channel extents, keep invalid scale lanes zero-initialized, and use FP32 fragments for per-token absmax reductions before computing the reciprocal scale. Co-authored-by: dingsg <shengge.ding@enflame-tech.com>
88a6293 to
82fbd40
Compare
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.
Context
This updates the existing Quant PR to cover the complete Quant-side fix from the H100 CuTeDSL full correctness and benchmark run.
The earlier version of this PR only handled the BF16 per-token FP32 amax issue. Full coverage also exposed tail-tile scale-grid and packed E5M6 store bounds issues, so this PR now keeps the Quant fixes together in one review instead of opening duplicate overlapping PRs.
Problems Found
Full H100/CuTeDSL coverage exercises quantization shapes where token counts, hidden sizes, scale blocks, and packed E5M6 groups do not always land exactly on a kernel tile boundary.
That exposed two TileKernels-side issues:
in_config.dtypeas the absmax fragment dtype, even though that dtype describes input storage rather than the reduction accumulator.For BF16 and narrow quantization paths, using the input storage dtype as the absmax accumulator can round or overflow the scale path before the final cast, producing byte mismatches against the PyTorch reference.
Fix
T.float32fragments for per-token absmax reductions before computing reciprocal scales.Why this belongs in TileKernels
These are kernel-level bounds and accumulator-dtype issues. The implementation schedules aligned tile work for performance, but memory accesses and reduction precision must still follow the logical tensor/scaling-factor layout. The fix is not tied to one CuTeDSL package version.
Relationship to Existing PRs
Validation
Validated as part of the H100 PCIe CuTeDSL full correctness and benchmark run after the matching TileLang CuTeDSL fixes were applied.
Local sanity checks for the current branch:
git diff --check origin/main..82fbd40ruff checkon the changed TileKernels Python filesJayceSu98 jayce.su@enflame-tech.com authored and validated this patch.
Co-authored-by: dingsg shengge.ding@enflame-tech.com