Repository navigation
fix(kernel): correct fp4 cache scale rounding - #720
Merged
Merged
Conversation
Collaborator
|
LGTM. |
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.
Based on the analysis and proposed fix in #673, fix DSV4.1 FP4 cache scale rounding reported on RTX 3090 Ti and reproduced on Radeon GPUs and RTX4090 with software emulation.
The compiler can fuse reciprocal multiplication with the emulated e4m3 magic-add into an FMA, skipping intermediate FP32 rounding and changing subnormal ties. Use
tl.math.div_rn(amax, 6.0)only for software emulation; retain the existing multiplication for native conversion through compile-timee4m3_native_cx().Validation:
python -m pytest tests/kernels/test_dsv41_pack.pyFor RTX4090 emulation, prefix the command with
FREETOKEN_FORCE_E4M3_EMU=1. KV pool and sparse-attention tests also pass (15/15 per path).AMD validation used ROCm 10.1 with #535's torchvision prerelease lower bound.
The checked RTX4090 default specializations produce byte-identical executable code before and after the change.