Repository navigation
core: TF_LOAD_PREFETCH; Gemma 4 and Qwen 3.5 CUDA read each layer ahead while it packs - #1928
Conversation
|
Thanks @jschmied. We reviewed this independently, and it's safe. Readers only |
|
Thanks @ashhart. Done in 2737e5f: the per-layer |
|
Thanks @jschmied: all three asks are answered in 2737e5f. The per-layer release is deferred while readers are open, |
|
Thanks @jschmied. GB10 A/B of
With the earlier re-review's LAND, this is queued to land. |
…ayer ahead while it packs, its pages released after
…ad, so TF_LOAD_PREFETCH=0 is main's path
2737e5f to
b52ae7e
Compare
|
Thank you @jschmied. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
|
Thanks @jschmied! This is in TensorFold 1.2.2, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.2 |
Gemma 4 and Qwen 3.5 on CUDA load their layers one at a time: fault the mapped pages in, upload, pack, synchronize. The page faults run on the loading thread at about 1.4 GB/s buffered, so a cold load mostly waits on the disk. GLM already avoids this with
TF_GLM_LOAD_PREFETCH.This PR moves that knob into core and uses it for both families:
core/checkpoint_prefetch.zig:readerCount/configured()readTF_LOAD_PREFETCH. Unset now means on, with 16 readers (GLM's default).0is exactly main's path: no readers and no per-layer release, so pages are released once atcache.close. Anything up tomax_readerssets the count. Any other value now fails the load witherror.BadLoadPrefetch, where main ignored the variable. A test covers all four cases.core.checkpoint.loadReadersre-exports it.gemma4/cuda_weights.zigandqwen3_5/cuda_weights.zig: every layer'sCheckpoint.prefetch(prefix, readers)reads it into the page cache on its own threads while the loop uploads and packs it. When a layer was read ahead (readers > 0),release()drops its pages once it is on the device, so the page cache never holds more than about one layer.Cold load on a GB10 (page cache dropped before every start, NVMe; order main, branch, branch, main; the reply to a fixed greedy prompt is byte-identical in every run):
Checks: lean (0 new),
zig build test, the CI set and diff-check all pass on 2737e5f.A question before a follow-up: starting layer i+1's read while layer i packs (one-layer lookahead) takes this further, to 13/12 s for the 27B and 8/8 s for Gemma, close to the warm floor. Same replies. The catch is that the page release then can't be per layer:
release()drops a whole file, and the next layer's pages are already in it. So the cache would grow to the model's size untilcache.close. A clean fix is a range release in core (fadvise/madvise on one layer's byte span). Do you want that as a follow-up PR?