Skip to main content

Module model_files

Module model_files 

Source
Expand description

SafeTensors and GGUF model files as a table of their tensors. Only the header is read, so a 70 GB checkpoint opens like a 7 MB one. Both parsers are hand-written over a bounded reader, checking every stated length before allocating or skipping, so a hostile header errors rather than allocating gigabytes or panicking. Rows are a small eager frame made lazy; metadata and totals go to a ModelSummary for Info’s Model tab.

Structs§

Header
One file’s header.
ModelSummary
What a model’s header says beyond its tensors, and their totals.
Remote
How a remote model’s files are reached: a source per URL and sibling file URLs. open and stop are called from concurrent shard readers (SHARD_READS).
Tensor
One tensor, as a header describes it.
TypeShare
One dtype’s share of a model.

Enums§

MetaValue
One metadata value, as the Model tab shows it.
ModelKind
Which of the two formats a model file is.
RangeError
Why a ranged read stopped.

Constants§

FIRST_GGUF_RANGE
The first GGUF header read; each next is twice the last up to MAX_RANGE, so a few KB costs one request and a 5-10 MB vocabulary four or five (see a_vocabulary_sized_gguf_header_takes_a_few_ranges).
FIRST_SAFETENSORS_RANGE
The first SafeTensors read: the header length and usually all its JSON (shard headers are KB to tens of KB); longer takes one more request.
MAX_SAFETENSORS_HEADER
The largest SafeTensors header read: the limit the reference implementation sets.
SHARD_READS
Shard headers read at once: hundreds of shards one at a time add up to minutes; a few at once gets most of the gain without a burst.

Traits§

RangeSource
Bytes of one remote object, fetched a range at a time: an HTTP server, or an object in a store.

Functions§

build
The table and the summary for headers already read; names are their files.
detail
The Model tab: the model’s totals, then its metadata as key and value, every value whole.
is_safetensors_index
Whether path is a SafeTensors index: model.safetensors.index.json.
looks_like_gguf
Whether the first bytes of a file are GGUF’s magic.
looks_like_safetensors
Whether the first bytes of a file are a SafeTensors header: a little-endian length a header could have, then the { that opens its JSON.
read_gguf
Read one GGUF header (versions 2 and 3, either byte order) from reader, which holds len bytes in all.
read_header_ranged
Read one model header from src with ranged requests: SafeTensors’ first FIRST_SAFETENSORS_RANGE plus any remaining JSON; GGUF in growing ranges until the tensor infos end. File-reader bounds all hold; stop is checked before each request.
read_header_ranged_from
As read_header_ranged with first range first (at least 8 bytes): small for the fuzz target and tests, to cross many ranges.
read_model
Read paths — model files, or SafeTensors indexes that name them — as one table of tensors, with a file column when there is more than one file.
read_remote_model
Read urls (remote model files, or SafeTensors indexes naming them) as one tensor table, fetching only headers, as read_model does on disk. RangeError::NoRanges only for one standalone file (downloadable instead).
read_safetensors
Read one SafeTensors header from reader, which holds len bytes in all.
url_file_name
The last segment of a URL, without a query: what a file’s row and its errors call it.

Type Aliases§

Metadata
Metadata as key and value, in the order the file has them.
OpenRanges
A ranged source for a URL.