sparse seqlens 从 topk 派生:SGLANG_MINICPM_DERIVED_SPARSE_SEQLENS 默认 ON
direct sparse page table:SGLANG_MINICPM_DIRECT_SPARSE_PAGE_TABLE 默认 ON
stage1 actual maxlen + direct pool + skip extra zero:SGLANG_MINICPM_STAGE1_ACTUAL_MAXLEN / SGLANG_MINICPM_STAGE1_DIRECT_POOL / SGLANG_MINICPM_POOL_EMPTY_OUTPUT 默认 ON;只缩 stage1 max_seqlen_k,不缩max_pooling_1d_varlen.max_context_len
Now I have the full diff. Let me check for residual references to deleted symbols across the repo.
Assistant
Good — all residual references are in docs/ (historical) and eval/start_dflash.sh / start_ddtree.sh* (探索性, not production per CLAUDE.md). Production eval/start_eagle.sh doesn't set any of these.
Let me verify SGLANG_TREE_USE_FLASHINFER_WRAPPER deletion impact and confirm no other prod paths touch deleted code.
Now check what triggers verify_tree_mask_wrapper. EAGLE-3 uses chain verify; the tree wrapper is only used for DDTree (tree-shape) spec.
Assistant
Now let me check all callers and references in the demo-sala/ tree.
Assistant
Confirmed — verify_tree_mask_wrapper only set for DDTree (line 803-809). EAGLE-3 chain verify uses verify_prefill_wrapper (causal=True). So tree probe path change doesn't affect production.
Assistant
Verified: tree_wrapper only set when dflash_full_custom_mask=True (DDTree only). EAGLE-3 chain verify path completely unaffected.
Let me also confirm that start_eagle.sh indeed doesn't set the deleted env vars and that production prefill code path is intact.
Good — flashinfer_block_page_size / flashinfer_block_page_offset fully removed from the dataclass, and the call site in minicpm_backend.py no longer passes them. Now check there's no other consumer that reads them.
删 5 个 flag 定义:_MINICPM_FUSED_GLA_QK_NORM_ROPE、_MINICPM_FUSED_GLA_QK_NORM_ROPE_OOP、_MINICPM_GLA_FUSED_SIGMOID_MUL、_MINICPM_GLA_FUSED_RMSNORM_SIGMOID_MUL、_MINICPM_FUSED_MLP_ACT_QUANT
删 import from sgl_kernel import fused_qk_norm_rope as _fused_qk_norm_rope
All env flag references are in non-production scripts (DFlash/DDTree exploratory, prepare_env reports, bench scripts). Production eval/start_eagle.sh and demo-sala/prepare_env.sh are clean.
The dynamic conditions equivalence: original use_block_table_v3 = _MINICPM_PREFILL_BLOCK_TABLE_V3 and min(seq_lens) >= num_sparse_topk_tokens. With env default=1 and not overridden in start_eagle.sh, _MINICPM_PREFILL_BLOCK_TABLE_V3=True, so the new code is equivalent. Same for _MINICPM_TOPK_TO_FI_INDICES=1 default. Confirmed.
This is critical. The 471e20b fix originally used wrapper.begin_forward(...) for cross-forward refresh. Now let me look at the intermediate commits to understand when buffer refresh replaced begin_forward.
_MINICPM_CROSS_FORWARD_BUFFER_REFRESH default was "1" (ON) as introduced in 4541b54. So the cleanup correctly preserves the production behavior (always refresh buffers, not call begin_forward).
Now let me verify the conv_hit removal didn't break anything. Let me check the 43c6cc0 commit (disable unsafe flashinfer conversion cache).
So _MINICPM_UNSAFE_FI_CONVERT_CACHE default was "0" (OFF) — confirmed in the cleanup diff line 79 ("0"). The conv_hit cross-layer cache was unsafe and the prod default disabled it. The cleanup removes the dead path. Now I need to verify the else body that was kept doesn't reference cur_layer_id/page_table_ptr (which were defined only in the deleted conv_hit cache setup section).
Looking at the cleanup diff (lines 325-336): cur_layer_id and page_table_ptr were defined BEFORE conv_hit check, so they get deleted in the cleanup. The retained else body (lines 396+) doesn't use either—it only uses using_direct_topk_indices, bs, max_sparse_tokens, params. Good.
But there's also the line self._conv_cache_last_layer_id = cur_layer_id at the bottom. Let me check that's fully removed.
Now let me also verify cur_layer_id is still defined in decode path (it gets used in the reuse_plan logic).
Assistant
Good. cur_layer_id is re-declared in the decode plan section (line 624). The deleted cur_layer_id (used only for conv_hit cross-layer cache) was a separate declaration in the convert section. The decode-section cur_layer_id is still intact.
Let me verify the plan cache reuse logic is intact and still properly distinguishes within-forward vs cross-forward.
Pool/topk-sorted:_max_pooling_1d_varlen_empty 和 topk(..., sorted=False) 都是原 default ON。topk 之后立即 .indices.sort(-1).values(utils.py:790, 806),所以 stage2 接收的 indices 顺序与原 sorted=True 完全一致——无 stage2 indices 顺序问题。
ALL_SPARSE_PREFILL_METADATA:动态条件 len(sparse_bs_list)==bs and all(seq_lens>=dense_len) 保留;env flag default ON 删除等价。--dense-as-sparse 把 dense_len=0,条件第二项永真。
最后检查范围内 minicpm.py 其它 getenv("SGLANG_MINICPM..." 现存读取,确认没有遗漏的 flag 被改:
Assistant
Plan cache reuse logic is fully intact. The _cross_forward flag is still set to True when shape_only_plan_cache triggers reuse, and the buffer refresh (lines 665-667) is preserved unconditionally. Now let me sanity-check the AttentionParams field deletion — make sure nobody writes to them.
如果原本是函数局部变量、每次调用都 False 初始化(env OFF 时),那"修了 stale-state" 是误判 — 实际只是删除了死分支
验证 is_prefilling 路径外(decode 路径 / is_prefilling and split_stage1 路径)use_stage1_direct_pool 是否仍然被消费:函数末尾 if use_stage1_direct_pool: 是单一引用还是多处?
做法:
git show e2e3bd6 -- demo-sala/sglang/python/sglang/srt/layers/attention/minicpm_sparse_utils.py | sed -n '/use_stage1_direct_pool/,/^@@/p' | head -150 看完整 diff context
git show e2e3bd6~1:demo-sala/sglang/python/sglang/srt/layers/attention/minicpm_sparse_utils.py | sed -n '650,820p' 看改前完整代码
git show e2e3bd6:demo-sala/sglang/python/sglang/srt/layers/attention/minicpm_sparse_utils.py | sed -n '650,820p' 看改后完整代码
Survey existing CUTLASS sm120 epilogue visitor templates in the flashinfer-bundled CUTLASS to understand how to write a new visitor that does pair-reduction (acc[2i], acc[2i+1] → silu(acc[2i]) * acc[2i+1]) inside a NVFP4 GEMM epilogue.
Also look at the parent sm90 versions: sm90_visitor_compute_tma_warpspecialized.hpp, sm90_visitor_load_tma_warpspecialized.hpp
And the production raw kernel in /user_4813494d/openbmb/outputs/prefill_experiments/fp4_blockscale_epilogue_sm120/fp4_blockscale_epilogue_sm120.cu which uses LinCombBlockScaleFactor<16, ElementD, ElementCompute, ElementBlockScaleFactor, RowMajor, void, float>
Context for the task:
The production GEMM (gate_up_proj) computes Y = X @ W^T producing (M, N) bf16 where N=2*intermediate=32768
We want a fused kernel that emits FP4-quantized (M, N/2) = (M, 16384) using SwiGLU pair-reduction: out[i, j] = silu(Y[i, 2j]) * Y[i, 2j+1]
The output is FP4 with per-block ue4m3 scale factors (block size 16)
Hardware is sm_120a (Blackwell client)
This is the "S2" milestone — start with identity pair-mul (silu omitted, just g * u)
What I need from you (RESEARCH ONLY, NO CODE CHANGES):
Which existing visitor template is closest to what we need? (e.g., Sm90Compute, Sm90EVT, Sm90AuxStore, Sm90VisitorImpl chain)
What is the signature of the visit() method in a typical compute visitor on sm90/sm120? (Array<T, N>? per-thread fragments?)
Does the existing LinCombBlockScaleFactor (and Sm120LinComb*) compose like Sm90EVT<Sm90Compute<...>, Sm90LinearCombination> or differently?
Are there examples in the tree of a visitor that REDUCES the fragment size (output FRAG_SIZE/2 from input FRAG_SIZE)? Search for keywords like "split", "pair", "reduce", "fold" in those files.
What is the actual fragment layout on sm120 NVFP4 — is acc[i] for i in 0..FRAG_SIZE-1 row-major across (M, N) with N-stride-1? (Per the docs we assume yes but verify.)
The SFD output ScaleFactor generator: which template does it (Sm1xxBlockScaledOutputConfig? Sm120BlockScaleFactorRowStore?), and how is the per-block N=16 width relayed?
Report findings in under 600 words. Cite file:line references. Identify whether S2 is straightforward (extend a near-match visitor) or requires building a new SFD-aware pair-reduce visitor from scratch.
Assistant
I'll survey the CUTLASS sm120/sm90 epilogue visitor templates to answer these research questions.
Assistant
This is very informative. Let me read the sm90 compute visitor to understand the standard visitor pattern.
Assistant
Now let me look at the production raw kernel and search for "pair/reduce/split/silu/swiglu" patterns.
Assistant
Now search for related "split / pair / reduce / fold / silu / swiglu" examples across cutlass:
Assistant
Now let me check the sm90 store visitor / aux store for output writing and look at the visitor signatures for store callbacks at the top-level:
Assistant
Now let me look at the operations.hpp to understand the LinCombBlockScaleFactor operation declaration:
Assistant
Now let me check the Sm1xxBlockScaledOutputConfig to understand SFD scaling factor block layout:
Assistant
I have enough information. Let me also briefly confirm visitor compose pattern with Sm90EVT and the Sm90VisitorImpl chain order semantics:
Assistant
I have enough to write the report. Let me finalize findings.
Sm120LinearCombRowBlockScaleFactor at sm120_callbacks_tma_warpspecialized.hpp:107-110 is the structural prototype:
code
Sm90EVT< Sm120BlockScaleFactorRowStore<...>, // outer node (does SF gen + apply + store SFD)
Sm90LinearCombination<...> > // child (produces fp32 frg = alpha*acc + beta*C)
The outer node is what we must replace/extend. Its visit() is the trivial pass-through at sm120_visitor_store_tma_warpspecialized.hpp:209-217 — it just returns frg_input (the fp32 fragment from the child). The actual SFD math lives in reduce() (sm120_visitor_store_tma_warpspecialized.hpp:219-450) which runs once per epilogue subtile after all visit() calls accumulate visit_results.
2. visit() signature in compute visitors
Standard sm90 compute visitor (sm90_visitor_compute_tma_warpspecialized.hpp:171-203):
code
Array<ElementOutput, FragmentSize>
visit(Array<ElementAccumulator, FragmentSize> const& frg_acc,
int epi_v, int epi_m, int epi_n,
Array<ElementInputs, FragmentSize> const&... frg_inputs);
FragmentSize is a small per-thread chunk (the sm120 SFD code at sm120_visitor_store_tma_warpspecialized.hpp:287-290 asserts FragmentSize == ColsPerThreadAccFrag(2) * RowsPerThreadAccFrag(2) == 4, the standard 16x8 MMA per-thread layout).
3. Composition pattern
LinCombBlockScaleFactor is just a tagged FusionOperation marker (operations.hpp:515-521); the actual realization is the Sm90EVT<outer, child> tree above. FusionCallbacks partial specialization (sm120_callbacks_tma_warpspecialized.hpp:128-183) is what maps the op tag → EVT tree. We would compose identically: Sm90EVT<NewSwiGLUBlockScaleStore, Sm90LinearCombination<...>>, plus our own FusionOperation tag and a matching specialization. The orchestration () calls child first, then — so a custom outer node fits naturally.
User
Design the CUTLASS sm120 NVFP4 GEMM-with-SwiGLU-pair-fold epilogue. RESEARCH + DESIGN ONLY (no production code changes); but you may write and run probe code under /user_4813494d/openbmb/outputs/prefill_experiments/gate_up_swiglu_fp4_sm120/ to validate hypotheses.
Context
I have a working scaffold at /user_4813494d/openbmb/outputs/prefill_experiments/gate_up_swiglu_fp4_sm120/gate_up_swiglu_fp4_sm120.cu which is essentially a renamed copy of /user_4813494d/openbmb/outputs/prefill_experiments/fp4_blockscale_epilogue_sm120/fp4_blockscale_epilogue_sm120.cu — uses LinCombBlockScaleFactor fusion, produces FP4 output for (M, N, K) GEMM.
I need to extend it so it computes:
Y_acc = A @ B^T where A is (M, K) FP4, B is (N=2*intermediate, K) FP4, weight B is pre-permuted so adjacent rows are (g, u) pairs:
B[2k] = gate row k
B[2k+1] = up row k
so Y_acc[i, 2k] = (A @ gate_row_k)
Y_acc[i, 2k+1] = (A @ up_row_k)
D[i, k] = silu(Y_acc[i, 2k]) * Y_acc[i, 2k+1] (or just g*u for S2 stage)
D is FP4-quantized: shape (M, N/2//2 bytes), with block-scaled (SFVecSize=16) UE4M3 scale factors in a Sm1xxBlockScaledOutputConfig swizzled SFD buffer sized for (M, N/2, K, 1).
Per-batch shape: M=8192 (full chunk) or 8087 (tail), N=32768, K=4096. The cute_dsl sm_100 reference is /opt/SGLang-MiniCPM-SALA/sglang_minicpm_sala_env/lib/python3.10/site-packages/flashinfer/fused_moe/cute_dsl/blackwell/blockscaled_contiguous_gather_grouped_gemm_swiglu_fusion.py — read its register-domain SwiGLU math.
Key constraint discovered
The existing sm120 visitor Sm120BlockScaleFactorRowStore (at sm120_visitor_store_tma_warpspecialized.hpp:60-510):
visit() is passthrough; the real work happens in reduce() at lines 219-450
visit_results tensor shape is determined by problem_shape (full N) — cannot be shrunk by visitor alone
Per-thread fragment FragmentSize=4 = ColsPerThreadAccFrag(2) × RowsPerThreadAccFrag(2)
acc[0], acc[1] are adjacent N columns of the same row; acc[2], acc[3] are adjacent N columns of next row
After pre-permuting weight rows to interleave (g, u), the per-thread fragment naturally has (g_i, u_i, g_{i+1}, u_{i+1}) at positions [0,1,2,3] — pair-fold is purely thread-local, no shuffle needed
SFVecSize=16 means each output SF covers 16 N positions; with pair-fold, each output SF covers 16 OUTPUT positions = 32 INPUT N positions
For output domain we'd need 2× as many fragments per SF
The hard question: how to halve the output D size
GEMM is launched with problem.N = ?, weight B has shape (2*intermediate, K). Output D should be sized (M, N/2). Three candidate strategies — please evaluate each, ideally with a small CUTLASS probe:
Assistant
I'll research the cute_dsl sm_100 reference and the existing sm120 visitor to design the pair-fold epilogue.
Assistant
Now let me look at the surrounding context to understand how cute_dsl halves the N dimension at the GEMM level (problem shape / weight layout):
Assistant
Critical finding: cute_dsl runs MMA at FULL N (mma_tiler[1], weight is [NxK] interleaved), and the C tiler is N/2. The MMA produces full-N accumulator in tmem; the epilogue then iterates subtiles in pairs (up, gate) at granularity 64, reduces each pair to one output tile of size 64 N, halving the C-side store. The N halving lives entirely in the C smem layout / epilogue subtile iteration, not in the GEMM problem shape.
Assistant
Confirmed: cute_dsl passes B as (n, k, l) with FULL n, MMA tiler.N = full mma_inst_shape_mn[1], C tensor (m, interm_size=n//2, 1) with C-side TMA / smem layout built from mma_tiler_c[1] = mma_inst_shape_mn[1] // 2. The interleaving granularity in cute_dsl is 64 (one full epi_tile[1]), not 2.
Now read the sm120 visitor reduce() to find exact lines:
Assistant
Now I have the full picture of the visitor reduce(). Let me find where visit_results is written to GMEM (the actual D store):
Assistant
Now I have the complete picture. Let me look at the outer epi_n loop structure and tCgD partitioning:
Assistant
Now I have everything. Let me check tile_atom_to_shape_SFD to understand what shape we register the SFD for, and look at the FusionCallbacks builder to understand the existing visitor wiring:
Assistant
Now I understand the EVT structure: Sm90EVT<RowStore, LinearCombination> — RowStore.reduce() writes the SFD; the parent EVT pipes visit_results = tRS_rCompute_frg (which now lives in the visitor's local registers) into the smem store path (sm90 line 884-891). The smem store is the actual D path.
Let me also check the tile_atom_to_shape_SFD and the bSG_gD/gD construction to see where N appears in the GMEM tensor:
Assistant
Now I see exactly what the GMEM/store path uses. The N dimension of D is wired through make_shape(M, N, L) from problem_shape (line 571), the EpilogueTile, and CtaTileMNK. The gD_epi shape is (EPI_TILE_M, EPI_TILE_N, EPI_M, EPI_N) — these dimensions come from problem.N / CtaTileMNK.N and CtaTileMNK.N / EpilogueTile.N.
Let me run a quick probe to confirm the FragmentSize=4 layout assumption and visualize what tRS_rAcc_frg and visit_results look like in the small problem:
Assistant
Now let me look at the FragmentSize that's actually being used and the tRS_rD_layout shape — this is the critical info for the fold:
Assistant
FragmentSize=4 confirmed. Now I have all the info I need. Let me double-check one thing — what does tRS_rCompute_frg look like? It's recast<Array<RegisterElementD, 4>>(tRS_rCompute) where tRS_rCompute has layout tRS_rD_layout = take<0,3>(thread_r2s.partition_S(sD_epi)) i.e. (R2S, R2S_M, R2S_N). So tRS_rCompute_frg shape is (R2S/4, R2S_M, R2S_N) with Array<f32,4> elements.
Looking back at the visitor's reduce(): visit_results(0, row, acc_frag_start_for_sf + i) — index 0 is the V-mode (R2S inner), row indexes R2S_M, third index iterates over R2S_N. The 4 elements of Array (acc_frag_row=0,1; col=0,1) are the same MMA 16x8 quad fragment.
Crucially: tRS_rD_layout is constructed from thread_r2s.partition_S(sD_epi), where sD_epi has EpilogueTile shape (EPI_TILE_M, EPI_TILE_N). So the fragment's per-thread N footprint = EPI_TILE_N / num_threads_per_n. The outer epi_n loop iterates CTA_N / EPI_TILE_N times, and each iteration's visit_results covers EPI_TILE_N cols.
Now I'm ready to do the probe and write the design. Let me write a small probe that confirms tRS_rCompute_frg shape numerically:
Assistant
Good. SFD is laid out from (M, N, L) directly. So if we tell the kernel problem.N = N_full to do MMA, but want SFD sized for N_half, we have to either (a) pass a "stride trick" or (b) modify the kernel template instantiation to use a SeparateD output size, which CUTLASS doesn't natively support.
I have enough to give the design. Let me write a small probe to verify Strategy A halve-store works mechanically — but actually given time and the complexity of CUTLASS template instantiation, the report itself can be authored directly. The probe will be more useful as part of the actual S2 implementation, not the analysis phase.
Let me capture the key references for the report:
Assistant
LinCombEltAct exists in CUTLASS sm120 for monolithic SiLU, but it does element-wise activation, not pair-fold. Now I have everything for the report.
B is passed at full N: b = cute.make_tensor(b_ptr, layout=...(n, k, l)...) (line 3528–3529). MMA runs at full N. mma_tiler[1] = mma_inst_shape_mn[1] (line 578).
C is half N: interm_size = n // 2 (line 3523); c = ...(m, interm_size, 1)... (line 3541–3543). c_sf similarly halved (line 3544–3550).
Halving is in a separate C tilermma_tiler_c (lines 594–598): mma_tiler_c[1] = mma_inst_shape_mn[1] // 2. Likewise cta_tile_shape_mnk_c[1] = cta_tile_shape_mnk[1] // 2 (line 620).
Inside the epilogue (line 2562–2582): subtiles are iterated in pairs of 64 columns: subtile_idx in range(0, subtile_cnt, 2); per iteration loads tmem subtile 2*i as "up" and 2*i+1 as "gate", computes SwiGLU in register, stores one output subtile of width 64 to a C smem buffer sized for mma_tiler_c[1]. Output SF tensor is indexed at the halved coord epi_tile_cnt[1] + real_subtile_idx (line 2679).
Constraint: pair-fold granularity = epi_tile[1] = 64; valid mma_tiler_n in {128, 256} (line 3343); even epi_tile count required (line 3341).
Implication for sm120: cute_dsl uses the two-tiler approach (full-N MMA tiler vs. half-N C/D tiler) with pair-granularity = epi_tile_n (64), not granularity 2. sm120 CUTLASS C++ does not expose a separate MmaTilerC parameter — the sm90 epilogue derives gD_epi directly from problem_shape.N and CtaTileMNK. So we cannot literally copy the cute_dsl strategy without forking the collective epilogue.
2. Sm120BlockScaleFactorRowStore reduce() lines that change
The reduce body iterates SFs over tC_rSFD_flt (line 320), reads pairs of accumulator slots , (lines 338–339), and writes them back at the same positions after scaling (lines 421–422).
Key finding: determine_attention_backend returns "fa3" only when is_sm90a_supported (major==9). On sm120 (major==12) it falls to "fa2". Now check is_fa3_backend_supported and the gen_batch_prefill_module dispatch.
Assistant
Important finding: fa3 path includes <flashinfer/attention/hopper/variants.cuh>. Let me check gen_customize_batch_prefill_module to see compile flags.
Assistant
Key finding: fa3 backend uses sm90a_nvcc_flags (compute_90a only). That means JIT will compile sm_90a SASS that does NOT run on sm_120 hardware. Let me verify how fa3 dispatch happens when backend="fa3" is explicitly set.
Assistant
Confirmed: fa3 path uses sm90a_nvcc_flags = ["-gencode=arch=compute_90a,code=sm_90a"] (from core.py:127). Now check the FA3 source file (batch_prefill_sm90.cu) to confirm it uses Hopper-only instructions (WGMMA / TMA).
Assistant
Interesting — there's a blackwell subdirectory. Let me check it.
Assistant
Key finding: hopper code uses cute::SM90_TMA_LOAD, SM90_TMA_STORE, GMMA::* (WGMMA). All Hopper-only PTX. Now read the sm120 trtllm-gen module dispatch.
Assistant
fmha_v2_prefill_deepseek is hardcoded for head_dim=192/128 (DeepSeek-R1 MLA). Not usable for our 128/128 GQA. Let me check trtllm_fmha_v2_prefill and what gen_fmha_v2_module and get_trtllm_gen_prefill_module look like (sm support).
Assistant
Confirmed: gen_trtllm_fmha_v2_sm120_module is DeepSeek-R1-specific (only 3 kernels: 192x128 BF16 / FP8 e4m3, all for MLA). Not usable for our 128/128 GQA standard attention.
Now check gen_trtllm_gen_fmha_module (cubin-loaded trtllm-gen).
Assistant
gen_trtllm_gen_fmha_module uses prebuilt cubins (downloaded artifacts). Now check if those cubins include sm120 builds. Also let me check the actual sparse stage2 path in our SGLang fork to confirm how backend flows.
Assistant
Confirmed our SGLang fork creates the wrapper with backend="fa2" at line 366. Now check whether cute-dsl backend supports paged KV for sm120 — already saw that prefill.py:1554-1559 explicitly rejects cute-dsl for paged KV. Let me also check cutlass backend on sm120.
Assistant
Important note: cutlass FMHA (line 159) explicitly rejects sm120: "SM12x (RTX 5090/DGX Spark) lacks tcgen05 MMA required by this kernel". Now check what BatchPrefillWithPagedKVCacheWrapper does when backend is explicitly set to "fa3" or other on sm120. Look at run-time enforcement around line 1976-2055.
Assistant
Critical observation: trtllm-gen requires causal=True for paged KV (line 2005-2008). Our sparse stage2 uses mask_mode=0 (non-causal, sparse blocks). So trtllm-gen is out for our sparse stage2 path.
Now let me check the cudnn backend path to see if it has sm120 support, and look more broadly at sparse_attention support.
Assistant
Sparse wrappers only support fa2/fa3 (no trtllm/cudnn). Now let me search FlashInfer github for any sm120 fa3 work.
Assistant
Excellent — direct hit. FlashInfer issue #2555 is exactly our question. Let me fetch it.
Assistant
Strong evidence. Key insight from the gist: SM120 lacks TMEM, lacks tcgen05, lacks 2CTA clusters. But FA3 specifically uses WGMMA + TMA + warp-specialization (SM90-only Hopper instructions), not tcgen05 (which is SM100-only). Let me confirm whether SM120 has WGMMA. This is the key question: FA3 needs SM90's WGMMA, not FA4's tcgen05.
Assistant
Confirmed: wgmma is not supported on sm_120. ptxas explicitly rejects wgmma.fence for .target sm_120. This is the smoking gun: FlashInfer's fa3 backend hardcodes Hopper code (sm90's WGMMA + TMA load/store), and even if you could trick the Python gate to dispatch, ptxas will fail at JIT compile time because the kernel source uses cute::SM90_TMA_LOAD, SM90_TMA_STORE, and GMMA::* (WGMMA via cute).
Let me also check the flash-attn PyPI / Tri Dao's repo current state.
Assistant
Now check the SGLang discussion #10564 and any actual sm120 fa3 fork.
Assistant
Now I have a complete picture. Let me also verify by quickly checking our actual FlashInfer's fa3 source code (batch_prefill_sm90.cu) to confirm it really uses WGMMA/TMA — for the final cite.
Assistant
Comment at line 258 in our own fork already says "is not supported in FA2/FA3 backends". Let me check that context too.
Assistant
That's just a comment about FP8 output. Sufficient evidence collected. Now let me compose the report.
FA3 backend 在 sm120 上的非破坏性启用调研
1. FA3 backend 在 sm120 的硬件支持
关键代码路径:
flashinfer/utils.py:543-545is_sm90a_supported: major == 9 and cuda >= 12.3 — 只接受 Hopper
flashinfer/utils.py:500-509determine_attention_backend: return "fa3" if is_sm90a_supported(...) else "fa2" — sm120 (major=12) 在 auto 模式下永不走 fa3
flashinfer/utils.py:563-565is_sm120a_supported: major == 12 and minor == 0 and cuda >= 12.8 — sm120 有独立 gate,但 fa3 路径不查它
Now let me search FlashInfer issue #2555 and any XQA-related sm120 discussion.
Assistant
Excellent. Got crucial confirmation. Let me also look at one more piece — does XQA's q.shape allow our shape, and is the SPEC_DEC path (q_seq_len>1) decode-style with full attention over all pages?
Assistant
Now let me check the XQA grid dim, which tells us per-batch granularity. Already saw: dim3 dimGrid{nbSubSeqPerSeq, nbKHeads (* nbTokenBlocksPerGrp), batchSize}. This means batch_size = number of sequences, and seqLen[i] gives per-seq length. Pages are arranged as [batchSize][maxNbPagesPerSeq] contiguous list.
For our sparse stage2 with max_seqlen_q=1 and bs = chunk_q_len * head_group_num = 32768 * 16 = 524288 rows per layer per chunk (huge!), XQA would treat each row as one "sequence" with its own page table of top-K * 64 / page_size pages. Let me check the maxBatchSize:
/opt/SGLang-MiniCPM-SALA/sglang_minicpm_sala_env/lib/python3.10/site-packages/flashinfer/xqa.py:178-260(API doc 明示 "Apply attention with paged KV cache using XQA kernel",q shape 为 [batch_size, beam_width, num_q_heads, head_dim] 或 spec dec 时 [batch_size, beam_width, q_seq_len, num_q_heads, head_dim])
flashinfer/xqa.py:316-317: if get_compute_capability ... not in [9, 10, 12]: raise RuntimeError("XQA is only supported on SM90, SM100, SM120/SM121 GPUs")
No exact "FragmentSize/2 output" precedent. What does exist:
Sm90TopKSoftmaxColReduction (sm90_visitor_topk_softmax.hpp:325+) reduces across the N tile in reduce() (not across pairs inside a fragment), and re-visits to mask outputs. It demonstrates the visit + reduce + re-visit pattern but reduces to a scalar per row, not pairs.
Sm120BlockScaleFactorRowStore::reduce() (sm120_visitor_store_tma_warpspecialized.hpp:319-424) already iterates visit_results(0, row, acc_frag_start_for_sf + i) and mutates the fragment in place (lines 421-422). This is the prototype for in-place pair fold.
So S2 requires writing a new node — but the geometry is favorable: the standard MMA thread frag has ColsPerThreadAccFrag = 2 (line 287). Two N-contiguous columns are already owned by the same thread in the same frg_acc[acc_frag_row] / frg_acc[acc_frag_row+1] slots. Pair reduction is purely thread-local, no shuffle required.
5. Fragment layout on sm120 NVFP4
Confirmed at sm120_visitor_store_tma_warpspecialized.hpp:286-290 and the ASCII diagram lines 222-272. Per-thread FragmentSize=4 fragment is (Col0_Row0, Col1_Row0, Col0_Row1, Col1_Row1) with N-stride-1 for cols, M-stride for rows — so frg_acc[0] and frg_acc[1] are adjacent N elements of the same row (and similarly [2], [3]). Pair-mul frg[0]*frg[1] and frg[2]*frg[3] is the SwiGLU pair-reduce directly.
6. SFD output config
Sm1xxBlockScaledOutputConfig<SFVecSize> at cutlass/detail/sm100_blockscaled_layout.hpp:191-229. The Vec width (16) flows in as the template arg. tile_atom_to_shape_SFD(M, N, K, L) builds the SFD tensor layout — used both in the raw kernel (fp4_blockscale_epilogue_sm120.cu:172-175) and inside Sm120BlockScaleFactorRowStore::get_consumer_store_callbacks (sm120_visitor_store_tma_warpspecialized.hpp:462,474). The visitor itself takes SFVecSize template parameter and asserts N % SFVecSize == 0 (line 110).
Assessment: S2 difficulty
Medium — not from scratch, but a real new visitor. The straightforward path:
CloneSm120BlockScaleFactorRowStore into Sm120SwiGLUBlockScaleFactorRowStore.
Override visit() to consume frg_input (size 4) and produce a size-2 array {frg[0]*frg[1], frg[2]*frg[3]} (S2 identity-pair-mul; later replace with silu(frg[0])*frg[1]). The output FragmentSize template needs to be parameterizable or the caller's FragmentSize=4 retained with visit_results reinterpreted as half-width. Simplest path: keep FragmentSize=4 but treat positions [0,2] as "valid output" and [1,3] as zero, then have the store ignore half. Cleaner: have the SF amax/store path also be width-halved (N/2 problem geometry passed to outer template).
The reduce() body (lines 320-424) keeps working as is once you halve the effective N dimension and AccFragsPerSF accounts for the post-fold count.
Add a new FusionOperation tag (mirror LinCombBlockScaleFactor) and a FusionCallbacks partial specialization to bind it to the new EVT.
Caller side: GEMM is launched with logical N = 32768 (full gate+up), but SFD/D tensors are sized for N/2 = 16384. This means the problem_shape vs. dD/SFD layout mismatch needs a deliberate stride/layout choice (likely launch with problem_shape.N = 32768 and rely on the visitor halving inside the epilogue, OR launch with N=16384 but pull a stride-2 view inside the visitor for frg_acc). The first option is cleaner because the MMA still produces 32768 N accs which we fold in registers.
The hardest single hazard: ensuring SFVecSize=16 after pair-folding still aligns to the underlying AccFragsPerSF (line 301) — folding 32 N cols → 16 N cols means AccFragsPerSF and the WarpsPerSF = SFVecSize/16 (line 295) bookkeeping need to be re-derived for the folded domain, not the raw acc domain.
Key file references
/opt/SGLang-MiniCPM-SALA/sglang_minicpm_sala_env/lib/python3.10/site-packages/flashinfer/data/cutlass/include/cutlass/epilogue/fusion/sm120_visitor_store_tma_warpspecialized.hpp:60-510 — Sm120BlockScaleFactorRowStore (the clone target)
/opt/SGLang-MiniCPM-SALA/sglang_minicpm_sala_env/lib/python3.10/site-packages/flashinfer/data/cutlass/include/cutlass/epilogue/fusion/sm120_callbacks_tma_warpspecialized.hpp:88-183 — EVT composition and FusionCallbacks specialization (template)
/opt/SGLang-MiniCPM-SALA/sglang_minicpm_sala_env/lib/python3.10/site-packages/flashinfer/data/cutlass/include/cutlass/epilogue/fusion/sm90_visitor_tma_warpspecialized.hpp:572-622 — Sm90TreeVisitor (calls child then node)
/opt/SGLang-MiniCPM-SALA/sglang_minicpm_sala_env/lib/python3.10/site-packages/flashinfer/data/cutlass/include/cutlass/epilogue/fusion/operations.hpp:505-521 — LinCombBlockScaleFactor tag (template for new SwiGLU tag)
/opt/SGLang-MiniCPM-SALA/sglang_minicpm_sala_env/lib/python3.10/site-packages/flashinfer/data/cutlass/include/cutlass/detail/sm100_blockscaled_layout.hpp:191-229 — Sm1xxBlockScaledOutputConfig for SFD layout
/user_4813494d/openbmb/outputs/prefill_experiments/fp4_blockscale_epilogue_sm120/fp4_blockscale_epilogue_sm120.cu:43-52 — current GEMM wiring; the FusionOperation typedef is the swap point for the new tag
Strategy A: problem.N = N_full (= 32768). MMA produces full-N fragments. Visitor pair-folds in reduce(). After reduce(), output fragments still claim full-N footprint; store callback must compress to N/2. THIS REQUIRES MODIFYING THE STORE CALLBACK (not just the EVT visitor). Likely needs to rewrite tC_gD layout to skip every-other-N output.
Strategy B: problem.N = N_half (= 16384). Tell CUTLASS the output is N_half. Weight has 2×N_half = N_full rows but only the first N_half rows are read by the MMA (since CUTLASS computes based on problem.N). The other N_half rows are dead. NOT useful (we miss half the weight).
Strategy C: problem.N = N_half but use a LayoutB with stride that exposes 2 rows of weight per logical output col. E.g., the mainloop sees B at LogicalRow = i but the actual GMEM offset is i_actual = 2*i + (k_inner_idx & 1). This is a weight-layout trick. Complex and may need cute layout customization.
Strategy D (alternative): keep problem.N = N_full, run the full GEMM and quantize to FP4 (N_full size), then do pair-fold + re-quantize in a separate kernel launched in the same stream. This loses the BW saving (writes full-N FP4 + reads it back). Defeats the purpose.
Strategy E: Use two passes through the visitor — first pass collects amax over pair-folded values into shared memory; second pass scales and stores. visit() called once per fragment by CUTLASS, so this may need a state machine.
Please:
Read the cute_dsl sm_100 swiglu reference and report HOW it handles the output dim halving — does the underlying GEMM produce N_full and then compress, or does it run at N_half with paired weight?
Read the existing Sm120BlockScaleFactorRowStore reduce() (sm120_visitor_store_tma_warpspecialized.hpp:219-450) and identify EXACTLY which lines need to change for pair-folding (consider AccFragsPerSF doubling, etc.).
Identify which CUTLASS file controls the actual D tensor store after reduce() — i.e., where visit_results is finally written to GMEM. Is it in the same Sm120BlockScaleFactorRowStore class, or in a higher-level epilogue file? We need to compress fragment N before this point.
Recommend the simplest viable strategy (A/B/C/D/E or hybrid) for an S2 PoC that JUST does identity pair-mul (no silu), with FP4 quantization correctness verified against a simple BF16 reference:
Provide a concrete code sketch for the simplest strategy in CUTLASS terms — what new visitor/callback to write, what to change in the kernel template instantiation, expected ~100-300 lines of new code.
Identify pitfalls that could make S2 fail or require S2b (e.g., SFVecSize alignment after fold, fragment storage layout mismatch, warp cooperation pattern conflicts).
Report under 1500 words, with concrete file:line references and the recommended code sketch. The goal is to enable me (or a follow-up agent) to actually implement S2 in 1-3h without re-doing this analysis.
acc_frag[acc_frag_row]
acc_frag[acc_frag_row + 1]
For pair-fold inside reduce(), the surgical edits are:
AccFragsPerSF_in = SFVecSize / (1 * NumThreadsPerQuad * WarpsPerSF) (double — each output SF still covers SFVecSize output elems; in input domain those occupy 2× the cols, but we still produce only 1 output element per pair, i.e., per acc_frag the effective ColsPerOutFrag = 1)
replace amax_op(amax, acc_frg[acc_frag_row]) with amax_op(amax, swiglu(acc_frg[acc_frag_row + 0], acc_frg_pair[acc_frag_row + 0])) — see Strategy A below
L418–423 scale-write loop
rewrite to (a) compute fused value out = swiglu(g, u) * acc_scale, (b) store into the lower half of visit_results, (c) zero/keep upper half (it gets discarded by the store callback)
Critically the SF generation rate does not change in count if you also halve the SFD layout — output has N/2 cols, each SF covers SFVecSize=16 of those, so each thread still emits the same number of SFs. The shfl_xor pattern (L348–352, L370–376) for amax across quads is unchanged — pair-mate is in the same thread's fragment (positions [0,1] vs [2,3] of acc_frag).
Pair-mate location confirmed in user prompt: with B permuted so adjacent rows alternate (g, u), the per-thread fragment of size 4 = {frag[0]=g_i_row0, frag[1]=u_i_row0, frag[2]=g_i_row1, frag[3]=u_i_row1} because ColsPerThreadAccFrag=2 and RowsPerThreadAccFrag=2 — the two cols of one MMA quad fragment are adjacent N — exactly the (g, u) pair. So swiglu(frag[0], frag[1]) and swiglu(frag[2], frag[3]) give the two output values for that row-pair, with zero shuffle.
3. Where visit_results actually becomes a GMEM store
bSG_gD partitioning (L646) and gD_epi = flat_divide(gD, EpilogueTile{}) (L576) both come from gD = local_tile(mD, take<0,2>(CtaTileMNK{}), coord_shape) (L573) and mD = ...get_tma_tensor(make_shape(M,N,L)) (L571) where N = problem.N. The TMA descriptor for D is built at CollectiveBuilder time from problem.N × LayoutD.
So N halving in the GMEM/TMA store path requires that either (a) the kernel sees problem.N = N_half (and we hide the 2× weight rows in the mainloop), or (b) we customize CollectiveEpilogue and tma_store_d so problem.N (mainloop) ≠ D.N (epilogue).
4. Recommended strategy: C+A hybrid — call it Strategy F
Strategy A pure ("MMA full-N, compress in store") requires writing a custom Sm120 collective epilogue that decouples MMA-N from D-N — too invasive for S2. Strategy B is wrong (drops half the weight). Strategy C alone (LayoutB stride trick) is fragile and likely breaks TMA descriptor assumptions for B. Strategy D defeats the BW savings.
Strategy F (recommended for S2 PoC):
Set problem.N = N_half so the entire collective epilogue (gD, sD, TMA store_d, SFD layout) is half-sized — no epilogue collective fork needed.
Double-stride trick on the MMA, in K only — at GMEM-tile level, swap from "load B[n, k]" to "load B[2n, k] and B[2n+1, k] in adjacent K-tiles, accumulate into adjacent N slots of the same MMA fragment". This is hard.
Actually no — Strategy F is too clever. Let me reconsider.
Simplest viable S2 (revised recommendation): Strategy A with custom collective epilogue dimensions, but use problem.N = N_full and customize ONLY the SFD layout + a thin store wrapper:
Look again at what's hard-wired by problem.N:
TMA descriptor for D (built in CollectiveEpilogue constructor)
mD_mn = make_shape(M, N, L) (sm90 line 571)
SFD tile_atom_to_shape_SFD(problem_shape_mnkl)
All three are computed at host-side from problem_shape. If we set problem.N = N_full, we get a full-N D buffer and full-N SFD — the BW win is lost.
Real simplest viable S2 — Strategy G: set problem.N = N_half, run MMA at N_half, and pre-permute weight so the (g,u) pair is along K, not N. I.e.: instead of B having interleaved rows, B has rows b_i = concat(gate_row_i, up_row_i) along K and the GEMM computes Y[i, j] = sum_k a[i, k] * (gate[j, k] + up[j, k]) — NO. That's the wrong math.
OK let me actually think clearly. SwiGLU requires two separate dot products per output: Y_g = a · g, Y_u = a · u, then out = silu(Y_g) * Y_u. You cannot fuse them into one dot product. So MMA must produce both, the question is just where they live spatially.
Therefore the only viable answer is the cute_dsl pattern: MMA at full N, output at half N, with a custom collective epilogue that knows the C/D tiler is half the MMA N tiler.
Final recommendation for S2 PoC
Strategy H (the realistic answer): do not modify the visitor's reduce() first. Instead:
Stage S2a (the genuinely-simplest PoC, ~50 LOC, no CUTLASS template surgery): implement Strategy D (full-N FP4 quantize then a separate Triton/CUDA pair-fold + re-quantize kernel). This validates the math + permuted-weight layout + reference parity without touching CUTLASS. Cost: lose BW. Value: provides a known-good numerical reference for S2b and unblocks Eagle/Marlin integration testing.
Stage S2b (true fused, ~250 LOC): fork Sm120BlockScaleFactorRowStore into Sm120BlockScaleFactorRowStoreSwiGLUFold (same file, sibling struct), and write a thin Sm120SwiGLUFusedCollectiveEpilogue that:
Takes problem_shape with N_full for mainloop sizing but exposes N_half for gD/sD/tma_store_d/SFD.
Constructs gD_epi from local_tile(mD_half, (CTA_M, CTA_N/2), ...) while gAcc still comes from full-N mainloop.
Iterates the epilogue loop with epi_n going 0..size<3>(gD_epi) (half count), and the visitor sees tRS_rAcc_frg_mn indexed by adjacent pairs of MMA N tiles.
This is the C++ port of mma_tiler_c[1] = mma_tiler[1] // 2 from cute_dsl.
5. Code sketch (S2b, the fused path)
cpp
// 1. New visitor with pair-fold reduce()
template <int SFVecSize, class EpilogueTile, class CtaTileShapeMNK,
int FragmentSize, class ElementOutput, class ElementCompute,
class ElementBlockScaleFactor>
struct Sm120BlockScaleFactorRowStoreSwiGLUFold {
// Identical Arguments/Params/SharedStorage to Sm120BlockScaleFactorRowStore
// visit() still passthrough — work happens in reduce()
template <class SmemT, class SyncFn, class VTensor>
CUTLASS_DEVICE void reduce(SmemT&& smem, SyncFn const& sync, int epi_m,
int epi_n, bool is_last, VTensor visit_results) {
static constexpr int ColsPerThreadAccFrag = 2; // 2 N cols per quad frag
static constexpr int RowsPerThreadAccFrag = 2;
static constexpr int NumThreadsPerQuad = 4;
constexpr int WarpsPerSF = SFVecSize / 16;
// Each output SF covers SFVecSize output cols == 2*SFVecSize input cols.
// Per-thread input-col coverage doubles -> 2x AccFragsPerSF:
constexpr int AccFragsPerSF =
(SFVecSize * 2) / (ColsPerThreadAccFrag * NumThreadsPerQuad * WarpsPerSF);
static_assert(size<2>(visit_results) % AccFragsPerSF == 0);
for (int sf_id = 0; sf_id < size(tC_rSFD_flt); ++sf_id) {
// ... unchanged coord decoding ...
ElementCompute amax{0};
auto acc_frag_row = row_in_acc * RowsPerThreadAccFrag;
auto acc_frag_start_for_sf = sf * AccFragsPerSF;
for (int i = 0; i < AccFragsPerSF; ++i) {
auto& f = visit_results(0, row, acc_frag_start_for_sf + i);
// Pair-fold: positions [0]=g0,[1]=u0 -> y0
// positions [2]=g1,[3]=u1 -> y1
ElementCompute y_lo = f[acc_frag_row + 0] * f[acc_frag_row + 1];
ElementCompute y_hi = f[acc_frag_row + 0] * f[acc_frag_row + 1]; // adjust
// (S2 PoC: identity g*u; replace with silu(g)*u later)
amax = amax_op(amax, y_lo);
amax = amax_op(amax, y_hi);
// Stash fused values back into f[0],f[1] (output domain)
f[0] = y_lo; f[1] = y_hi;
}
// ... unchanged shfl_xor + cross-warp amax reduce ...
// Write SFD as before (only difference: SFD is sized for N_half via
// problem_shape passed at host).
// ... unchanged scale-write loop — but loop body now stores back into
// f[0..1] only (f[2..3] are dead garbage).
}
// Unchanged write_sf gate and copy_aligned.
}
};
// 2. Fork the CollectiveEpilogue so D-side uses N_half but mainloop sees N_full.
// Simplest: subclass / wrap the sm90 collective with a host-side trick.
// Two-problem-shape approach in prepare_args:
// - mainloop is sized by (M, N_full, K, L)
// - epilogue's gD/sD/tma_store_d/SFD are sized by (M, N_half, K, L)
// - this requires forking the collective builder OR a manual GemmKernel
// instantiation where the CollectiveEpilogue is constructed with a
// reduced "problem shape" while CollectiveMainloop holds full N.
// 3. fusion::FusionCallbacks specialization for a new LinCombSwiGLUFoldBSF op
// that wires Sm90EVT<Sm120BlockScaleFactorRowStoreSwiGLUFold<...>,
// Sm90LinearCombination<...>>.
The fork point is CollectiveBuilder lines 491–501 in sm120_builder.inl. The cleanest implementation is to write a manual CollectiveEpilogue template (bypass the builder) where you pass two different CtaTileMNK sizes: a "mainloop tile" with N=128 and an "epilogue tile" with N=64. Then gD/sD/tma_store_d are built from the epilogue tile. Mainloop accumulator stays sized to N=128; visitor sees tRS_rAcc_frg of double N-extent vs. tRS_rD_frg, and the pair-fold drops the second half.
6. Pitfalls
Builder will reject inconsistent tile sizes.Sm120TmaBuilderImpl derives EpilogueTile_MN from TileShape_MNK and asserts EpilogueTile_MN | CtaTileMNK. You must hand-roll the epilogue template instantiation, not use CollectiveBuilder.
SmemD swizzle atom is sized by EpilogueTile. If epilogue tile N changes from 128→64, the smem swizzle (sm120_get_epilogue_smem_swizzle_layout_atom, sm120_builder.inl L375) regenerates; make sure your hand-rolled version uses the half-N tile.
Sm90LinearCombination::visit() returns the binary op result of size FragmentSize=4. Your pair-fold reduces 4 acc lanes to 2 output lanes — but tRS_rCompute_frg is shaped (FragmentSize=4, ..., R2S_N). Either: (a) keep FragmentSize=4 and waste-write the upper half (then the store callback's tiled_r2s will write garbage to smem positions that must not be TMA'd — needs predication), or (b) introduce a half-sized tRS_rCompute_half_frg view and a custom tiled_r2s that copies only the lower 2 lanes per fragment.
AccFragsPerSF doubles (output SF covers same #output cols but 2× input MMA cols). Verify size<2>(visit_results) % AccFragsPerSF == 0 does not regress.
Norm constant & amax over FUSED values, not raw acc. Apply silu(g)*u first, then amax — the existing reduce() does amax over raw acc; you must move the fused-compute before amax. This is shown in cute_dsl line 2664 (compute) → line 2696 (amax over tCompute).
SiLU numerical accuracy. cute_dsl uses exp2(-x*log2e) + rcp_approx (line 2624–2639). Approximate, fastmath. PoC can start with silu(x) = x / (1 + __expf(-x)); tighten later.
Norm constant double-application.LinCombBlockScaleFactor multiplies by alpha in Sm90LinearCombination::visit() and again uses norm_constant in Sm120BlockScaleFactorRowStore. With pair-fold, silu(alpha*g) * (alpha*u) is what cute_dsl does (lines 2658–2666). Make sure alpha is applied before silu, not after.
TMA store size mismatch. TMA D descriptor stride is set from problem.N at kernel init. If you cheat and only call TMA with N_half elements per tile, the descriptor must be built for an N_half tensor — meaning user-side allocation, problem_shape, and SFD layout must be N_half. The output buffer in prepare_args must be sized (M, N_half/2 bytes). This is already correct in the scaffold.
MmaNPerEpiN branch (sm90 line 824). If your hand-rolled epilogue keeps EpilogueTile.N=64 but MmaTile.N=128, the epi_tile_m * epi_tile_n > mma_tile_m * mma_tile_n path triggers; you get an inner mma loop iterating MmaNPerEpiN=2 times — exactly the pair-iteration. This is the natural insertion point: when MmaNPerEpiN==2, the visitor visit() is called twice per epi_n, with mma_n_in_epi=0 (gate) and mma_n_in_epi=1 (up). Pair-fold can be done in visit() by stateful accumulation across these two calls instead of inside reduce(). This is actually the cleanest implementation path and avoids most of the visitor surgery.
Revised final recommendation
Use the MmaNPerEpiN==2 natural pair-iteration at sm90_epilogue_tma_warpspecialized.hpp:830–843 (Strategy I). Concretely: keep CUTLASS builder happy by setting CtaTileMNK = (CTA_M, CTA_N=128, CTA_K) and EpilogueTile = (EPI_M, EPI_N=64). With problem.N = N_half, mainloop produces full-N fragments (... no, mainloop is also driven by CtaTileMNK.N=128). To get the full-N MMA but half-N epilogue, the EpilogueTile alone isn't enough — you still need decoupled tilers, which means the hand-rolled CollectiveEpilogue.
The honest minimum complexity for true fused S2 is ~300 LOC: a fork of the visitor (~100), a fork of Sm120TmaBuilderImpl to decouple MMA-N from D-N (~150), new FusionCallbacks specialization (~50). Start with S2a (Strategy D) to lock down the math, then S2b.
Key file references for the implementer
Visitor to fork: sm120_visitor_store_tma_warpspecialized.hpp:60-510 (reduce body :219-450)
Where visit_results becomes D smem store: sm90_epilogue_tma_warpspecialized.hpp:884-891
TMA D store call: sm90_epilogue_tma_warpspecialized.hpp:734-745
Builder to fork for decoupled MMA/D tiles: sm120_builder.inl:344-440 (Sm120TmaBuilderImpl)
第一次 kernel launch时,runtime 会拿不到 sm_120 的 cubin/PTX entry → cudaErrorNoKernelImageForDevice (error 209: "no kernel image is available for execution on the device")。
这正是 Dao-AILab/flash-attention#1638 报的错。
没有 PTX fallback:-gencode=arch=compute_90a,code=sm_90a 不带 code=compute_90a PTX,所以 JIT-to-target 也不可行;即便带 PTX,sm_120 ptxas 也会拒绝 wgmma/SM90_TMA_* 指令(外部确认 wgmma.fence not supported on .target 'sm_120')。
结论:强制 fa3 → 运行时崩(选项 b 的精确变体:JIT compile 成功,第一次 launch IMA / cudaErrorNoKernelImageForDevice)。不会 silent fallback to fa2。