Repository navigation
Conversation
cmd_serve returned into _serve_cuda before it registered the SIGUSR1 stack dump, so the dump its comment calls "the way to see where a silent server waits" existed only on the Mac. The registration now comes before the backend branch; nothing else moves. Test: the handler is registered before _serve_cuda runs (host; fails before the change). The CUDA dispatch test stubs the registration, as the MLX tests do.
…ed build left The eleven CUDA extensions build on first use through tensorfold.cuda.build.load, which adds the GPU's -gencode flag and calls torch.utils.cpp_extension.load; neither prints anything. A start killed during a build leaves torch's lock in the build directory, and every later start waits on it without a word: the log stops at "loading ...", the GPU idles, and only a stack dump shows FileBaton.wait(). tensorfold.cuda.build.load still passes torch the same arguments. After the architecture check, and before torch's load, it looks up the build directory (torch's private _get_build_directory; without it, no line) and prints: - "building CUDA extension NAME (first start after an install or update; later starts reuse it)" when the directory holds no built module, or one older than a source; - the lock's path and "if no other build is running, a killed build left it: stop this start, delete the lock and start again" when the lock is there, again after 60 s if the same lock file is still there. The start is stopped first because a wait that ends imports whatever module the directory holds without building it: after an update, the old one. A GPU older than compute capability 9.0 is still refused before any line. Tests (host): the lines for a first build, a built module, a newer source and a lock; the repeat after the delay, and none after the load ends or the lock changes; the other arguments reach torch unchanged beside the GPU's flag; an older GPU is refused with no line; no line without the lookup; with real torch and nothing compiled, load waits on the very lock the line names until it is deleted. test_the_container_list_adds_nothing points TORCH_EXTENSIONS_DIR at a temporary directory, since load now looks up the build directory. tests/cuda/test_build.py builds one extension with nvcc, checks both lines end to end and that the named steps clear a planted lock. Not yet run on a GPU.
…ndezvous - Troubleshooting: a CUDA start that stops after "loading ..." with the GPU idle; kill -USR1 prints every thread's stack, and a wait in the extension build is a build lock whose path the start log names: stop the start, delete the lock and start again. - Two ranks: the rendezvous port (TCPStore, init_process_group tcp://) and the link between the ranks are not authenticated; keep them on a private link, or firewall the port to the peer.
nood-co1
force-pushed
the
contrib/cuda-start-diagnostics
branch
from
September 28, 2026 18:45
4ca35a3 to
215b3f0
Compare
This was referenced Sep 28, 2026
Owner
|
This shipped in 0.3.6.3 under your name (a586f3de). A CUDA start that goes quiet now says why: extension builds |
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
A CUDA start that waits shows nothing: the log stops at
loading …and the GPU idles. This PR makes it say why.kill -USR1 <pid>prints every thread's stack on CUDA too. It worked on the Mac only.RUNBOOK.mdgets a troubleshooting row for a silent CUDA start, and a note that the two-rank rendezvous is not authenticated.Why
At
main(71377a5, 0.3.6.2):cmd_servereturns_serve_cuda(...)(cli.py:433-434) before it registersfaulthandler.register(signal.SIGUSR1, all_threads=True)(cli.py:438-441). The comment there calls the dump "the way to see where a silent server waits", but a CUDA server never registers it.tensorfold.cuda.build.load(cuda/build.py:23-29), which adds the GPU's-gencodeflag and callstorch.utils.cpp_extension.load. All eleven extensions import it (cuda/experts.py:20,cuda/exl3/experts.py:25,cuda/exl3/linear.py:18,cuda/kernels/gdn.py:15,cuda/kernels/qmm.py:16,families/qwen3_5/cuda/b16.py:13,families/qwen4_exp/cuda/gdn.py:24,families/qwen4_exp/cuda/gdn_io.py:15,families/glm5_next/cuda/kda.py:15,families/glm5_next/cuda/exl3_mm.py:20andfamilies/nemotron_h/cuda/mamba.py:194) and passverbose=False. A build prints nothing._jit_compiletakes aFileBatonon<build directory>/lock. A process that finds the file there callsFileBaton.wait(), which polls until the file is gone and says nothing. torch 2.11 does not pass the baton'swarn_after_seconds. If a start is killed during a build, the lock stays, and every later start waits on it with no end._jit_compileimports the module the build directory holds and does not build (torch 2.11,cpp_extension.py:2286and:2294). Deleting the lock while a start waits therefore loads whatever a killed build left: after an update, the old module. A host probe (torch 2.11 CPU, build and import replaced by recorders, an older module and a newer source in the directory, the lock deleted after 0.5 s) recorded one import and no build. So the hint says to stop the start before deleting the lock.RUNBOOK.md:124-133) has no row for this. The two-rank section (:91) gives only the port number. Neither rendezvous is authenticated:TCPStoreincuda/comm.py:50, andinit_process_group("nccl", init_method="tcp://…")infamilies/qwen3_5/cuda/engine.py:44. NCCL's own connections between the ranks carry no authentication either.Change
cli.py: thefaulthandlerimport and registration, with their comment, now come beforeif backend == "cuda". Nothing else moves.src/tensorfold/cuda/build.py: 0.3.6.1'sload(**kwargs)becomesload(name, sources, **kwargs). It still appends the GPU's-gencodeflag fromarch_flags()first, so a GPU older than compute capability 9.0 is refused before any line, and it passes every argument totorch.utils.cpp_extension.loadunchanged. Before that call it finds the build directory:build_directory=when given, else torch's_get_build_directory(name, verbose=False). That is a private torch helper. If it is missing or raises, nothing is printed and the build goes ahead as before. Otherwise it prints:[tensorfold] building CUDA extension NAME (first start after an install or update; later starts reuse it)when the directory holds no built module (NAMEplus torch'sLIB_EXT), or when a source is newer than the built module. Headers and flags are not compared: a change to a header (cuda/experts.cuh,cuda/kernels/qmm_frag.cuh,cuda/exl3/decode.cuh,cuda/exl3/experts_grouped.cuh) or to an extension's flags alone rebuilds without the line.<dir>/lockexists, instead:[tensorfold] CUDA extension NAME waits on the build lock PATH; if no other build is running, a killed build left it: stop this start, delete the lock and start again.threading.Timer, cancelled when the load returns. The same-file check keeps the hint off a lock this start has taken for its own build.loadfromtensorfold.cuda.buildand passname=andsources=by keyword.RUNBOOK.md:loading …, GPU idle":kill -USR1 <pid>prints every thread's Python stack; a wait in the extension build is a build lock, and the start log names its path; when no other build is running, stop the start, delete the lock and start again;Not in this PR: building the extensions before the weights load. Since 0.3.6.2, Flash Next loads its prompt kernels at startup instead of on the first request (416106f, from #40); that still runs after the weights are read, and this PR's lines print wherever a build happens. Building before the weights load would change
families/qwen4_exp/cuda/engine.pyagain. It can follow as its own PR, together with an optionaltensorfold buildcommand that prebuilds the extensions into an image.Exactness
Not affected. The same names, sources and flags reach torch, 0.3.6.1's
-gencodeflag included, so the same modules are built and loaded. The PR adds printed lines and moves one signal registration. No kernel, engine or sampling code changes.Tests
Host: macOS, Python 3.13.5, PyTorch 2.11.0 CPU, MLX 0.31.1, an import-only stand-in for Triton (no kernel launches).
tests/test_cuda_cli.py::test_a_cuda_start_dumps_its_stacks_on_sigusr1:SIGUSR1is registered withall_threads=Truebefore_serve_cudaruns.test_cuda_dispatch_keeps_the_resolved_contextnow stubs the registration, as the MLX tests intests/test_memory_budget.pydo.tests/test_cuda_build.py: 13 tests added beside 0.3.6.1's four, under the sametorchmarker. torch's build and directory lookup are stubbed onto a temporary directory. The tests check that:build_directory=argument is the directory checked;-gencodeflag;tests/test_cuda_build.py::test_the_lock_named_is_the_one_torch_waits_onuses real torch and compiles nothing. It plants a lock atTORCH_EXTENSIONS_DIR/<name>/lockand checks thatloadwaits on that file, that the printed line names it, and that the call returns once the file is deleted (with an import error, since nothing was built).test_the_container_list_adds_nothingnow pointsTORCH_EXTENSIONS_DIRat a temporary directory, sinceloadlooks up the build directory.tests/test_cuda_build.pyandtests/test_cuda_cli.pyonmain's sourcesbuild._say, SIGUSR1 not registered); the 31 existing tests passtests/test_cuda_build.py25 times in a row (it has timer tests)testswithouttests/cuda),mainThe same 154 ids fail or error on both, and none is in this PR's two host files. This host has 36 GiB of memory, no Triton backends and no
transformerstokenizer, and has MLX 0.31.1 where GLM-5.3-Flash needs 0.32.2; the test tree used here has notools/orCHANGELOG.md. Thirteen one-line breakages of the branch, each applied alone, are each caught by the two host files; they include dropping the GPU's flag, printing before the architecture check, and one call site back on torch'sload.tests/cuda/test_build.py(new, GPU) buildstensorfold_qwen4_exp_gdn_iowith nvcc into an emptyTORCH_EXTENSIONS_DIRin a fresh process. The first start prints the building line and the second prints nothing. It then plants a lock and starts again: the start prints the lock line and waits. The test stops it, deletes the lock and starts again, which exits 0 and prints nothing.GPU status
Steps 1 and 2 passed; step 3 has not run. Surface: one DGX Spark (GB10); the
tensorfold-benchimage (PyTorch 2.13.0a0, NVIDIA 26.07; CUDA 13.3),TORCH_CUDA_ARCH_LIST=12.1; TensorFold 215b3f0, this branch onmain71377a5, imported from the branch's tree; toy models.python3 -m pytest tests/cuda/test_build.pypython3 -m pytest tests/cudamain(71377a5): 548 passed, the same 71 skipped. The 2 more aretest_build.py'sThe 71 skipped tests need EXL3, Nemotron or MLX checkpoints, ExLlamaV3, or
TENSORFOLD_TEST_NCCL=1; 18 of them compare with ExLlamaV3 at rate and codebook pairs it does not support.Building eight extensions into an empty
TORCH_EXTENSIONS_DIR: each printed[tensorfold] building CUDA extension NAME (first start after an install or update; later starts reuse it)on this branch; none printed a line onmain(71377a5).Not run:
TORCH_EXTENSIONS_DIRprints the building lines duringloading …; a start after one killed during a build prints the lock line, and 60 s later the repeat; during that wait,kill -USR1 <pid>prints the stacks; once that start is stopped and the lock deleted, the next start prints the building lines and finishes.Evidence
The wait this PR explains, as observed on TensorFold 0.3.1 before this change (not re-run on this branch; its served start is step 3 above, not run). Surface: one DGX Spark (GB10), NVIDIA's PyTorch container (
nvcr.io/nvidia/pytorch:26.07-py3, PyTorch 2.13.0a0), a one-GPU Qwen3.8 Flash Next start.A start killed while it built
tensorfold_qwen4_exp_gdnleft torch's lock.Every later start stopped at
loading …with the GPU idle.A
py-spy dumpof the waiting start showed:Deleting the lock before the next start fixed it.
On
main(0.3.6.2), from reading the code (the killed-build wait was not re-run): the eleven extensions still build on first use through torch'sload, by way oftensorfold.cuda.build.load, and nothing prints before the wait.A comment on #42 reports the same wait: a CUDA test slept about ten minutes with the GPU idle on a build lock in a
TORCH_EXTENSIONS_DIRshared by builds of eight commits, and passed with a fresh directory.#56 reported a CUDA extension build that fails rather than waits: on v0.3.5 and v0.3.5.1 (DGX Spark, torch 2.14.0a0), nvcc stopped on
tensorfold_qmm_v3because code that needs sm_89 or sm_90 was compiled for sm_80 and sm_86. 0.3.6.1 fixes that build: every extension builds throughtensorfold.cuda.build.load, which passes-gencodefor the GPU present and refuses a GPU older than compute capability 9.0. This PR keeps both. Its lines come after that check, and the GPU's flag still reaches torch.Overlaps
mainsince 0.3.6.2, and this branch is based on it.RUNBOOK.mdand merges clean there withmainand with this branch.RUNBOOK.md's troubleshooting table, where this PR adds a row: 1 conflict block. Keeping this PR's row as the table's last line, then CUDA: read the Flash Next NVFP4 (ModelOpt FP4) checkpoint as it ships #67's text, resolves it. CUDA: read the Flash Next NVFP4 (ModelOpt FP4) checkpoint as it ships #67 merges clean withmain, and its other files merge clean with this branch; both PRs' host test files pass on the merge: 110 tests.Submitted by an agent from Blockbrain Labs (https://x.com/blockbrain_labs, https://github.com/blockbrain-ai).