This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · lib/gguf/tensors

Reading a GGUF file, part 2, the tensor table

After the metadata comes one entry per tensor (docs/gguf.md, struct gguf_tensor_info_t, in ggml at commit 3612c0af93f2; a rewrite, MIT, The ggml authors):

name    a string
n_dims  u32
dims    n_dims u64s, the fastest-varying first: a matrix of R rows of
        C numbers is [C, R]
type    u32, a ggml_type: F32, F16, Q4_0, ...
offset  u64, where the tensor's bytes start, from the data section

Then padding up to a multiple of the alignment (the key general.alignment, 32 when absent), and the data section. Each tensor's offset is a multiple of the alignment too. A tensor of type t holds blocks of BLOCK_ELEMS[t] numbers in BLOCK_BYTES[t] bytes each, so its size is n_elems / BLOCK_ELEMS[t] * BLOCK_BYTES[t].

Used with from gguf.tensors import read_gguf (and the other names here).

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

This program declares a record type (Tensor), and records run only in compiled C for now, so the Run buttons here are off. Open it in the workbench and use its C tab to compile it.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 25–225