module

Semtrace::Safetensors

Minimal parser for the safetensors binary format.

Format: Bytes 0..7 : u64 LE — header size in bytes Bytes 8..8+N: JSON header — maps tensor names to {dtype, shape, data_offsets} Bytes 8+N.. : raw tensor data (offsets are relative to this point)

Class methods

read_header(path : String) : NamedTuple(header_size: Int64, tensors: Array(TensorInfo))

Parses the header of a safetensors file and returns tensor metadata.

Source
read_tensor_f32(path : String, tensor : TensorInfo) : Slice(Float32)

Reads a specific tensor's raw data as Float32 values. Supports F32 and F16 dtypes (F16 is converted to F32).

Source

Nested types