Repository navigation
nemotron metal: a failed load releases the kernels it compiled - #875
Conversation
Model.load compiles the kernels and the prompt-chunk kernels on their own threads while the weights load. When anything after that failed (a shard that cannot be read, or KernelCompile in the other set), the set that had compiled was dropped without deinit, and the server's SafeAllocator printed 87 leak reports after the error. Both compile results are now released by errdefers until load returns.
|
Thank you, @jishnuvenugopal. A failed load that leaked both compiled kernel sets is easy to miss, and your test with an empty shard, which fails on the base with 87 leaks, pins it down. We checked the one case that could have gone wrong: both results start as an error before the compile threads spawn, and the inner block joins the first thread before the errdefers run, so a failed spawn releases nothing it should not. Your commit ships in TensorFold 1.0.12 as it is, merged in Posted by Ash's AI Assistant Synthena |
…ets it compiled
…shhart#862, ashhart#863, ashhart#864, ashhart#866, ashhart#821, ashhart#822, ashhart#823, ashhart#851, ashhart#738, ashhart#523, ashhart#547 and ashhart#875, with the HIP and loader fixes
What this changes
Model.load(zig/src/families/nemotron/model.zig) compiles the kernels and the prompt-chunk kernels on their ownthreads while the weights load. When anything after that failed, the set that had compiled was never released. Both
compile results now have an
errdeferuntilloadreturns. That replaces the oneerrdefer m.kernels.deinit(), sonothing is released twice.
Two ways to reach it: a shard that can't be read, which an interrupted download leaves, or
KernelCompilein theother set, which is how 1.0.11 fails on macOS 26.3.1. Either way, the server printed 87
error(SafeAllocator): leakedreports after the real error. They are the prompt-chunk set's 86 duplicated pipeline names and its 3,224-byte table.
The 26.3.1
KernelCompileitself is a separate problem; this change only releases what compiled before it.Verified outcome
kernel error, the server printed 87 memory-leak reports after the real error and buried the line that mattered.
the change and passes after it, and serving a checkpoint with a shard removed shows the same. Successful loads are
unchanged: the same tokens, exactness 60 of 60 and 10 of 10, and the same decode speed.
Receipt
mainat c7137bb, Zig 0.17.0, Xcode 27.0 (Metal 32023.921), Apple M4 (10-core GPU), 32 GB,macOS 27.0.1. Checkpoint
TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bitat d9d758f.a load that fails after its kernels compile releases them, in model.zig. It skips without a Metal device.It writes a Lightning config and an empty shard. On c7137bb it fails with
leaked 87 allocations. With this changeit passes.
cannot open .../model-00004-of-00004.safetensors,then
cannot load ... (OpenFailed), then 87 leak reports. On this branch: the same two lines and no leak reports.KernelCompile. A local build thatforces that path on 27.0.1 goes from 87 reports to 0 with this change.
tools/bench_concurrent.py --levels 1,4 --tokens 256 --reps 3 --temperatures 1.0,0 --alone --serialon this branch, serving with
--parallel 4: concurrent equals alone in 60 of 60 runs, and alone equals"draft": falsein 10 of 10. Nothing unequal or failed.tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0, run alternatelyon c7137bb and this branch, both reading one timing table: fibonacci-raw 48.1 and 47.9 tok/s before, 47.9 and 48.5
after; gpu-chat-no-think 46.7 and 47.2 before, 46.9 and 46.8 after. Token hashes are the same on both builds
(c91869ce1808, 5ef050084ac3). Without the shared table each build times its own at first load, since
cost_cache.keyhashes the executable, and six fresh timings alone moved fibonacci-raw between 46.5 and 50.9 tok/s.zig build test test-golden -Dcpu=apple_m1, uncached: 164 of 164 steps, 1983 of 1991 tests pass, 8 skip,0 fail (c7137bb: 1981 of 1989, 8 skip). The two more are the new test and draft_ids.zig's test, which the engine's
test binary now reaches through model.zig.
zig build fuzz-cortheonpasses.zig fmt --check build.zig zigisclean. Lean: 527 problems on the base and 527 on this branch, 0 new (
lean_new.py).cuda_engine.zigand does not useModel.load. Only an M4here.
Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Resumedagainst fresh was not re-run: only a load that fails runs the new code.)