Repository navigation
[Perf][Compile] Add local compilation for cos/sin RoPE - #4985
Merged
Merged
Conversation
acisseJZhong
force-pushed
the
compile_rope
branch
2 times, most recently
from
October 1, 2026 01:08
10e25f5 to
9009cf1
Compare
acisseJZhong
force-pushed
the
compile_rope
branch
from
October 1, 2026 01:15
9009cf1 to
1eea86f
Compare
acisseJZhong
force-pushed
the
compile_rope
branch
from
October 1, 2026 01:45
1eea86f to
5cf05da
Compare
acisseJZhong
force-pushed
the
compile_rope
branch
2 times, most recently
from
October 1, 2026 03:31
3849a5c to
c126d60
Compare
acisseJZhong
marked this pull request as ready for review
October 1, 2026 03:34
acisseJZhong
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
October 1, 2026 03:34
acisseJZhong
force-pushed
the
compile_rope
branch
from
October 1, 2026 04:09
c126d60 to
61d25c2
Compare
acisseJZhong
requested review from
IvanKobzarev,
SherlockNoMad,
aditvenk,
felipemello1,
pzhan9 and
sanketpurandare
as code owners
October 1, 2026 06:24
acisseJZhong
force-pushed
the
compile_rope
branch
from
October 1, 2026 16:53
58b50fb to
fe0e894
Compare
acisseJZhong
force-pushed
the
compile_rope
branch
from
October 1, 2026 17:00
fe0e894 to
7054ca8
Compare
felipemello1
reviewed
Oct 1, 2026
Comment on lines
47
to
+51
| def qwen35_local_compile_config() -> LocalCompileConfig: | ||
| """Return the default local compile regions for Qwen3.5 models.""" | ||
| return LocalCompileConfig(regions=["gated_rmsnorm", "loss", "offset_rmsnorm"]) | ||
| return LocalCompileConfig( | ||
| regions=["gated_rmsnorm", "loss", "cos_sin_rope", "offset_rmsnorm"] | ||
| ) |
Contributor
There was a problem hiding this comment.
noob question: why do we need this custom fn? And why only for qwen 3.5?
Contributor
Author
There was a problem hiding this comment.
because offset_rmsnorm is sth only qwen3.5 uses, so the common import won't cover this.
acisseJZhong
force-pushed
the
compile_rope
branch
from
October 1, 2026 19:48
7054ca8 to
eea909c
Compare
acisseJZhong
force-pushed
the
compile_rope
branch
2 times, most recently
from
October 1, 2026 19:52
103848f to
e384b4f
Compare
|
Warning: Unknown label
Please add the new label to .github/pytorch-probot.yml |
acisseJZhong
force-pushed
the
compile_rope
branch
from
October 1, 2026 22:59
e384b4f to
aa5b6e2
Compare
acisseJZhong
force-pushed
the
compile_rope
branch
from
October 1, 2026 23:01
aa5b6e2 to
fd3947f
Compare
This was referenced Oct 1, 2026
Closed
acisseJZhong
added a commit
that referenced
this pull request
Oct 2, 2026
## Summary - Add function-scoped local compilation for the Kimi K3 SiTUGLU activation. - Enable the situglu local-compile target by default. - Cover dense execution and the grouped-expert call path that passes offsets. - Stack on #4985. ## Performance Steady-state BF16 operator latency on one H100 with Kimi K3 beta=4 and linear_beta=25. Compilation time is excluded. Results are the average of two independent run medians; each run used five measurements after warmup. Shapes use the released Kimi K3 hidden dimensions with representative TP8/EP8 layouts. Routed-expert rows assume balanced top-k=16 routing across EP8. | Path | Rank-local shape | Eager fwd | Local compile fwd | Speedup | Eager fwd+bwd | Local compile fwd+bwd | Speedup | | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | | Dense, 4K tokens, TP8 | [512, 4224] | 79.65 us | 13.07 us | 6.09x | 189.29 us | 76.17 us | 2.49x | | Dense, 32K tokens, TP8 | [4096, 4224] | 850.16 us | 54.15 us | 15.70x | 2.074 ms | 137.29 us | 15.11x | | Shared experts, 4K tokens, TP8 | [512, 768] | 43.63 us | 7.45 us | 5.85x | 188.14 us | 76.03 us | 2.47x | | Shared experts, 32K tokens, TP8 | [4096, 768] | 120.50 us | 16.40 us | 7.35x | 295.94 us | 77.56 us | 3.82x | | Routed experts, 4K tokens, EP8 | [8192, 3072] | 1.208 ms | 86.69 us | 13.93x | 2.943 ms | 205.78 us | 14.30x | | Routed experts, 32K tokens, EP8 | [65536, 3072] | 9.204 ms | 621.20 us | 14.82x | 22.555 ms | 1.561 ms | 14.45x | Local compile is faster for every tested shape. These isolated operator results do not claim the same end-to-end training speedup. The routed path still evaluates the full padded buffer because SiTUGLU does not consume offsets. ## Testing - pytest -q tests/unit_tests/cpu/test_compile_config.py tests/unit_tests/cpu/test_feed_forward.py tests/unit_tests/cpu/test_moe.py (32 passed, 9 subtests passed) - pytest -q tests/unit_tests/gpu/test_situglu.py (3 passed) - Verified compiled forward and backward emit Triton code. - Verified forward, gate gradient, and up gradient match the eager reference. - Verified compiled forward and both input gradients are bitwise batch-invariant.
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
CosSinRoPE.forwardas the defaultcos_sin_ropelocal compile region.MRoPEthrough its inheritedCosSinRoPE.forward.ComplexRoPEeager because Inductor does not efficiently lower complex operators.This PR is stacked on #4931.
Performance
One NVIDIA H100 with BF16 inputs. Forward+backward includes query and key gradients. Each result is the median of five trials with 20 warmup iterations and 100 timed iterations per trial. Compilation time is excluded.
Shape is
[T, Hq, Hkv, D], whereTis the rank-local token count after packing andHq/Hkvare rank-local heads after TP. A speedup above1.0xmeans local compile is faster.CosSinRoPE
The exact Helion cos/sin override applies to these models.
[4096, 8, 4, 128][40960, 32, 8, 128][163840, 40, 8, 128][4096, 16, 2, 128][81920, 64, 8, 128][4096, 32, 4, 64]Local compile is faster than eager for all tested shapes and faster than Helion for three of six. Helion remains 1.05x, 1.10x, and 1.09x faster for the Qwen3 8B, 14B, and 32B shapes, respectively.
MRoPE
MRoPEinherits the locally compiledCosSinRoPE.forwardand specializes cache construction for three-axis positions. The Helion override targets exactlyCosSinRoPE.Config, so it does not replaceMRoPE.Config.[T][2048, 8, 2, 64][T, 3][2048, 8, 2, 64][T][65536, 12, 2, 64][T, 3][65536, 12, 2, 64][T][262144, 16, 1, 64][T, 3][1048576, 6, 1, 64]Local compile is faster than eager for all tested MRoPE text and three-axis shapes.
Complex RoPE exclusion
DeepSeek V3 recipes use four packed 16K sequences per DP rank, so
T = 65536. The 16B model has 16 query heads; the 236B and 671B models have 128. All use one MLA RoPE key head andD = 64.[65536, 16, 1, 64][65536, 128, 1, 64]Inductor warns that complex-operator code generation is unsupported. Exploratory local compile is only 1.05-1.07x faster than eager, while Helion is 4.06-4.57x faster on the DeepSeek V3 shapes. Therefore this PR leaves
ComplexRoPEeager and retains the Helion override.These are isolated operator measurements, not end-to-end training results.
Correctness
Tests