Skip to content

[enhancement]: Cheaper GGUF header reads for large-vocabulary encoders #9986

Open

Description

@Pfannkuchensack

What should this feature add?

Reading a GGUF header is expensive for large-vocabulary encoders, and the same header is parsed several times per install and per load.

Cost per open (gguf-py GGUFReader, which builds a numpy view per array element, ~1M of them for a 256k vocabulary):

File Header parse
city96 UMT5-XXL Q8_0 ~10 s
Qwen2.5-VL-7B ~6 s
T5 v1.1, 32k vocab ~3 s

Opens:

WrappedGGUFReader.close() calls gc.collect() on every read, which shows up on loads under the model-load lock. A reviewer measured at the existing call sites that the caller's with … as reader binding keeps the reader alive until return. So the collect can't release the memmap early; the map is released on return anyway.

Proposals, independent of each other:

  1. A header reader that skips array payloads, or reads them lazily. This helps every large-vocabulary GGUF encoder.
  2. Let ModelOnDisk fill its metadata cache from the reader that load_state_dict already opens, saving one parse per GGUF identification.
  3. Drop the gc.collect() from WrappedGGUFReader.close() if it is confirmed unnecessary on Windows.
  4. Once feat(wan): load the UMT5 text encoder from GGUF builds #9967 has landed, read the qwen2vl.context_length check in feat(qwen-image): load the Qwen2.5-VL text encoder from GGUF builds #9969's config from mod.metadata() instead of a second reader.
  5. Once feat(anima): load the Anima transformer from GGUF builds #9970 has landed, size stable-diffusion.cpp whole-pipeline SD 3 GGUFs (feat(sd3): load SD 3.5 transformers from GGUF builds #9972) by their transformer tensors via gguf_tensor_bytes, as Anima all-in-one files are.

Additional Content

Collected from the reviews of #9967, #9969, #9970 and #9972.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions