Hibari // Architecture

Architecture

A LLaMA-style decoder written from first principles

These diagrams show Koto 1.3.1 exactly as it is implemented in src/hibari/model/. The same code builds any size; Koto 1.1.x is the same structure at 6.2M parameters.

Model source →Design document →

Specification

Koto 1.3.1 vs 1.1.x
Koto 1.3.1 (current)Koto 1.1.x
TypeDecoder-only causal Transformer (LLaMA-style)same
Parameters29,368,8326,163,712
Blocks × width8 × 5126 × 256
Attention8 heads × 64, full multi-head, no biases8 heads × 32
Feed-forwardSwiGLU, d_ff 1536SwiGLU, d_ff 768
Normalisationpre-RMSNorm, ε = 1e-5same
PositionsRoPE, θ = 10,000, adjacent-pair rotationsame
Regularisationresidual dropout 0.1none
Context256 tokenssame
Vocabulary4,096 byte-level BPE tokens, 7 chat specialssame
Output headtied to the token embeddingsame

1 · End to end

Overall architecture
Overall architecture
The conversation is formatted with the chat template (<|system|>, <|user|>, <|assistant|>, end of turn <|eos|>), tokenised, embedded, passed through 8 blocks and a final RMSNorm, and projected to 4,096 logits. A token is sampled and fed back with the KV cache, so the prompt is processed once. The diagrams were drawn for the 29.4M architecture shared by 1.3.0 and 1.3.1; 1.3.1 additionally uses residual dropout 0.1 during training (the diagram's “Dropout 0.0” is the attention dropout, unchanged).

2 · One Transformer block

Pre-norm residual block
Transformer block
h = x + Attention(RMSNorm(x)); y = h + SwiGLU(RMSNorm(h)).

Each block normalises before each sub-layer and adds the result back to the residual stream. Pre-norm keeps training stable without warm-up tricks.

SwiGLU: down(silu(gate(x)) · up(x)), three bias-free projections with hidden size 1536.

Residual dropout (new in engine 0.4.1) drops 10% of each sub-layer output during training only; it adds no parameters, so checkpoints and GGUFs are unaffected.

3 · Attention

Multi-head causal self-attention
Multi-head causal attention with RoPE and KV cache
Bias-free Q/K/V, RoPE on Q and K, KV cache, scaled dot-product with a causal mask.

RoPE rotates adjacent pairs of each query and key by a position-dependent angle (θ = 10,000), so attention depends on relative position. This is exactly llama.cpp's ROPE_TYPE_NORM, so the weights are exported unpermuted.

KV cache: during generation each new token attends to the cached keys and values; tests check that this equals re-running the full sequence.

Causality is tested directly: changing token j never changes the logits before j.

4 · Embedding and output

Tied weights
Token embedding and tied output projection
logits = h · Eᵀ — the output head reuses the embedding matrix.

The 4,096 × 512 embedding matrix is used twice: to look tokens up and, transposed, to score the next token. Tying saves 2.1M parameters and the GGUF omits output.weight.

Tokenizer: byte-level BPE trained for Koto, with 7 special tokens. Text a user types that looks like a special token (<|assistant|>) is escaped, so a user cannot forge turns.

5 · The application layer

Python engine only
#StageWhat it does
1Safety layerSelf-harm, violent intent and harmful-instruction requests get a fixed, reviewed response; the model is not called.
2Task routerRewriting requests (rephrase, correct grammar, formal, casual, polite, shorten, simplify) are sent in the exact form used in training.
3NormalisationChat shorthand (u, r, wat, thx) is expanded for the model only; safety and routing see the original text.
4Candidates + criticSeveral replies are sampled in one batched pass; a transparent critic ranks them (fluency, relevance, named appropriateness rules). It never writes text.
5CleaningChat markers removed, emojis capped, an unfinished last sentence trimmed. Nothing is added.

These stages live in the Python engine. A GGUF run in llama.cpp or Ollama returns the raw model's reply without them.

6 · GGUF export and parity

llama.cpp + Ollama
VariantSizeSame greedy reply as PyTorch (11 prompts)
F32112.2 MiB11/11
F1656.2 MiB11/11
Q8_029.9 MiB11/11
Q4_K_M17.5 MiB9/11

The exporter writes the llama GGUF architecture with the full tokenizer and chat template, plus hibari.* provenance metadata (model and weights version, checkpoint and tokenizer SHA-256). A NumPy reference runtime that reads only the GGUF reproduces the PyTorch logits.