Commit e85f52b
committed
sm12x: cap C128A metadata kernel loop at effective_topk (no shape changes)
Cudagraph-safe retry of suggestion #2 from PR vllm-project#41834 comment 4450901180.
Previous attempt (e34daef, reverted) also exposed
``c128a_*_effective_topk`` on the metadata and truncated the buffer
slice inside ``deepseek_v4_attention``; that truncation baked the
shape into the captured forward launch, breaking replay when
``effective_topk`` shifted between capture and replay.
This version only touches the metadata builder (which already runs
*outside* the captured forward), so per-call ``effective_topk``
variation is fine:
1. Pre-fill ``global_decode_buffer[:num_decode_tokens]`` and
``prefill_buffer[:num_prefill_tokens]`` with ``-1`` before launch.
2. Compute ``effective_topk_arg = cdiv(max num_compressed across
in-flight tokens, BLOCK_SIZE) * BLOCK_SIZE``, capped at
``max_compressed_tokens``.
3. Kernel inner loop uses ``effective_topk`` (was
``max_compressed_tokens``); store mask uses the same.
The buffer entries the kernel skips
(``[effective_topk, max_compressed_tokens)``) stay at ``-1`` from the
pre-fill, so downstream sparse MLA accumulate kernels (which still
iterate the full ``max_compressed_tokens`` width inside the cudagraph)
see only ``-1`` sentinels in the tail and short-circuit them via
``kv_index >= 0`` / ``candidate < valid_len`` checks. No tensor shape
changes inside the captured forward → cudagraph capture/replay
remains correct.
Savings here are limited to the metadata kernel itself; the accumulate
kernels' iteration count is unchanged (their loop bound is the captured
``num_candidates`` shape value, which we deliberately do not narrow).
Bench at long ``max_model_len`` will confirm whether this is enough to
recover a meaningful chunk of the ~27 % TPOT regression observed at
``max_model_len=131072`` vs ``8192``.
Signed-off-by: jasl <jasl9187@hotmail.com>1 parent 1796f5f commit e85f52b
1 file changed
Lines changed: 49 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1082 | 1082 | | |
1083 | 1083 | | |
1084 | 1084 | | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
1085 | 1120 | | |
1086 | 1121 | | |
1087 | 1122 | | |
| |||
1090 | 1125 | | |
1091 | 1126 | | |
1092 | 1127 | | |
1093 | | - | |
| 1128 | + | |
1094 | 1129 | | |
1095 | 1130 | | |
1096 | 1131 | | |
1097 | 1132 | | |
1098 | 1133 | | |
1099 | 1134 | | |
1100 | | - | |
| 1135 | + | |
1101 | 1136 | | |
1102 | 1137 | | |
1103 | 1138 | | |
| |||
1114 | 1149 | | |
1115 | 1150 | | |
1116 | 1151 | | |
1117 | | - | |
| 1152 | + | |
1118 | 1153 | | |
1119 | 1154 | | |
1120 | 1155 | | |
| |||
1123 | 1158 | | |
1124 | 1159 | | |
1125 | 1160 | | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
1126 | 1167 | | |
1127 | 1168 | | |
1128 | 1169 | | |
1129 | | - | |
| 1170 | + | |
1130 | 1171 | | |
1131 | 1172 | | |
1132 | 1173 | | |
1133 | 1174 | | |
1134 | 1175 | | |
1135 | 1176 | | |
1136 | 1177 | | |
1137 | | - | |
| 1178 | + | |
1138 | 1179 | | |
1139 | | - | |
| 1180 | + | |
1140 | 1181 | | |
1141 | 1182 | | |
1142 | 1183 | | |
| |||
1161 | 1202 | | |
1162 | 1203 | | |
1163 | 1204 | | |
1164 | | - | |
| 1205 | + | |
1165 | 1206 | | |
1166 | | - | |
| 1207 | + | |
1167 | 1208 | | |
1168 | 1209 | | |
1169 | 1210 | | |
| |||
0 commit comments