Repository navigation
Studio: walk each GGUF tokenizer array once per process and seek past it on later reads - #15687
Conversation
…of a read and seek per entry
… can seek back [skip ci]
# Conflicts: # studio/backend/utils/models/gguf_metadata.py
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Follow-up to #15593 (buffered GGUF string walks, merged).
A cold local GGUF load reads the header many times before llama-server starts:
_read_gguf_metadataruns for the route preflight, the diffusion check, the non-chat refusal check and the real read, and_gguf_scan_tensor_bytesplus eachgguf_metadatareader (general, chat template, nextn, embedding length, staged dims, MTP standalone, mrope, TTS) walks the same tokenizer arrays again. With #15593 each walk is buffered, but there are still 23 to 36 walks of 150k to 262k entries per file. This PR walks each array once per process and replays later walks of the same unchanged file as one seek.What changes
utils/models/gguf_metadata.py:skip_gguf_stringsandtake_gguf_strings_by_first_byteget a small memo in front of the unchanged walks. A hit seeks to the remembered end and returns the remembered count (and, fortake, a new list of the remembered entries).(st_dev, st_ino, st_size, st_mtime_ns, st_ctime_ns)fromos.fstaton the open file, plus the start offset, the entry count and the kind of walk. A finishedtakealso answers askipof the same array, since every entry was whole and at most 1 MiB.open(path, "rb")take part.BytesIO, wrappers, pipes and streams that cannot seek back never do.fstatafter the walk differs from before it (written during the walk), or when the kept entries of atakeexceed 1 MiB. Growing files (downloads) change size and are recent.take, and its kept entries are tens of KB.Results
Fresh process per sample, running the readers of a cold local load in order (4x
_read_gguf_metadata,_gguf_scan_tensor_bytes, 8gguf_metadatareaders), base = #15593 head, interleaved, n=8 per arm. Walk counts and bytes read are deterministic.Base and head ranges do not overlap for any file. A separate rerun of the Qwen3-0.6B row (3 rounds per arm) gave 543 to 575 ms vs 93 to 140 ms, with the same 23 -> 2 walks and 66.9 MB -> 9.0 MB read.
Equivalence: 60 real GGUF headers plus 300 fuzzed ones (chunk straddles, entries over 1 MiB, corrupt lengths, truncation, invalid UTF-8) through 18 reader entry points, comparing return values, exception type and message and the final
tell()on files andBytesIO: 17,736 checks, 0 differences, with the memo warm across readers. Calling every reader three times on a warm memo also gives 0 differences. Python 3.9, 3.10, 3.11, 3.12 and 3.14: 0 mismatches.Tests
tests/test_gguf_walk_memo.py(20): a hit reads no entries and equals a fresh walk; a finished take answers the skip; hits return a new list; offset and count are part of the key; a same-size rewrite with the old mtime restored, a rename over the file with the old mtime, an in-place rewrite where ctime is the creation time (as on Windows), a recently changed file, a growing file, inode 0, a change during the walk andBytesIOare all walked again; the LRU bound and the 1 MiB kept cap hold; 8 threads agree; the llama reader and the metadata readers share one walk. Base (Studio: walk GGUF tokenizer string arrays through one buffer #15593 head, test copied in): 2 failed, 12 errors. This PR: 20 passed.test_gguf_string_walk.py,test_gguf_metadata.py,test_gguf_header_delta.py,test_gguf_admission_token_count.py,test_gguf_image_capability.py,test_gguf_metadata_log_volume.py: all pass on both base and this PR.Not covered
os.fstat,stat.S_ISREG,time.time_ns) with no OS branches.st_ctimeis the creation time, so a rewrite in place that keeps the same size and also restores the exact old mtime (to 100 ns) would not be seen until the process restarts. A rename or copy over the file changes the file index, and any normal write moves mtime. The existing metadata caches in this module trust the same fields.