Train a causal byte language model
Create distinct document partitions, train a native decoder, evaluate, save, resume and generate exact token IDs.
// Native document-preserving byte language-model research workflow.
// Use new checkpoint/tokenizer paths for each experiment.
import aner.token
import aner.gen
import aner.dev
let codec = token.byte_tokenizer()
let training = token.corpus(codec, List(
"abababababababab", "babababababababa"), role: "training")
let validation = token.corpus(codec, List(
"abababababababa", "bababababababab"), role: "validation")
let initial = gen.decoder(codec, context: 24, width: 8,
heads: 2, layers: 1, seed: 63, dropout: 0.0)
print(gen.baseline())
print("Initial validation loss")
print(initial.loss(validation))
let partial = initial.train(training, steps: 90, batch: 2, rate: 0.01, seed: 99,
clip_norm: 1.0, warmup_steps: 0, weight_decay: 0.0)
codec.save("byte.anertoken")
partial.save("byte-partial.anergen")
let restored = gen.load("byte-partial.anergen")
let model = restored.resume(training, steps: 90)
print(model.summary())
print("Training loss")
print(model.loss(training))
print("Validation loss")
print(model.loss(validation))
print("Validation perplexity")
print(model.perplexity(validation))
dev.capture("Native language model", model)
let prompt = codec.encode("ab", bos: true, eos: false)
let continuation = model.generate(prompt, max_new_tokens: 8,
temperature: 0.0, top_k: 0, top_p: 1.0, seed: 7)
// Byte generation can end inside a UTF-8 sequence; Bytes is always reversible.
print(codec.decode_bytes(continuation, skip_special: true).hex())
model.save("byte-trained.anergen")
Make it your experiment.
With a compatible development runtime installed, save this program as examples/generative_byte_llm.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/generative_byte_llm.aner
aner run examples/generative_byte_llm.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Use a compatible current native Aner development runtime with aner.token, aner.gen and sequence primitives. CPU supports Float64 and Float32; native Metal/MPS sequence kernels require Float32 and a compatible build. CUDA sequence kernels are not implemented. Run checkpoint examples from a fresh working directory because existing artifacts are never replaced. These local synthetic examples require no model provider, credentials or network connection. The runtime and VS Code extension remain development software without public downloads.
Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution