Repository navigation
build: add opt-in FLASHRT_SLIM_BUILD to trim VLA-deployment kernel compile surface - #120
Merged
LiangSu8899 merged 9 commits intoJun 27, 2026
Conversation
Add a build-structure measurement tool ahead of the VLA-deployment kernel gating work. scripts/build_inventory.py reads a configured CMake build dir (CMakeFiles/<target>.dir/DependInfo.cmake, generator-agnostic) and reports the translation units each pybind module compiles directly, categorizing the flash_rt_kernels surface per the Current Build Layout groups. tests/test_build_inventory.py pins the current SM89 baseline (flash_rt_kernels = 55 TUs: 15 generic / 12 qwen36 / 7 sm120-nvfp4 / 7 motus-video / 2 dit / 2 qwen3 / 10 other) and asserts the neutral helpers (bf16_matmul_bf16, embedding_lookup_bf16) stay in the generic core. It skips cleanly without a configured build dir. Also document in CMakeLists.txt that the upcoming cleanup is compile-time surface reduction only (no kernel math / dispatch / graph-capture / runtime fallback change) and stays compatibility-default until validated. No runtime behavior change.
Introduce FLASHRT_SLIM_BUILD (default OFF) for VLA deployments that do not need the full model/architecture-specific kernel set. The standard build is unchanged (broad, compatibility-oriented); turning the option ON drops translation units a given path does not use, reducing flash_rt_kernels compile time. Compile-time surface reduction only — no kernel math, dispatch, graph capture, or runtime fallback change. First gated group: 5 Motus-VAE-only FP8 quantize TUs that today compile unconditionally even on SM89 where no Motus model runs: awq_quant_fp8_static_bf16, bf16_ndhwc_to_ncdhw_transpose, bf16_quant_fp8_ncdhw_to_ndhwc, bf16_rms_silu_ncdhw, bf16_rms_silu_quant_fp8_ncdhw_to_ndhwc_v4 Their bindings in csrc/bindings.cpp are guarded by FLASHRT_HAVE_MOTUS_VAE_FP8 (includes + 11 m.def sites) so they drop in lockstep with the sources; the Motus Python frontend already probes them with hasattr(). ada_layer_norm_fp8.cu and bias_gelu_quantize_fp8.cu are deliberately kept always-compiled: a binding trace found ada_layer_norm_fp8 is used by GROOT N1.7 and bias_gelu_quantize_fp8_static_bf16 by Melband-RoFormer, so they are not Motus-only and stay in the core (neutral ownership deferred to a later PR). Validation (local SM89, RTX 4090): - default configure: flash_rt_kernels = 55 TUs (unchanged); builds + links. - slim configure: flash_rt_kernels = 50 TUs (5 dropped); builds + links cleanly with bindings guarded. - default .so exposes all 11 Motus symbols + the 2 shared symbols. - tests/test_generic_kernel_bindings.py + tests/test_build_inventory.py pass. - Qwen3-VL 2B SM89 smoke unchanged: prefill 81.1ms, decode 3.748ms, cos_vs_eager=1.0.
Gate 10 Qwen3.6-family-only TUs behind FLASHRT_SLIM_BUILD (via the internal
FLASHRT_HAVE_QWEN36_KERNELS compile-def). These are used only by the Qwen3.6
family (Qwen3.6 dense/thor/spark + Nex-N2, the Qwen3.6-35B-A3B MoE):
causal_conv1d_qwen36, linear_attention/gated_delta_wy_{bf16,bf16_mma_fla,
output_o_mma_fla,recompute_wu_mma_fla}, gated_deltanet_qwen36,
rms_norm_gated_silu_qwen36, qwen36_misc, bf16_matmul_qwen36,
bf16_matmul_qwen36_thor
A slim VLA build (Qwen3-VL etc.) needs none of them; Qwen3-VL touches zero of
the 12 candidate files. Their bindings in csrc/bindings.cpp (5 contiguous m.def
runs + 9 includes) are guarded by the same macro so they drop in lockstep with
the sources.
Kept always-compiled (NOT gated):
- silu_mul_qwen36.cu: silu_mul_qwen36_bf16 is shared by Qwen3-dense
(qwen3_rtx.py), Higgs, and Cosmos3-video; sigmoid_mul_qwen36_bf16 ships in
the same TU.
- bf16_matvec_qwen36.cu: bf16_matvec_qwen36_bf16 is used by Higgs.
- neutral helpers bf16_matmul_bf16.cu / embedding_lookup_bf16.cu (flashrt-project#112) stay in
the core; only the legacy wrappers bf16_matmul_qwen36_bf16 /
qwen36_embedding_lookup_bf16 live inside the gated TUs. flashrt-project#112 migration is
confirmed complete (those legacy symbols have only Qwen3.6 callers now).
These two qwen36-named-but-shared files mirror Unit 1's ada_layer_norm /
bias_gelu carve-out; neutral ownership is deferred to a later flashrt-project#112-style PR.
Validation (local SM89, RTX 4090):
- default configure: flash_rt_kernels = 55 TUs (unchanged); builds + links.
- slim configure: flash_rt_kernels = 40 TUs (10 dropped); builds + links cleanly
with bindings guarded.
- default .so exposes all gated Qwen3.6 symbols + the shared + neutral symbols.
- tests/test_generic_kernel_bindings.py + tests/test_build_inventory.py pass.
- Qwen3-VL 2B SM89 smoke unchanged: prefill 81.4ms, decode 3.746ms,
cos_vs_eager=1.0.
- Gap: full Qwen3.6 / Qwen3-dense runtime smoke needs the server path / extra
resources; the keep-list decision is validated structurally (shared sources +
ungated bindings remain in both modes).
Stop compiling 7 SM120/NVFP4-named TUs in slim SM89 builds. They are named/built for SM120 NVFP4 but compiled unconditionally, wasting time on SM89 where they are unreachable. Each group compiles when 'NOT FLASHRT_SLIM_BUILD OR <arch macro ON>', which keeps the default SM89 surface at 55 (compatibility), drops all 7 only in a slim SM89 build, and guarantees SM120/NVFP4 builds keep them (slim or not). Group A (4 fp4_w4a4_*_sm120): bindings are already inside #ifdef ENABLE_CUTLASS_SM120_NVFP4_W4A16, so on SM89 the Python symbols never existed; only the source compiled. Gate the sources on the SAME condition that defines that macro (GPU_ARCH 120/121) — the macro is a compile-def, not a CMake variable, so it is not tested as one. No bindings.cpp change for this group. Group B (fp8_block128_to_nvfp4_swizzled, bf16_weight_to_nvfp4_swizzled, silu_mul_to_nvfp4_swizzled): bindings were unguarded (exposed on SM89 but runtime-unreachable; every Python loader self-gates on has_nvfp4()). Gate the sources on 'NOT slim OR ENABLE_NVFP4' and guard the bindings + includes with the matching FLASHRT_HAVE_NVFP4_SWIZZLE compile-def in lockstep. No new parallel arch gate invented; reuses ENABLE_CUTLASS_SM120_NVFP4_W4A16 / ENABLE_NVFP4 per plan. Validation (local SM89, RTX 4090): - default SM89: flash_rt_kernels = 55 TUs (unchanged); builds + links; Group B symbols present, Group A binding arch-gated absent (both unchanged from before). - slim SM89: flash_rt_kernels = 33 TUs (7 dropped); builds + links cleanly. - configure-check GPU_ARCH=120 slim: all 7 kept (sm120_nvfp4_named=7) via the arch-macro OR condition — no SM120 GPU locally, configure/inventory only. - tests/test_generic_kernel_bindings.py + tests/test_build_inventory.py pass. - Qwen3-VL 2B SM89 smoke unchanged: prefill 81.3ms, decode 3.750ms, cos_vs_eager=1.0.
Document that a slim SM89 build (FLASHRT_SLIM_BUILD=ON) drops 22 TUs (55 -> 33): -5 Motus VAE FP8, -10 Qwen3.6/linear-attn, -7 SM120/NVFP4-named. Comment-only; the default-build baseline assertion stays 55.
The slim build (FLASHRT_SLIM_BUILD=ON) gates Qwen3.6 TUs, so the legacy bindings bf16_matmul_qwen36_bf16 / qwen36_embedding_lookup_bf16 are intentionally absent there, and flash_rt_kernels drops to 33 direct TUs. The Unit 0 tests asserted the compat-only surface and failed under slim. - test_generic_kernel_bindings: detect build mode from the module via a Qwen3.6 sentinel (causal_conv1d_qwen36_bf16) gated under the same FLASHRT_HAVE_QWEN36_KERNELS macro. Require legacy names only in compat; assert their absence in slim. Neutral names required in both modes. - test_build_inventory: read FLASHRT_SLIM_BUILD from CMakeCache.txt and assert the matching surface (compat 55 / slim SM89 33, with category breakdowns). - build_inventory: object libraries linked via $<TARGET_OBJECTS:...> were not counted (fa2 reported 1 TU vs 21 real). Report per-obj-lib TUs, attribute them to the linking module via link.txt/build.ninja, and add object_tu_count / total_tu_count. Add a regression test.
Harden the slim-aware binding/inventory tests: - test_generic_kernel_bindings: determine slim vs compat from FLASHRT_SLIM_BUILD in CMakeCache.txt instead of inferring it from the presence of a Qwen3.6 sentinel symbol. Symbol-inference silently passes a compat build that regressed and dropped the whole Qwen3.6 binding group (no sentinel -> looks slim -> 'absent' asserts pass). Now compat asserts the sentinel + legacy names ARE present, slim asserts they are NOT, and the sentinel is a cross-check against the configured mode. - test_build_inventory: the direct-count/category baselines are SM89-only (other arches add/remove arch-owned sources), so skip them whenever the configure is not SM89, in compat as well as slim.
Address review nits on the object-library accounting: - Ninja branch matched the target name as a bare substring, which could mis-attribute object libs to a longer target whose name contains this one. Match the module filename (<target>.cpython-...so) instead. - Distinguish 'manifest found, no object libs' (empty set) from 'no manifest' (None) in the Ninja branch, matching the Makefile link.txt branch semantics. - Document that object-library discovery relies on the <name>_obj naming convention used throughout CMakeLists.txt. Tooling-only; local Makefile builds exercise the link.txt path and report unchanged (kernels 55+2=57, fa2 1+20=21).
Member
|
I added a small public docs patch on top of this PR:
Local checks for the docs patch:
|
LiangSu8899
approved these changes
Jun 27, 2026
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
Adds an opt-in
FLASHRT_SLIM_BUILDCMake option (default OFF) that dropsmodel/architecture-specific CUDA translation units the target hardware/model
path does not need, reducing
flash_rt_kernelscompile time for VLAdeployments on weaker build machines.
This is compile-time surface reduction only. It does not change kernel math,
launch parameters, thresholds, dtype conversions, dispatch policy, graph-capture
behavior, Python API semantics, or runtime fallback. The default build keeps the
exact broad, compatibility-oriented kernel set it has today; slimming is fully
opt-in.
How it works
Each gated group is guarded by its own internal
FLASHRT_HAVE_*compiledefinition so the corresponding pybind bindings in
csrc/bindings.cppdrop inlockstep with their sources — a gated source whose binding stayed compiled
would fail to link. Architecture-keyed groups reuse the existing arch macros
(
ENABLE_NVFP4,GPU_ARCH) so real NVFP4/SM120 builds always retain them, slimor not.
Gated groups (slim mode):
Shared FP8 helpers used by other models (GROOT AdaLN, MelBand GeLU-FFN) stay
always-compiled.
helpers reused by Qwen3-dense / Higgs / Cosmos3 stay always-compiled. Neutral
helpers (
bf16_matmul_bf16,embedding_lookup_bf16) are never gated.ENABLE_NVFP4/GPU_ARCHso SM120and NVFP4 builds keep them in both modes.
Tooling
scripts/build_inventory.pyreports the directly-compiled TUs per pybindtarget from the configured build dir (generator-agnostic, via
DependInfo.cmake), categorizes theflash_rt_kernelsset, and accounts forobject-library TUs linked via
$<TARGET_OBJECTS:...>so the reported compilesurface is not understated.
tests/test_build_inventory.pyandtests/test_generic_kernel_bindings.pyare build-mode aware: they read
FLASHRT_SLIM_BUILDfromCMakeCache.txtandassert the matching surface and binding contract. Compat asserts legacy +
neutral bindings present; slim asserts the gated legacy bindings are absent
while neutral bindings remain.
Validation
SM89 (RTX 4090):
flash_rt_kernels: 55 direct (+2 object) TUs.flash_rt_kernels: 33 direct (+2 object) TUs (−22 direct).flash_rt_qwen3_vl_kernels(9) andflash_rt_fa2(1+20) unchanged.absent in slim; neutral bindings present in both.
Thor (compute capability 11.0,
GPU_ARCH=110):flash_rt_kernels: 59 direct (+8 object) TUs.flash_rt_kernels: 37 direct (+8 object) TUs (−22 direct).architecture-specific object libraries Thor requires.
Both architectures confirm: slim removes exactly the intended 22 direct TUs,
default compatibility builds retain the broad historical bindings, and no
architecture-specific object libraries needed at runtime are dropped.
Scope notes
kept always-compiled in this PR; neutralizing their ownership is deferred to a
follow-up to avoid moving kernel bodies here.
until more hardware/model paths are validated.