Skip to content

Commit 7da5a65

Browse files
committed
[None][perf] MegaMoE: run the SM107 gen-phase defaults on the decode scheduler
The re-synced Rubin gen-phase kernel accepts only ("decode", lead) schedules and refuses grouped / phase_interleave at construction, which the backend turns into a silent fallback to the generic kernel. Move the gen-phase table to decode tactics picked on VR200 at EP4 (DSv4-Pro and Kimi K3, balanced and power-law routing), drop the Kimi K3 512 entry that the generic table now matches, and log a rejected default tactic as a warning. The 384 bucket uses N128 with an FC1 lead of 91, 1.1-2.2% faster than N256 / lead 45 on this kernel. GLM 5.2's high-throughput target builds its own gen-phase kernel, which has no decode scheduler. Give the shared runner an overridable _default_tactic(); the GLM runner keeps the phase_interleave tactics the shared table used before (32-192 tokens/rank) and refuses a decode tactic. The custom op allocates the generic kernels' tmp buffer as the 128-byte-aligned tail of the cached local workspace and declares the output activation 32-byte aligned for the top-k reduce. Tests check that every gen-phase default is a decode tactic, builds the gen-phase kernel for DSv4-Pro and Kimi K3, and that the GLM runner keeps its phase_interleave tactics. Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
1 parent 97bb881 commit 7da5a65

3 files changed

Lines changed: 240 additions & 133 deletions

File tree

‎tensorrt_llm/_torch/modeling_v2/models/glm_moe_dsa/glm_5_2_nvfp4__sm_107__high_throughput/ops/moe/megamoe_runner.py‎

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
_LOCKED_KERNEL_KWARGS,
1212
_SF_PADDING_BLOCK,
1313
Sm100MegaMoENvfp4Runner,
14-
_default_megamoe_tactic_for_key,
1514
_launch_cluster_configuration,
1615
_unpack_tactic,
1716
validate_megamoe_tactic,
@@ -20,6 +19,60 @@
2019

2120
from ...kernels.moe.constants import GEN_TOKEN_BUCKETS
2221

22+
# This model's gen-phase kernel (kernels/moe) predates the decode scheduler: it runs any
23+
# non-grouped schedule as phase_interleave without checking the hint. Keep the phase_interleave
24+
# tactics the shared table used before it moved to decode.
25+
_GLM_GENPHASE_TACTICS: dict[int, Tuple] = {
26+
32: (
27+
[256, 128, 256],
28+
[4, 1, 1],
29+
None,
30+
("phase_interleave", 3),
31+
"atomic_counter",
32+
"epi_warps",
33+
True,
34+
1,
35+
1,
36+
(2, 4),
37+
),
38+
64: (
39+
[256, 128, 256],
40+
[4, 1, 1],
41+
None,
42+
("phase_interleave", 3),
43+
"atomic_counter",
44+
"epi_warps",
45+
True,
46+
1,
47+
1,
48+
(1, 4),
49+
),
50+
128: (
51+
[256, 256, 256],
52+
[4, 1, 1],
53+
None,
54+
("phase_interleave", 3),
55+
"atomic_counter",
56+
"epi_warps",
57+
True,
58+
1,
59+
1,
60+
(1, 4),
61+
),
62+
192: (
63+
[256, 256, 256],
64+
[4, 1, 1],
65+
None,
66+
("phase_interleave", 3),
67+
"atomic_counter",
68+
"epi_warps",
69+
True,
70+
1,
71+
1,
72+
(1, 4),
73+
),
74+
}
75+
2376

2477
def _construct_rubin_kernel(
2578
*, sm_version: int, common: dict, combine_format: str
@@ -114,8 +167,17 @@ def _build_unique_id(self):
114167
# The shape/tactic keeps the shared runner's positional key contract.
115168
return (*super()._build_unique_id(), "glm-rubin-high-throughput")
116169

170+
def _default_tactic(self, num_tokens: int) -> Tuple:
171+
tactic = super()._default_tactic(num_tokens)
172+
if _unpack_tactic(tactic)[3][0] == "decode":
173+
bucket = shared._sm107_tactic_bucket(self.max_tokens_per_rank)
174+
tactic = _unpack_tactic(_GLM_GENPHASE_TACTICS[bucket])
175+
return tactic
176+
117177
def _build_kernel_once(self, tactic: Tuple):
118178
validate_megamoe_tactic(tactic, sm_version=self.sm_version)
179+
if _unpack_tactic(tactic)[3][0] == "decode":
180+
raise ValueError("The GLM gen-phase kernel has no decode scheduler.")
119181
cached = self.__class__.kernel_cache.get(self._tactic_cache_key(tactic))
120182
if cached is not None:
121183
return cached[1]
@@ -214,17 +276,13 @@ def query_rubin_kernel_properties(**kwargs):
214276
tactic = kwargs.pop("tactic", None)
215277
runner = RubinMegaMoERunner(local_rank=0, output_dtype=torch.bfloat16, **kwargs)
216278
if tactic is None:
217-
tactic = _default_megamoe_tactic_for_key(
218-
runner.unique_id(), num_tokens=runner.max_tokens_per_rank
219-
)
279+
tactic = runner._default_tactic(runner.max_tokens_per_rank)
220280
kernel, _ = runner._resolve_kernel_descriptor(tactic, allow_fallback=True)
221281
return int(kernel.get_workspace_sizes()[1]), True
222282

223283

224284
def runner_kernel(runner):
225-
tactic = _default_megamoe_tactic_for_key(
226-
runner.unique_id(), num_tokens=runner.max_tokens_per_rank
227-
)
285+
tactic = runner._default_tactic(runner.max_tokens_per_rank)
228286
return runner._resolve_kernel_descriptor(tactic, allow_fallback=True)[0]
229287

230288

0 commit comments

Comments
 (0)