Update quant.pyfix: add pack_dim to per_1x32_f4_quant for tl.dot_scaled RHS compatibility#2704
Open
Update quant.pyfix: add pack_dim to per_1x32_f4_quant for tl.dot_scaled RHS compatibility#2704
Conversation
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
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.
Problem
per_1x32_f4_quantalways packs FP4 values along the last dimension (dim=-1). This is correct fortl.dot_scaledLHS operandA(M, K) → (M, K//2), but produces the wrong layout for the RHS operand:per_1x32_f4_quant(B)whereB(K, N)→fp4=(K, N//2)(packed along N)tl.dot_scaled:fp4=(K//2, N)(packed along K)This dimension mismatch causes
Memory Access Faultwhen AITER-quantized data is passed totl.dot_scaledon MI355X/MI350 hardware.Additional finding: Triton 3.6 breaking change
Triton 3.6 also changed the expected
rhs_scaleshape:rhs_scale = (K//32, N)rhs_scale = (N, K//32)← transposedSolution
Add a
pack_dimparameter toper_1x32_f4_quant:pack_dim=-1(default): pack along last dimension → fordot_scaledLHS (backward compatible)pack_dim=0: pack along first dimension → fordot_scaledRHSAlso adds
per_1x32_f4_quant_for_dot_scaled()convenience function.Usage
Verification
Tested on MI350 (GFX950/CDNA4) with both Triton 3.4 and 3.6:
Backward compatibility verified:
pack_dim=-1(default) produces identical output to the original function.