Browse documentation
aner.gen · Reference

Native pretrained training and deployment

Import supported floating dense Llama GGUF, fine tune full weights or LoRA on CPU, resume checkpoints and export local deployment artifacts.

Development APIs

These APIs require the matching development native runtime and optional capabilities. Published Aner 0.0.5 runtime packages and the published editor do not supply these additions. This documentation publishes no runtime, editor package or model weights. See release status and Downloads for separately verified artifacts.

This development feature completes a native local workflow: import a supported pretrained model, prepare explicit training/validation data, fine tune all weights or LoRA factors, checkpoint/resume, and deploy the result through llm.load. Existing service clients and bounded aner.gen models keep their own contracts.

The optional backend executes through LibTorch C++ inside the native runtime. Training calls launch no separate language runtime subprocess, download no model and do not enroll the computer in a network. Existing Ollama and cloud connections keep their provider contracts.

Supported initial profile

The first training profile is dense Llama GGUF with floating F32/F16/BF16 weights, RMSNorm, adjacent pair RoPE, SwiGLU, multihead/grouped-query attention, and optional tied token/output embeddings. Weights are imported into FP32 for native training. The first qualified training placement is CPU. Unsupported devices, quantized training weights, architecture variants, scaling rules or extra tensors fail explicitly. This is not QLoRA or arbitrary modern model compatibility.

GGUF carries the tokenizer and chat template used by both data preparation and deployment. Template execution uses the pinned engine's supported built in conventions; arbitrary Jinja execution or model supplied code is not performed. Native imports check tensor dimensions, names, finiteness, configuration and tokenizer identity. The new path is independent of the legacy one million parameter decoder limit. Actual size is governed by explicit admission estimates and host resources; this does not establish that a 14B model is practical to train locally.

End to end API

The CSV files below have question,answer headers and independently selected training and validation rows. Run in a fresh output directory because published artifacts do not overwrite existing files.

aner
import aner.gen
import aner.llm

let base = gen.import_model("models/base-f16.gguf", device: "cpu",
    max_memory_bytes: 4294967296)
let training = gen.supervised_csv(base, "training.csv", input: "question",
    target: "answer", role: "training", context: 128)
let validation = gen.supervised_csv(base, "validation.csv", input: "question",
    target: "answer", role: "validation", context: 128)

// Default LoRA selects every supported query/value attention projection.
let adapted = base.lora()
let tuned = adapted.fine_tune(training, validation, steps: 20,
    micro_batch: 1, accumulation: 4, rate: 0.0002, seed: 71)
print(tuned.validation_loss())
tuned.checkpoint("checkpoint-20")

let restored = gen.load_pretrained_checkpoint("checkpoint-20", device: "cpu",
    max_memory_bytes: 4294967296)
let continued = restored.resume(training, validation, steps: 10)
continued.save_model("domain-f32.gguf")
gen.quantize_model("domain-f32.gguf", "domain-q4.gguf", format: "q4_0")
let adapter_manifest = continued.save_adapter("domain-adapter")

let native = llm.load("models/base-f16.gguf", context: 128, device: "cpu")
let specialized = native.with_adapter(adapter_manifest)
let answer = specialized.generate("Explain this observation.", max_tokens: 32)
print(answer.text())
specialized.close()
native.close()

To fine tune the full model, call base.fine_tune(...) directly. Source handles remain unchanged. Model states are immutable; training owns a private mutable state for its duration and publishes the resulting model after a coherent update. The initial language API is synchronous. Long work can be divided into bounded fine_tune/resume calls with explicit checkpoints between calls. Existing TrainingJob asynchronous APIs continue to apply to their bounded native models; they are not silently reinterpreted as modern training jobs.

Methods and explicit controls

OperationContract
gen.training_available()Query the optional native training build capability.
gen.training_backend()Inspect the numerical backend/version/build identity.
gen.import_model(path[, device[, max_memory_bytes]])Load a supported trainable floating GGUF; defaults CPU and 4 GiB estimated budget.
gen.supervised_csv(model,path,input,target,role,context)Immutable masked supervised examples from explicit CSV columns.
gen.causal_text(model,documents,role,context)Document bounded causal next token examples.
model.parameter_names()Inspect exact registered GGUF weight names.
model.trainable_parameters()Inspect the currently selected weights or factors.
model.lora()Freeze the base and create rank 8, alpha 16 query/value adapters.
model.lora(targets[,rank,alpha,seed])Select supported named projections and explicit factor configuration.
model.fine_tune(training,validation,steps,micro_batch,accumulation,rate,seed[,clip_norm,weight_decay])Start a new optimizer run from the supplied weights/factors.
model.checkpoint(directory)Save a standalone resumable package to a new directory.
gen.load_pretrained_checkpoint(directory[,device[,max_memory_bytes]])Validate and reconstruct the complete supported training state.
model.resume(training,validation,steps)Continue exact compatible optimizer/data progression.
model.save_model(path)Publish merged F32 GGUF deployment weights and a provenance sidecar.
model.save_adapter(directory)Publish GGUF factors and return the exact base manifest path for with_adapter.
gen.quantize_model(source,output,format[,max_memory_bytes])Publish deployment only q4_0 or f16 GGUF from floating weights; default admission 2 GiB. Requantization is refused.
model.loss(data)Compute actual loss bearing token weighted loss.
model.steps(), model.trained_tokens()Read committed optimizer updates and actual scored training tokens.
model.summary(), model.memory_summary()Inspect configuration, lineage and accounting scope.

