Direct weight space programming
Check, apply and reverse explicit local checkpoint changes with preserved byte identities.
Experimental guideDevelopment APIsThe experimental weight space API is available in Aner 0.0.8. The paired inference workflow requires a build with the optional native GGUF backend.
Aner can validate and apply explicit changes to a local model checkpoint without running backpropagation or an optimizer. This is an experimental gradient free model adaptation route: a weight program specifies the stored values to change, and Aner produces an independently identifiable, reversible candidate checkpoint. It belongs alongside conventional training and fine tuning workflows. It is not evidence that direct weight programming replaces pretraining, supervised fine tuning or LoRA.
The motivating MIT weight space programming report describes a reasoning LLM inspecting and modifying network weights. Its successful Qwen intervention primarily reduced reasoning loops. Its non looping Gemma experiment did not establish a meaningful new capability. Aner's initial research route replays the released Qwen patch; replay is distinct from discovering a new edit. There is no automated LLM proposer, optimizer, evaluation search or training data generator in this module.
Connection to existing modules
| Existing module | Relationship |
|---|---|
aner.tensor / aner.nn | Native Float32/Float64 tensors, explicit neural weights, inference and differentiation remain the route for numerical tensor computation. Checkpoint editing preserves encoded storage bytes and does not create an autograd graph. |
aner.gen | gen.parameter_names, gen.parameter and immutable gen.with_parameter already support parameter inspection/replacement in supported Aner generative models. Weight space file transactions complement these APIs for external checkpoints. |
| Modern pretrained I/O | Tensor import and training have their own numerical conversion contracts. The weight editor preserves the original Safetensors or GGUF header, padding and encoded payload, which is necessary for exact BF16 replay. |
aner.llm | Verified acquisition, numeric NPZ import, checkpoint transactions, sampling and raw completion support the complete application workflow. Local inference handles keep their immutable shared weights; load each edited deployment artifact separately. |
aner.api | Existing native chat routes remain available for supported chat models. The qualified Qwen3.5 raw completion profile is called directly from Aner; chat routes do not expose it. |
The executable application is written entirely in Aner. It acquires pinned assets, constructs patch transactions, runs paired inference, grades its limited probes and emits receipts through included modules. Those modules are implemented in Aner's native C++ runtime; pretrained inference uses the pinned llama.cpp engine. Application source does not need a separate importer, format transplant runner or inference adapter.
llm.load retains its llama/qwen2 chat support and adds qualified dense qwen35 raw, stateless text completion. Only the pinned Qwen3.5 to 0.8B BF16 artifacts in this experiment have been exercised. Metadata admission does not establish compatibility or quality for every member of the family. Safetensors editing and inference admission remain separate operations.
Aner API
The following operations require import aner.llm and return versioned JSON Strings. Acquisition takes an explicit HTTPS URL; the remaining operations use local paths. They are available to the interpreter and the checked serial native compilation path. They are serial effects and are not admitted inside compiled parallel tasks.
| Operation | Result |
|---|---|
llm.fetch_artifact(url: String, path: String, sha256: String, bytes: Int64) -> String | Acquire a pinned HTTPS asset or verify an existing local copy; never overwrite an existing file. |
llm.weight_import_npz(base: String, archive: String, specification: String, out_path: String) -> String | Import explicit numeric index/stored-bit arrays under a hash pinned mapping, validate the resulting patch against the base, and publish a new patch file. |
llm.weight_inspect(path: String) -> String | Read one Safetensors or supported GGUF file; report its format, complete file digest and each tensor's name, dtype, normalized shape, element count and raw payload digest. |
llm.weight_check(base: String, patch: String) -> String | Validate the entire proposed transaction and report calculated changes without creating an output checkpoint. |
llm.weight_apply(base: String, patch: String, out_dir: String) -> String | Perform the same validation, stage a copied checkpoint and inverse, verify the result, then publish a new transaction directory. |
llm.weight_revert(transaction: String, out_dir: String) -> String | Verify a committed transaction and its inverse, then restore the original complete file digest into a different new directory. |
Named arguments can be reordered. Type/import errors are checked before execution; runtime failures use diagnostic R3101. Inspection and dry runs can read the complete checkpoint multiple times, so they are substantial I/O operations for large files.
import aner.llm
let base = "models/base.safetensors"
let patch = "patches/reviewed-edit.json"
print(llm.weight_inspect(path: base))
print(llm.weight_check(base: base, patch: patch))
print(llm.weight_apply(base: base, patch: patch, out_dir: "runs/candidate-001"))
print(llm.weight_revert(transaction: "runs/candidate-001", out_dir: "runs/restored-001"))The import and transaction parent directories must exist. Output patch files and transaction directories must be new. The original checkpoint is never overwritten. The reusable transaction functions are also shown in the Aner example.
Verified acquisition and numeric archive import
fetch_artifact requires an exact lowercase SHA-256 and byte count in 0..16 GiB. It streams HTTPS with certificate/host verification, at most six redirects and a 64 KiB response header budget per request. Every redirect destination is validated before connecting. URL credentials and fragments are rejected; URLs are omitted from diagnostics and receipts. No ambient proxy, netrc credentials or authentication is used. A transfer has a one hour deadline, a ten second connection timeout and a thirty second low speed limit.
An existing destination is opened as a regular nonsymlink file and its complete size/hash are checked; a mismatch fails without replacing it. A new download is written to private staging, reverified and published without replacement. Missing real parent directories may be created. Symlink ancestors are rejected, and the destination's parent identity is rechecked before success. The receipt schema is aner.artifact_fetch.v1, with status VERIFIED_EXISTING or FETCHED. This acquisition operation is currently available on macOS and Linux; llm.load itself still performs no download.
For example, acquire the released sparse archive from its pinned revision:
import aner.llm
print(llm.fetch_artifact(
url: "https://raw.githubusercontent.com/RikiyaT/lm_understand-logs/4d09ba6d6a7e891dd8063974dfe81b3d78e3494f/exp8_math/runs/p50c/edit/edit.npz",
path: "assets/edit.npz",
sha256: "e92a92aafd1f1068b4fd94aa0fbe081ba3ddea2047ee7bcac7161d861be299e7",
bytes: 387619))
print(llm.weight_import_npz(
base: "assets/qwen3.5-0.8b-base-bf16.gguf", archive: "assets/edit.npz",
specification: "specifications/p50c-gguf.json", out_path: "generated/p50c-gguf.json"))The specification schema is aner.weight_npz_import.v1. It requires archive_sha256, base_sha256, scope and edits; optional provenance is carried into the generated patch. Scope uses the same fields as the patch below. Every edit requires tensor, dtype, shape, base_sha256, edited_sha256, indices_array and values_bits_array. Array names identify flat .npy members. Tensor names, normalized shapes and payload hashes must match the selected checkpoint format. The importer requires the expected edited tensor hashes, even though an ordinary patch may omit them.
Indices must be distinct one dimensional little endian signed/unsigned 32 bit or 64 bit integers, nonnegative and exactly representable within JSON's integer range. Values must be one dimensional little endian uint16 for BF16/F16 or uint32 for F32 and have the same count. These are stored bit patterns, not floating point values. The native importer supports bounded stored/DEFLATE ZIP members and numeric NPY versions 1/2. It rejects object data, Fortran order, multidimensional arrays, unsafe names, repeated/unreferenced members, inconsistent ZIP headers, bad CRCs and trailing compressed data.
After decoding, weight_import_npz runs the same full base/scope/finite-value/edited-hash validation as weight_check before exclusively publishing the new patch. Its aner.weight_npz_import_receipt.v1 receipt records IMPORTED, archive/specification/patch identities, array and replacement counts, and the validation receipt. No model weight changes occur during import.
Patch format v1
aner.weight_patch.v1 is a declarative JSON format. It contains no executable code, expressions or dynamic module names. Duplicate JSON keys, unknown schema fields, nonfinite numerical values and malformed storage ranges are rejected.
| Field | Meaning |
|---|---|
schema | Exactly aner.weight_patch.v1. |
base_sha256 | SHA-256 of the entire source file, including its original header. |
scope.allowed_tensors | Explicit names that this patch may edit. |
scope.max_changed_elements | Conservative cap on all specified positions, including replacements that happen to be no ops. |
scope.max_changed_fraction | Conservative cap on specified positions divided by the checkpoint's total stored element count. This denominator can include non language model tensors in a multimodal checkpoint. |
scope.max_abs_change | Largest permitted numerical absolute change at a specified position. |
scope.max_relative_l2_change | Per edited tensor limit: norm(delta) / max(norm(base_tensor), 1e-30). |
edits | One entry per distinct edited tensor. Each requires tensor, dtype, shape, base_sha256, indices and values_bits; edited_sha256 is optional. |
provenance | Optional explanatory String, at most 4,096 bytes. Attribution is recorded text, not an authenticated identity. |
An edit's base_sha256 and optional edited_sha256 hash the tensor's contiguous encoded payload only. indices contains distinct zero based flat row major element positions. values_bits contains exact unsigned bit patterns: 0 to 65,535 for F16/BF16 and 0 to 4,294,967,295 for F32. The shape and dtype must exactly match the checkpoint. A matrix orientation mismatch is an error, not an implicit transpose.
Both formats expose logical row major shapes. GGUF records fastest axis first dimensions, so catalog inspection reverses their notation without moving payload bytes. The released [1024,3584] matrices appear as [3584,1024] in the GGUF file header and as [1024,3584] in Aner's catalog and patch. Safetensors and GGUF use different tensor names and complete file hashes, so each needs its own explicit import specification.
This v1 format performs no floating point conversion. For example, BF16 1.0 is stored as integer bits 16256 (0x3f80), while BF16 3.0 is 16448 (0x4040). The engine decodes values only to reject nonfinite weights and measure numerical limits; it writes the supplied bits directly. If a future proposer computes Float32 values, conversion and rounding must be explicit and independently validated before forming a v1 patch. Do not use a generic projection formula as a substitute for the published exact patch.
This complete example matches the 84 byte [1,2] BF16 fixture constructed in tests/wsp_language_tests.cpp, and changes only its first element to 3:
{
"schema": "aner.weight_patch.v1",
"base_sha256": "e8c7a3ad22e0364228dd60e5a9e9e698d11af0b82baadedf69897646033bbe77",
"scope": {
"allowed_tensors": ["toy.weight"],
"max_changed_elements": 1,
"max_changed_fraction": 0.5,
"max_abs_change": 2,
"max_relative_l2_change": 1
},
"edits": [{
"tensor": "toy.weight",
"dtype": "BF16",
"shape": [1, 2],
"base_sha256": "54114f538801f6678fbd079c23daf4084457385ab206deba2abd70d219cde832",
"edited_sha256": "6131bb73043ff97c056e1a3a187c39435acd24167367b831af40014efc9aa614",
"indices": [0],
"values_bits": [16448]
}]
}The scope is a declaration supplied by the patch author. It is not an independent access control policy: a proposer can write a permissive scope. A supervising application must compare the proposed names and budgets with its own approved policy, independently establish the permitted base identity, and decide whether to call weight_apply. There is no built in universal prohibition on embeddings, output heads or particular layers. The MIT application specifications supply the two specific allowed tensors for their strict replay profiles.
Transactions, receipts and limits
An applied directory contains:
model.safetensorsormodel.gguf: the candidate in its original storage format, with all untouched bytes preserved.patch.json: the exact admitted patch text.inverse.json: a generated patch containing the original bit patterns.receipt.json: complete file, patch, inverse and per tensor digests, targeted and actually changed counts, and numerical change measurements.
The receipt schema is aner.weight_receipt.v1, with an explicit format; weight_check returns status VALIDATED, while a committed application returns APPLIED. candidate_sha256 and inverse_sha256 are empty during a dry run. The backprop_used: false field describes this transaction engine, not the complete training history of the model. Hashes establish byte identity and tamper detection against a trusted receipt; they do not establish authorship or model quality.
Apply keeps a verified regular file handle open while validating and copying the base. It stages the candidate in a private directory, checks written tensor hashes and publishes with an atomic no replace directory operation on supported platforms. Failures before publication discard the stage. This is atomic publication, not a claim of crash durable storage after power loss. Input file paths must resolve to regular files and cannot themselves be symlinks.
Reversal checks the receipt, original patch and inverse digests, verifies the candidate identity, and requires the restored complete file digest to equal the original. It produces another transaction rather than modifying the original or current candidate. Preserve the original checkpoint and the entire transaction directory for audit and recovery.
| Resource or storage rule | Current bound |
|---|---|
| Source checkpoint | At most 16 GiB; single Safetensors or GGUF v3 file. |
| Safetensors JSON header or patch | At most 8 MiB; JSON depth at most 32 and parser node budget 2,100,000. |
| Safetensors catalog | At most 65,537 top level entries including optional metadata; tensor rank at most 16. |
| GGUF catalog | Header read budget 64 MiB; 1 to 65,536 tensors of rank 1 to 4, at most 4,096 metadata keys, string size at most 16 MiB, at most 1,000,000 values per flat metadata array and 2,100,000 scalar metadata values overall. |
| GGUF alignment | Power of two in 1..4,096; contiguous tensor ranges with only required alignment padding. Optional final alignment padding is preserved. |
| Patch | 1 to 16 distinct edited tensors and 1 to 16 distinct allowed names. |
| Specified positions | At most 1,000,000 across the patch, further restricted by its scope and JSON size. |
| Touched tensor payload | At most 64 MiB each; at most 256 MiB total retained tensor payload. Parser data, indices and bookkeeping use additional bounded memory. |
| Editable storage | F32, F16 and BF16 only; source and replacement values in touched tensors must be finite. |
| Other storage | Safetensors may contain supported fixed width numeric/Boolean descriptors copied unchanged. Every GGUF tensor must use F32/F16/BF16. Unknown dtypes, invalid offsets, overlaps, excess gaps and unindexed trailing data are rejected. |
| NPZ import | Archive at most 16 MiB, 1 to 32 flat members, aggregate decoded payload at most 16 MiB; member names at most 128 ASCII bytes. NPY header at most 65,536 bytes. |
| Import specification/output | Specification at most 256 KiB and 10,000 JSON nodes; generated patch at most 8 MiB, subject to all ordinary patch limits. |
There is no shard index loader, quantized weight editing, automatic parameter search, low rank expression interpreter, optimizer or automatic checkpoint to GGUF converter in the transaction engine. Acquisition uses explicit pinned URLs; editing an existing GGUF does not convert another checkpoint format into GGUF.
MIT replay and evaluation
The pinned experiment 8 release supplies a sparse BF16 patch for Qwen/Qwen3.5-0.8B at revision 2fc06364715b967f1860aea9cf38778875588b17. The published p50c manifest identifies the layer 15 and layer 19 mlp.down_proj.weight tensors, both [1024,3584]. The original intervention touched 131,072 positions; the stored sparse archive contains the 130,188 entries whose BF16 bits actually changed. Those are different counts. Published manifest
The Aner application repository contains the executable workflow as .aner programs and the reviewed mappings/probes as data:
| Program | Responsibility |
|---|---|
programs/replay.aner | Acquire or reverify pinned assets, import the same sparse archive under separate Safetensors/GGUF mappings, check/apply both transactions, and assert the expected candidate identities. |
programs/pilot-short.aner | Run eight paired manual arithmetic probes with an explicit prompt, fixed sampling and a 2,048 token output budget; grade and emit JSONL in Aner. |
programs/pilot-long.aner | Run the two probe 32,768 token control with the same declared decoding protocol. |
programs/revert.aner | Restore each format into a new directory and assert the original complete file identities. |
programs/check-helpers.aner | Validate the application's JSON escaping and simple integer answer grading helpers. |
The GGUF specification targets the pinned official BF16 export. It names blk.15.ffn_down.weight and blk.19.ffn_down.weight, verifies their base payload hashes against the released HF tensors, and supplies the same flat sparse indices and BF16 replacement bits. weight_apply edits that GGUF directly, preserving all other bytes. Safetensors and GGUF reversal each restore their own exact base file.
The pilot loads base and candidate separately with llm.load, configures eight threads and 512 token prefill batches/microbatches through with_optimizer, then calls with_sampling(20, 0.95, 1.5) and complete(rendered_prompt, budget, 0.6, 42). The Aner source supplies the full ChatML user message and explicit <think> assistant prefix. Sampler order is presence penalty, temperature, top k, top p, seeded draw. Presence history contains only tokens generated during that request. Responses retain visible reasoning delimiters and strict UTF-8; their telemetry records exact prompt/token hashes, the requested/effective seed and protocol.
The qualified Qwen3.5 path supports raw stateless text completion with an F16 attention cache and fully cleared recurrent state. It rejects chat rendering, persistent sessions, prefix caching, speculative decoding, LoRA and continuous batching. Recurrent memory estimates remain unknown (-1). See native inference for optional backend configuration and capability checks. The application controls evaluation and evidence; admission and byte integrity do not establish task quality.
Keep these evidence gates separate:
| Gate | Evidence needed |
|---|---|
PATCH_REPLAY_VERIFIED | Both published edited tensor hashes, correct counts, unchanged source and untouched bytes, and exact restoration. |
INFERENCE_SMOKE_VERIFIED | Original and candidate load through an identified backend and produce recorded paired outputs. |
INFERENCE_EVAL_REPLICATED | A comparable held out evaluation with the authors' full protocol, dataset identity, sample counts, decoding controls and uncertainty. |
NEW_EDIT_DISCOVERED | A new independently recorded proposal/search, practice only feedback, retained failed attempts and untouched holdout evaluation. |
This API document does not attest that a benchmark gate passed. Record executed gates and receipts in the accompanying research results. Neither replay nor a few successful generations establishes the MIT accuracy improvements, and no gate automatically implies the next.
The authors' Qwen evaluation used thinking on, temperature 0.6, top p 0.95, top k 20, presence penalty 1.5 and 32,768 maximum generated tokens. MATH 500 used four samples per problem and measured mean sample correctness rather than pass@4. Changing a token budget, backend, prompt template, sampler order, quantization or scoring changes the experiment. A small paired pilot remains a pilot even when it uses some of these settings. Published evaluation protocol
The user facing case study should link to repository code and validation records, report the actual Aner gate achieved, and label any MIT numbers as externally reported results. Website content must not store the source code artifacts. Preserve research data attribution: the MIT release license separates MIT licensed scripts from CC BY 4.0 logs/data/networks and other third party material. The Safetensors specification defines the storage layout used by the editor.
See the Language model connections module reference for the shared API.