Repository navigation
fix(flash next cuda): build the CUDA extensions before the weights load - #202
mcclanahanaman wants to merge 1 commit into
Conversation
A first start after an install or an update builds each CUDA extension the first time a step needs it (tensorfold.cuda.build.load). Flash Next met most of them in its prompt warm-up, after the weights had loaded. On a GPU that shares the host's memory, those builds left the server with less MemAvailable (still missing 20 s after it came up; the next start did not miss it), which the memory gate's live check works with. engine.build_kernels now loads every extension a Flash Next start uses (the NVFP4 linears' and the EXL3 packs' only for those checkpoints, the one-stream chain's only for one stream) right after admission, before the weights load: the same builds, earlier. Jetson AGX Thor, local-inference-lab Qwen3.8-Flash-Next-NVFP4 rev 7c4f1bc1, --kv-dtype int8 --parallel 4, MemAvailable 20 s after the server is up, a start with an empty extension cache minus the next start, in two container sessions: upstream 0.6.0 -2.00 and -1.36 GiB (6 builds, all after the load; MemFree moves with it, while the server's resident set, page cache and slab do not); this change -0.15 GiB (6 builds, before the load; an earlier revision that also built the one-stream chain: -0.01 GiB). Two starts that build nothing differ by up to 0.11 GiB. The printed cache room is 32.2-32.3 GiB in every start. tests/cuda/test_flashnext_forward.py: a start on the synthetic checkpoint loads every extension before the weights (one and two streams); with 0.6.0's engine.py it fails at both. tests/test_cuda_capacity.py's fake_runtime, which stops a start at its weights load to check admission without a GPU, now stubs build_kernels too. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01PRwDEapgChAWSk1ncJ62Yk
|
Thanks @mcclanahanaman. I measured this on a second unified-memory box: one DGX Spark (GB10, sm_121, 128 GB), Vontra Flash Next MLX 4-bit,
So on GB10 the cold start leaves about 2.5–2.8 GiB more available with the change, and it ends close to a warm start, as you saw on Thor. Startup time didn't change. With the PR, the five extensions build in |
|
Thank you, @mcclanahanaman. Building the CUDA extensions before the weights load is in TensorFold 0.6.4, with your commit under your name and a few lines changed to fit main: https://github.com/ashhart/TensorFold/releases/tag/v0.6.4 On a DGX Spark the combined Flash Next stack (#202, #201, #254, #248, #268) matched one-token decoding in 12 of 12 cells, with prompt speed at parity. Thank you for the careful work. |
Branch:
fix/flash-next-build-before-load(one commit, 5c5931b, onv0.6.0, c464617)TL;DR: On a first start after an install or an update,
tensorfold.cuda.build.loadcompiles each CUDA extension the first time a step needs it. Flash Next met them in its prompt warm-up, after the weights had loaded. On a Jetson AGX Thor (unified memory), that left the server with 1.36-2.00 GiB less MemAvailable than the next start (two sessions), still missing 20 s after the server came up. The engine now loads every extension it uses right after admission, before the weights load. With the same builds, the difference is 0.01-0.15 GiB, about the 0.1 GiB by which two starts that build nothing differ.The problem
pip install -Uortensorfold update) builds six extensions:tensorfold_nvfp4_prompt_v1,tensorfold_qwen4_exp_gdn_io,tensorfold_gdn_v2,tensorfold_experts_v7,tensorfold_nvfp4_v3andtensorfold_qmm_v3. All six are built after the weights load, in the warm-up.Cachedmoved by 0.07 GiB or less, andAnonHugePagesby 0.14 GiB. In the first stock session, about 1 GiB moved fromActive(file)toInactive(file)while netCachedstayed put. Where the missing GiB is held is not identified.MemoryGate.fitschecks the caches' growth against live MemAvailable. So the streams' caches have 1.4-2 GiB less to grow into for as long as the memory stays missing. How long that lasts in a running server was not measured. The printed "free for their caches" does not show it: it reads the same after both starts.The change
engine.build_kernels(exl3=, nvfp4=, solo=), which loads:experts,kernels.gdn,kernels.qmmandqwen4_exp.cuda.gdn_io;qwen4_exp.cuda.gdn(concurrent rounds never use it).FlashNextEngine.__init__calls it right after admission, so a refused start builds nothing, and beforeweights.load.tests/cuda/test_flashnext_forward.py::test_the_engine_loads_its_extensions_before_the_weights, at one and two streams. It records everytensorfold.cuda.build.loadcall and theweights.loadcall during a start and a first request on the synthetic checkpoint, and checks that no extension is loaded after the weights. It clears the loaders'lru_cachefirst, so each one goes throughbuild.load.tests/test_cuda_capacity.py::fake_runtime, which stops a start at its weights load to test admission without a GPU, now stubsbuild_kernels.Measurements
Jetson AGX Thor,
local-inference-lab/Qwen3.8-Flash-Next-NVFP4rev7c4f1bc1,--kv-dtype int8 --parallel 4. Two container sessions (1:up-m1, 2:up-b4), each with four starts in a row; the server was stopped and given 15 s between starts. MemAvailable was read 20 s after the server answered/v1/models:tensorfold serveand/proc/meminfo.The same kind of loss showed up earlier on a local Thor branch, on a first start that built its extensions after the weights loaded. Not measured: DGX Spark. It is also unified memory, so it may behave the same way.
Tests
tests/cuda/test_flashnext_forward.py::test_the_engine_loads_its_extensions_before_the_weights, at one and two streams.engine.py, both fail. One stream liststensorfold_experts_v7,tensorfold_qmm_v3,tensorfold_qwen4_exp_gdn,tensorfold_qwen4_exp_gdn_ioandtensorfold_gdn_v2. Two streams list the same set withouttensorfold_qwen4_exp_gdn. The synthetic checkpoint does not load the NVFP4 extensions.up-b4,up-b5):tests/cuda/test_flashnext_forward.py: 56 passed.tests/cuda/test_flashnext_nvfp4_loader.py,test_flashnext_tp.pyandtest_flashnext_multi.py: 70 passed, 2 skipped, 2 failed. The 2 failures aretest_flashnext_multi.py::test_packed_passes_keep_each_prompt_one_token_early[bf16]and[int8]. They fail the same way on plain 0.6.0 (details in the stage-ahead PR).tests/test_cuda_capacity.py,test_cuda_kv_dtype.py,test_cuda_parallel_admission.py,test_cuda_admission.py,test_exl3_engines.pyandtest_cuda_nemotron_admission.py): 147 passed.build_kernelsare exercised only by the CPU tests, which stub it;The commit also applies cleanly to the 0.6.1 branch (
pr-141-0.6.1). There, the list inbuild_kernelsshould be checked against the vision and image-row paths it adds. The new test would show any extension loaded after the weights.AI disclosure: an AI coding agent (Claude Code) wrote this change and ran the measurements on my Jetson AGX Thor. I approved posting it; I have not reviewed the code line by line.
🤖 Generated with Claude Code
https://claude.ai/code/session_01PRwDEapgChAWSk1ncJ62Yk