Repository navigation
Conversation
This was referenced Sep 29, 2026
Closed
Owner
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.
This is a set of changes targeting the initial startup/loading of models in TensorFold (trying to get it closer to the hardware I/O limits). It mostly involves better streaming of the data from disk, running the n-gram loading in parallel and offloading some of the packing into the GPU (off of the CPU).
This was heavily aided by Opus 5.5 and Astra 6 but I guided the specific changes and looked over the code after they both cross-reviewed it as well (though I did defer to Opus on the write-up below because it was a lot more diligent than I would have been in writing it up).
perf: 3–15× faster cold start on CUDA (every loader)
Cold starts on a DGX Spark were dominated by how checkpoints reach the GPU, not by the size of the models:
This PR reworks the load path of every CUDA family: Flash Next (MLX and EXL3), Qwen3.8-27B (MLX and EXL3, with DFlash2), Qwen3.6-35B, Nemotron, and GLM-5.3-Flash on two ranks. Every model gives the same greedy output as before, token for token.
Results
Time from
docker runto the first streamed token, on a cold page cache with the kernel cache warm. Baseline is TensorFold 0.3.6.2 (71377a5), and each result is on this branch.Vontra/Qwen3.8-Flash-Next-MLX-4bit-MTPturboderp/Qwen3.8-Flash-Next-exl3(3.05bpw_h5_ng5)Vontra/Qwen3.8-27B-MLX-4bitturboderp/Qwen3.8-27B-exl3(3.00bpw)Vontra/Qwen3.6-35B-A3B-MLX-4bit-MTPVontra/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit--tp 2, two Sparks)Vontra/GLM-5.3-Flash-MLX-4bit-MTPBefore: two cold starts each. After: one start on the final tree. Across repeated runs during development, results varied by about ±1 s.
Setup:
nvcr.io/nvidia/pytorch:26.07-py3: PyTorch 2.13, CUDA 13.3, Triton 3.7.1.POSIX_FADV_DONTNEEDbefore each start, with the GPU idle and ≥115 GiB available.How Flash Next MLX got there (146 s → 24 s), with the step each change was measured on:
empty_cache()every 8 layersHow GLM got there (341 s → 41 s):
empty_cache()every 8 layersWhat changed
1. Direct checkpoint reads:
tensorfold/cuda/direct_read.py(new)Readerreads byte ranges withO_DIRECTin 4 KiB-aligned spans of up to 64 MiB. Each span goes out as hundreds of requests in flight.O_DIRECTis refused: noos.O_DIRECT, orEINVALon the open or on a read. A read past the end of a truncated file raises instead of looping.SafeTensorsis a header index plus direct reads, and replacessafe_openin every CUDA loader: the 27B (MLX, EXL3 and the DFlash2 draft model), Qwen3.6's MTP tensors, and Nemotron. The Flash Next MLX reader and the EXL3 pack reader useReaderdirectly.safe_open(device="cpu")path went through the memory map at ~0.2 GB/s; it now reads at 1.6–5 GB/s.2. Read-ahead:
ReadAheadin the same moduletake()makes the caller's stream wait on the upload event and callsrecord_stream, so the allocator can't reuse the memory early.RankReaderqueues each layer's experts. Its row, column and dim1 splits run on the GPU (split_device), and pre-split rank folders use the same path. GLM's routed experts are ~2,300 small tensors a layer, so one-at-a-time reads had left the SSD mostly idle.3. Fused expert pack:
tensorfold/cuda/experts_pack.cu(new)experts.packregroups MLX 4-bit experts into the grouped kernels' blocks. It was an int64 per-nibble loop plus permute copies, about 40 elementwise passes.tensorfold_experts_v7, so it rebuilds once after upgrading, in about 30 s.4. GLM: experts stacked on the GPU
torch.stackon the CPU and then copied, single-threaded.5. Fewer device synchronizations
torch.cuda.empty_cache()runs every eighth layer instead of every layer, in Flash Next (MLX and EXL3), Nemotron and GLM. Each call waited for the GPU.6. The n-gram tables
mlockdirectly, which faulted 33 GB in one page at a time (28 s). The 8-thread prefetch now runs first, and the lock takes 0.4 s.Correctness
token_shabefore and after:1ab8fcf3894c, Flash Next EXL3c8ee64ccacb3;20f815d12e6d, 27B EXL3ff73a0b1628a;6df10f796821, Nemotron373fb6409cf4, GLMde5a23e55503.tests/test_direct_read.py(host, no GPU): direct and buffered reads againstsafe_open, unaligned tensors, truncated files, refusedO_DIRECT,ReadAhead.tests/cuda/test_direct_read_cuda.py: device reads; the Flash Next reader, direct and read-ahead; the fused pack against the original torch pack for both group sizes and non-contiguous inputs; the background-prefetch futures.tests/cuda/test_glm_split_and_policy.py: read-ahead in runs, GPU uploads, rank folders, and uploads consumed without synchronization.Notes for review
tensorfold/cuda/,families/*/cuda/).host_table.py, which the MLX path shares, is unchanged.split_filetool are unchanged.~/.cacheand~/.tritonacross containers, a RUNBOOK change, would address that.tests/test_cancellation.py::test_streaming_socket_disconnect_during_decode_releases_the_active_rowhangs on Linux with or without this change: itsrecvloop never ends once the server closes. The suite ran withpytest-timeout.