fix(kernels): store per-row scale for every row in layernorm_fp8 - #17
Open
pauliano22 wants to merge 1 commit into
Open
fix(kernels): store per-row scale for every row in layernorm_fp8#17pauliano22 wants to merge 1 commit into
pauliano22 wants to merge 1 commit into
Conversation
The scale store was gated behind `if tl.program_id(0) == 0`, so only row 0's Triton program ever wrote its scale. `scales` is allocated via torch.empty((M,)), so scales[1:] was left as uninitialized garbage — any caller dequantizing per-row FP8 output with these scales got wrong results for every row but the first. Each program already computes its own correct per-row `scale`; just store it unconditionally. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FLJ8M3VeafVxxNyQesNtfi
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.
What
kernels/layer_norm_fp8.py'slayernorm_quant_kernelgates the per-row FP8 scale store behindif tl.program_id(0) == 0:, so only row 0's Triton program ever writes its scale.Why it's a bug
scalesis allocated withtorch.empty((M,), ...)— uninitialized memory. Since one program handles each row (row_idx = tl.program_id(0)), the guard meansscales[1:]is never written and stays as garbage. Any caller dequantizing this kernel's per-row FP8 output (y_fp8 * scale) gets correct results only for row 0 and garbage for every other row.Fix
Each program already computes its own correct per-row
scalefrom that row's data — just store it unconditionally, matching howY_ptr's row is stored a line above.Testing
This repo has no CI or test suite (
run_all_benchmarks.pyis the only "check," and it requires a CUDA GPU). This sandbox has no GPU and notorch/tritoninstalled, so I could not execute this. The change is a minimal, one-line removal of an incorrectly-scoped conditional — worth a quickpython3 -csmoke test (create a smallx/w/b, calllayernorm_fp8, and confirmscaleshas no zero/garbage rows) on a GPU box before merging.🤖 Generated with Claude Code
https://claude.ai/code/session_01FLJ8M3VeafVxxNyQesNtfi
Generated by Claude Code