Sign in

    soehi/gguf/tensor does not have a README file

    TensorError

    pub(all) suberror TensorError {
    UnknownType(type_id~ : Int)
    UnsupportedType(type_id~ : Int, name~ : String)
    NegativeLength(n_elems~ : Int64)
    NotBlockAligned(n_elems~ : Int64, block_size~ : Int)
    LengthOverflow(n_elems~ : Int64)
    BufferTooSmall(offset~ : Int64, needed~ : Int64, available~ : Int64)
    OutputTooSmall(out_offset~ : Int, n_elems~ : Int64, out_len~ : Int)
    } derive(Eq,
    Debug
    )

    Error type for tensor byte-size computation and dequantization.
    impl Show for TensorError

    TensorError::message

    fn TensorError::message(self : TensorError) -> String

    Human-readable rendering of a TensorError, including the offending offset or type id where one applies.

    GgmlType

    pub(all) struct GgmlType {
    id : Int
    name : String
    block_size : Int
    type_size : Int
    } derive(Eq,
    Debug
    )

    A ggml tensor storage type as it appears in a GGUF tensor info.

    block_size is the number of elements covered by one on-disk block, or 1 for types stored element-by-element. type_size is the on-disk byte size of one block, or of one element when block_size is 1.

    Types whose ids were removed from the format (q4_2, q4_3, the repacked q4_0_4_4 variants, the repacked iq4_nl variants) are still listed by name so that a tensor directory parses, but report block_size 0 and cannot be sized or dequantized.

    GgmlType::from_id

    fn GgmlType::from_id(id : Int) -> GgmlType

    Look up a ggml type by its on-disk id.

    Unknown ids yield a type with block_size 0 whose name records the id, so callers can report "unknown type N" without guessing a layout.

    GgmlType::is_dequantizable

    fn GgmlType::is_dequantizable(self : GgmlType) -> Bool

    Whether this build can dequantize the type.

    Covers f32, f16, q4_0, q5_0, q8_0, q4_K and q6_K. Everything else is parsed and sized correctly but rejected on dequantization with a named error.

    GgmlType::is_known

    fn GgmlType::is_known(self : GgmlType) -> Bool

    Whether the id maps to a real storage layout rather than unknown or a removed type.

    GgmlType::is_quantized

    fn GgmlType::is_quantized(self : GgmlType) -> Bool

    Whether the type packs several elements into one block (i.e. is quantized).

    GgmlType::nbytes

    fn GgmlType::nbytes(self : GgmlType, n_elems : Int64) -> Result[Int64, TensorError]

    On-disk byte size of n_elems elements of this type.

    Mirrors ggml_nbytes() for a contiguous tensor: n_elems / block_size blocks times the per-block byte size. Element counts that do not fill whole blocks are rejected rather than rounded, because a real GGUF never contains them and silently truncating would misreport the data section.

    bf16_to_float

    fn bf16_to_float(v : Int) -> Float

    Decode a bf16 value; exposed for the CLI's eventual bf16 model support.

    dequant

    fn dequant(buf : Bytes, offset : Int64, ty : GgmlType, n_elems : Int64) -> Result[Array[Float], TensorError]

    Dequantize into a freshly allocated Array[Float].

    Convenience for callers that want the values and not the buffer — the CLI and the golden tests. The engine will prefer dequant_into with a reusable working buffer so that per-token decoding allocates nothing.

    dequant_by_id

    fn dequant_by_id(buf : Bytes, offset : Int64, type_id : Int, n_elems : Int64) -> Result[Array[Float], TensorError]

    Dequantize n_elems values of an arbitrary type into a new array.

    Same as dequant, but takes a raw id so the CLI can pass a directory entry straight through.

    dequant_into

    fn dequant_into(buf : Bytes, offset : Int64, ty : GgmlType, n_elems : Int64, out : FixedArray[Float], out_offset : Int) -> Result[Unit, TensorError]

    Dequantize n_elems elements of type ty from buf[offset:] into out, starting at out_offset.

    Reads are bounds-checked against buf.length() before the first block is touched; a short or misaligned source region fails with BufferTooSmall rather than reading past the end. The caller owns all storage, so no intermediate allocation happens per element.

    ggml_type_count

    let ggml_type_count : Int

    Total number of ids in the ggml type enum (GGML_TYPE_COUNT).

    half_to_float

    fn half_to_float(bits : Int) -> Float

    Decode an f16 half-precision bit pattern; exposed for tests and the CLI.