Skip to main content

Module tensor_roles

Module tensor_roles 

Source
Expand description

Task #12 / STELLAR §A — tensor-name → engine GEMM-role mapping + the ternary policy.

The transcoder (p64_weight) needs to know what each tensor is to (a) populate the P64 manifest with real engine roles (so a container boots without a GGUF re-parse) and (b) apply the §A compression policy: ternary the FFN projections, keep attention + norms + embeddings at higher fidelity (ternary norms/attention would wreck coherence).

Two naming conventions are recognised:

  • GGUF / llama.cppblk.{L}.attn_q.weight, blk.{L}.ffn_gate.weight, token_embd.weight, …
  • Hugging Face safetensormodel.layers.{L}.self_attn.q_proj.weight, model.layers.{L}.mlp.gate_proj.weight, model.embed_tokens.weight, lm_head.weight, …

Structs§

TensorRole
A resolved tensor identity: an engine role + its layer (P64_LAYER_GLOBAL for non-layer tensors).

Functions§

name_is_ternary_eligible
True iff this tensor name resolves to an FFN projection (so it is ternary-eligible). A name we cannot classify is not ternarised (fail safe to high fidelity).
name_to_role
Map a tensor name (GGUF or HF convention) to its engine role + layer, or None if unrecognised.
ternary_eligible
The §A ternary policy: only the FFN projection weights (gate / up / down) are eligible for BitNet-1.58b ternary packing. Attention projections, norms, and embeddings stay at higher fidelity — ternarising them destroys coherence.