Named arguments use the labels shown. Receiver methods correspond to module operations prefixed gen.pretrained_; dataset methods use gen.training_data_. Optional backend absence is a runtime capability error, not a cloud fallback.

Data, loss and evaluation

CSV supervised data renders the model's admitted chat format. Input and generation prefix tokens are excluded from loss; assistant-response/suffix tokens are scored. Preparation requires an exact token prefix alignment and rejects unsupported boundary behavior. Empty targets, malformed CSV, invalid roles, incompatible tokenizers and examples exceeding context fail instead of being silently repaired.

Training accepts only training role data. Validation rejects exact content present in the current training set or known inherited training lineage. These checks do not detect paraphrases, shared subjects, or unknown external pretraining overlap. Choose scientific partitions before preparing examples. Keep final test data separate from model selection.

One step is one optimizer update. micro_batch controls examples per forward pass; accumulation controls micro batches per update. Gradients are divided by actual scored tokens across the accumulation window. Short final windows are retained without duplicating rows to fill an epoch. Validation uses the same token weighted objective. A lower training loss is not a claim of improved general model quality.

Checkpoint and artifact identity

Checkpoints preserve base weights, adapter factors, Adam moments, optimizer policy, update/token counters, deterministic sample order/cursor, dataset identities, tokenizer, lineage and numerical implementation identity. Publication commits a manifest only after required files are complete. Existing destinations are refused. Checksums detect corruption and identify bytes; they do not prove authorship.

Exact resume requires the saved compatible numerical environment and exact input data. Bitwise replay is qualified on the same host CPU/runtime profile; it is not a promise across different hardware or math library implementations. Changing settings or data starts a new fine_tune run. A deployment model or adapter is not a replacement for an optimizer checkpoint.

An adapter is bound to the exact original GGUF source and its canonical tensor identity. Exporting changed full weights creates a new base: save/reimport that base before creating a new adapter selection. Applying a compatible adapter and exporting merged F32 weights are tested against the native inference backend; quantization has its own numerical effects and compatibility checks.

Resources and capability checks

The memory budget is admission guidance over model/training tensors and estimated activations. It excludes unrelated retained source handles, allocator overhead, thread stacks and total process RSS. It cannot prevent allocation failure under external memory pressure. LoRA reduces gradients and optimizer state; frozen base weights and forward/backward activations still occupy memory.

Query the capability before opening a model:

aner
import aner.gen
print(gen.training_available())
print(gen.training_backend())

A runtime without the optional training backend can type check the API but executing a training operation fails explicitly. It does not route work to a cloud provider or start a local service. The first admitted numerical backend uses LibTorch 2.9.0 C++ libraries. Optional inference support and training support are separate runtime capabilities.

Native serial compilation continues to support llm.load deployment; pretrained gen training currently runs through the Aner interpreter and is rejected by the standalone compiler with an explicit unsupported operation diagnostic.

Model architecture, canonical artifacts, bounded work and exact checkpoints are useful foundations for a later community created model. Volunteer participation, distributed aggregation, QLoRA kernels, broad accelerator training and multi billion parameter qualification remain separate work.

Qualification evidence

Recorded qualification includes an actual 134.5 million parameter SmolLM2 import, independent official source full vocabulary numerical/tokenizer comparison, real LoRA updates, exact resume and adapter/merged deployment through llm.load. The small measured training loss decrease demonstrates an update; it does not establish better general answers. Nontrivial randomized GQA fixtures separately qualify full weight updates, tied embeddings, F16/BF16 import, accumulation, artifact validation and quantization.

PretrainedModel and TrainingData retain immutable native resources until their last owning handle is released. Deployment LLMModel handles keep the explicit close() lifecycle documented by llm.load.

Prepare and run the complete source

Obtain the supported floating model separately and save it as models/base-f16.gguf. Save independently chosen training and validation rows as training.csv and validation.csv in the working directory. Both files require question,answer headers. For a small mechanism check, these are example rows, not a language quality training corpus:

Training:

csv
question,answer
What color is the clear daytime sky?,Blue.

Validation:

csv
question,answer
What color is fresh grass?,Green.

Save the complete adaptation source as examples/llm_pretrained_fine_tuning.aner, then run from the directory containing the two CSV files and models/:

sh
aner check examples/llm_pretrained_fine_tuning.aner
aner run examples/llm_pretrained_fine_tuning.aner

Checking opens no model, trains no weights and creates no output artifact. Running imports the local model, performs the explicitly requested updates and publishes new checkpoint, merged model, quantized model and adapter paths. Use a fresh writable working directory for another complete run. The default 4 GiB admission estimate does not establish that a chosen model fits available memory.

See native loading and lease lifetime, the generative module and the separate bounded training jobs for their corresponding lifecycle and compatibility contracts.

Aner documentation · Reference and guides