Import and adapt a bounded GPT 2 fixture
Import a separately prepared local GPT2LMHeadModel with its exact tokenizer, inspect memory and fine tune native LoRA factors without downloading weights.
// Prepare the four pinned safe files under models/tiny-gpt2 as documented.
// This tiny checkpoint verifies interoperability; it is not a quality benchmark.
import aner.token
import aner.gen
import aner.nn
nn.configure("cpu", "Float64", "preserve")
let model = gen.import_gpt2("models/tiny-gpt2", context: 8)
let codec = model.tokenizer()
print(model.summary())
print(model.memory_summary(batch: 1, length: 8, training: true))
let prompt = codec.encode("Hello world", bos: false, eos: false)
let output = model.generate(prompt, max_new_tokens: 3,
temperature: 0.0, top_k: 0, top_p: 1.0, seed: 7)
print(codec.decode(output, skip_special: true))
let adaptation = token.corpus(codec, List("Hello science", "Scientific work"), role: "training")
let adapted = model.lora(List("block.0.qkv", "block.1.attention.output"),
rank: 2, alpha: 4.0, seed: 23)
let tuned = adapted.fine_tune(adaptation, steps: 3, batch: 1, rate: 0.001, seed: 71)
tuned.save("imported-gpt2-lora.anergen")
print(tuned.loss(adaptation))
Make it your experiment.
With a compatible development runtime installed, save this program as examples/generative_pretrained_gpt2.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/generative_pretrained_gpt2.aner
aner run examples/generative_pretrained_gpt2.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 the bounded GPT2LMHeadModel importer. Before running, prepare the separately obtained compatible config.json, model.safetensors, vocab.json and merges.txt under models/tiny-gpt2 beneath the working directory. This example does not download weights or supply a pretrained model. Full sized GPT 2 exceeds current parameter limits; the guide defines the supported small fixture and numerical conventions. Run from a fresh working directory for the new imported gpt2 lora.anergen checkpoint. The declared execution is CPU Float64 and requires no model service or credentials. 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