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.
- Model
Summary - 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.
openandstopare called from concurrent shard readers (SHARD_READS). - Tensor
- One tensor, as a header describes it.
- Type
Share - One dtype’s share of a model.
Enums§
- Meta
Value - One metadata value, as the Model tab shows it.
- Model
Kind - Which of the two formats a model file is.
- Range
Error - 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 (seea_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§
- Range
Source - 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;
namesare their files. - detail
- The Model tab: the model’s totals, then its metadata as key and value, every value whole.
- is_
safetensors_ index - Whether
pathis 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 holdslenbytes in all. - read_
header_ ranged - Read one model header from
srcwith ranged requests: SafeTensors’ firstFIRST_SAFETENSORS_RANGEplus any remaining JSON; GGUF in growing ranges until the tensor infos end. File-reader bounds all hold;stopis checked before each request. - read_
header_ ranged_ from - As
read_header_rangedwith first rangefirst(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 afilecolumn 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, asread_modeldoes on disk.RangeError::NoRangesonly for one standalone file (downloadable instead). - read_
safetensors - Read one SafeTensors header from
reader, which holdslenbytes 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.
- Open
Ranges - A ranged source for a URL.