Repository navigation
Conversation
This branch has not been deployed
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.
Summary
When
attention_qk_normis enabled alongsideKATAGO_FUSED_ROPE_BACKWARD, applying Q/KRMSNormas separate ops adds extra memory-bound read/write passes over Q and K in both forward and backward and saves an extra copy of rotated Q and K. Since 2D RoPE rotation preserves vector norm, we can apply the per-head RMSNorm in registers inside the existing RoPE Triton kernel structure.katago::rope_qkn_forward/katago::rope_qkn_backwardandlearnable_rope_qkninpython/katago/train/fused_rope.py, mirroringlearnable_rope_qkvwithout modifying the non-QK-norm kernels.TransformerAttentionBlockbehindKATAGO_FUSED_QK_NORM(default1), automatically falling back wheneverKATAGO_FUSED_ROPE_BACKWARD=0,use_qk_norm=False, or single-graph compile disables fused RoPE. Compatible withtorch.compileper-block trunk and-attn-logit-penalty-cap.test_fused_rope_qkn_matches_autogradinpython/tests/test_fused_kernels.pycoveringfp32,fp16(including odd batch size), andbf16(v_head_dim != head_dim, small board).Numerics & Measurements
Everything inside the kernel is computed in fp32 from the packed QKV projection and rounded once on store (the separate-op path rounds rotated Q/K before normalizing, so the two differ only at fp16/bf16 rounding level).
Measured on RTX PRO 6000 Blackwell (
b13c768h12f896nbt3tflrsqkn-fson-silu, batch 128, FP16 AMP + Aurora + per-block compile):~2e-4rel L2 error in fp16, matching the separate-op path); 800-batch paired seeded training run had max relative loss diff8.4e-6(vs6.3e-6baseline run-to-run noise).(Note: ported cleanly onto current
masterand syntax-checked locally on macOS; the newly added pytest case intest_fused_kernels.pymirrors the GPU unit check above and has not yet been re-run viapyteston a CUDA box after porting.)