Skip to main content

Module cast

Module cast 

Source
Expand description

Canonical dtype casting for GGUF conversion: {F32, F16, BF16} sources to any writable GGMLType, including Q8_0 block quantization. Bit-for-bit the same math as the per-model converters (which predate this crate and keep their own verified copies).

Enums§

SrcDtype
Source dtype of raw checkpoint tensor bytes.

Functions§

cast_data
Cast raw little-endian tensor bytes from src to dst.
cast_with_q8_fallback
Cast with automatic Q8_0 fallback. Returns (bytes, actual_dtype, fell_back).
decode_to_f32
Decode raw bytes of src dtype into f32 values (exact for all three sources).
f16_to_f32
f32_to_bf16_bits
Round-to-nearest-even F32→BF16 with NaN preservation.
f32_to_bytes
f32_to_f16_bits
q8_dst_or_fallback
Q8_0 block-quantization fallback: tensors whose innermost dim or total element count is not a multiple of 32 stay F32. Centralizes the innermost % 32 check duplicated in generic.rs, the Python write_generic_gguf, and every per-model convert.rs.
quantize_q8_0