Skip to main content

Module weight_file

Module weight_file 

Source
Expand description

Minimal P64-style learned-head weight blob format + bounded parser (AU-LEARNED).

This is the on-disk container every learned audio head loads from. It is deliberately tiny and self-describing: a magic tag, a format version, a small dims shape vector, and a flat f32 payload. Real weights are gated on the principal (HA1 corpus / HA6 model); the format here lets us (a) round-trip a synthetic/test blob and (b) fail closed when a blob is absent or malformed. Parsing is cold (a Vec is allowed); inference over the parsed blob is the hot, caller-buffered path and lives in the head modules.

Wire layout (all little-endian):

  magic   : u32   = "QP64"
  version : u32
  ndims   : u32   (<= MAX_DIMS)
  dims    : [u32; ndims]
  ndata   : u32   (<= MAX_DATA)
  data    : [f32; ndata]

The parser requires the byte slice to end exactly after data — trailing bytes are rejected, so a truncated or padded blob cannot be silently accepted.

Structs§

WeightBlob
A parsed learned-head weight blob. Cold-path owned (Vec); heads borrow it during inference.

Constants§

MAX_DATA
Upper bound on data length in f32 elements (~4M floats = 16 MiB; bounds parsing).
MAX_DIMS
Upper bound on dims length (bounds parsing; a shape vector is always tiny).
WEIGHT_MAGIC
Blob magic: QP64 little-endian.
WEIGHT_VERSION
Current blob format version.

Functions§

make_blob
Convenience: build a well-formed blob with the current magic/version.
parse_weight_blob
Parse a weight blob from bytes. Bounded and strict: unknown magic → BackendUnavailable (treated as “no usable weights” so the head fails closed); any structural problem (short read, oversized counts, trailing bytes) → MalformedAudio. Never partially accepts.
write_weight_blob
Serialize a weight blob (cold path — tests and fixture generation). Inverse of parse_weight_blob.