Open Source // LLM Engine Built From Scratch

Hibari

An LLM engine written from first principles in PyTorch — and Koto, the conversational model built with it

Every part of Hibari is written directly: the Transformer, the byte-level BPE tokenizer, the training loop, KV-cache inference, a safety layer, a reply critic and a native GGUF exporter. No pretrained weights and no high-level model library are used. Its first model, Koto, lives in its own repository as a Git submodule of Hibari; the current release is Hibari-Koto1.3.1:29M.

Hibari on GitHub →Koto on GitHub →Hugging Face →Ollama →← Back to Projects
Run Koto in one line
ollama run kavimugil-r/Hibari-Koto1.3.1:29M
PyTorchFrom scratchGGUF llama.cppOllamaHugging Face

What Hibari is

The engine and its name
Hibari logo

Hibari (雲雀, Japanese for the skylark) is a research project to build a language model the long way: every layer is written and tested in this repository instead of being imported. The goal is understanding — a small model whose every number can be traced to the code, data and run that produced it.

The engine is deliberately model-agnostic: sizes come from a config file, and a model lives in its own repository. Koto is the first one; a release binds its checkpoint, tokenizer and GGUF files together by SHA-256, so a published file can always be traced back to its training run.

Author: Kavimugil Rajasekar · MIT licence · started 2026

Koto 1.3.1 at a glance

Current release
Parameters
29,368,832
Layers / width
8 × 512
Context
256 tokens
Vocabulary
4,096 BPE
Best val loss
2.781
Training
1.72 h, 1 GPU

Compared with the previous release (1.1.1, 6.2M parameters), 1.3.1 is better at following a conversation (conversation suite 0.645 → 0.733) and weaker at rewriting text (behaviour suite 0.660 → 0.628). All results →

Two repositories, one direction

Engine + submodule model
Engine

Hibari

A reusable, model-agnostic Python package (hibari) that can build, train, run, evaluate and export any model of this architecture. It never imports a model.

github.com/KavimugilRajasekar/Hibari · engine 0.4.1 · 418 tests

Model · Git submodule models/Koto

Koto

One concrete model: configs, tokenizer, data recipes, training runs, evaluation suites, experiment records and release files. Koto imports Hibari and only uses it.

github.com/KavimugilRajasekar/Koto · release 1.3.1 · 87 tests

git clone --recurse-submodules https://github.com/KavimugilRajasekar/Hibari.git
Hibari/                    engine: src/hibari, scripts/engine, tests, Docs
└── models/Koto/           submodule: configs, tokenizer, koto/ data + evaluation,
                           training/, experiments/, releases/, docs/

dependency:  Koto ──uses──▶ Hibari      (never the other way)

Architecture

How a reply is produced
Hibari Koto overall architecture
Chat turns → byte-level BPE tokenizer → token embedding → 8 pre-norm Transformer blocks → final RMSNorm → tied LM head → sampling, repeated token by token. 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). Every component explained →

Inside the engine

One package per responsibility
LayerPackageWhat it does
Modelhibari.modelDecoder-only Transformer: token embedding, RoPE, multi-head causal attention with KV cache, SwiGLU, pre-RMSNorm, tied output head, residual dropout
Tokenizerhibari.data.tokenizerByte-level BPE (4,096 tokens), chat template, escaping of special-token text typed by users
Datahibari.dataConversation formatting, windowing that never cuts a reply, assistant-only loss masking, length-grouped batching
Traininghibari.trainingAdamW with warm-up + cosine schedule, token-weighted gradient accumulation, resume, checkpoint provenance
Inferencehibari.inferenceBatched KV-cache sampling, streaming, chat session with context trimming, rewriting-task router, informal-text normalisation
Safety & rankingsafety · rerankingDeterministic safety layer with reviewed responses; a critic that ranks several model-written replies (it never writes text)
Exporthibari.exportNative GGUF writer (F32 / F16, then Q8_0 / Q4_K_M via llama.cpp) and a NumPy reference runtime that reads only the GGUF
Releasehibari.releaseRelease profiles that bind version, weights, tokenizer and GGUFs by SHA-256; validator; generated Ollama Modelfile

Links

Everything in one place