AMQL — AI Model Manipulation Tool
VIndex3 Model Container & Graph Database with transformation and R&D tools
[
AMQL turns LLMs into a queryable graph database — encode a checkpoint into a VINDEX3
container, then probe token relationships, trace causal pathways, edit weights, generate
LoRA adapters, merge models, prune layers, and export back to a standard checkpoint.
Built in C# against .NET 11.0 with an optional CUDA backend and a WPF desktop GUI.
Credit for the VIndex3 design: Chris Hay.
What is this for?
AMQL is the model-introspection engine behind a continuous-cognition platform. It exposes
the internal structure of a language model as a graph so you can query how tokens
relate, find the edges that carry one concept into another, and then edit those edges
— by patching weights, generating a LoRA adapter, or rewriting the base model.
At the token level you can remove false associations or add new ones in a familiar form
(e.g. "PlaceA is the capital of PlaceB"). At the next layer of abstraction you can adjust
relationships that haven't been described linguistically but are inferred — hallucinations,
incorrect tool selection, biases introduced during post-training.
Blending models via consensus-gated token alignment adds solution-space vectors from one
model into another. Combined with automated self-learning, this extends a model's
understanding beyond what fine-tuning alone can achieve — because fine-tuning is inherently
gated at human-level textual representations. Generating genuinely novel solution vectors
is a separate challenge, but AMQL lets you apply them once they exist.
Quick Start
# Create a tiny demo model, encode it, and generate a few tokens
amql-cli synth-model demo-model
amql-cli encode demo-model --out demo-container
amql-cli generate demo-container --prompt "The capital of France is" --tokenizer demo-model --steps 8
# Probe a token relationship
amql-cli route demo-container France Paris --tokenizer demo-model --top 5
Prerequisites: .NET 11.0 SDK and Git.
Architecture
AMQL is nine projects with a CLI front-end and a WPF desktop GUI:
| Project |
Purpose |
Amql.Cli |
CLI (amql-cli) — encode, infer, patch, merge, inspect |
Amql.Gui |
WPF GUI — container browser, command launcher, parameter editor, tensor explorer |
Amql.Vindex3 |
Container graph, schema, token-index management |
Amql.Safetensors |
Safetensors I/O, MXFP4, ternary, and NVFP4 codecs |
Amql.Inference |
Inference engine, tracing, LoRA adapter execution |
Amql.Hf |
HuggingFace checkpoint loading, config parsing, architecture mapping |
Amql.Merge |
Model merging, MoE-ification, fine-tuning, pruning, model conversion |
Amql.Entail |
The Entail language: statements compiled into model weights |
Amql.Onnx |
ONNX graph builder — zero-dependency protobuf writer |
Amql.Gguf |
GGUF v3 converter for llama.cpp deployment |
AMQL/
├── src/
│ ├── Amql.Cli/ Amql.Gui/ Amql.Safetensors/
│ ├── Amql.Vindex3/ Amql.Inference/ Amql.Hf/
│ ├── Amql.Merge/ Amql.Onnx/ Amql.Gguf/
├── native/amql_cuda/ # CUDA backend (GEMM, dequant, elementwise, attention, cuSOLVER)
├── tests/Amql.Tests/ # 293 unit & integration tests
└── docs/ # Design docs and architecture reference
CLI Reference
amql-cli encode <model-dir | https://huggingface.co/owner/name | owner/name> --out <container-dir> [--revision R]
amql-cli download <https://huggingface.co/owner/name | owner/name> [--out <dir>]
amql-cli verify <container-dir>
amql-cli generate <container> --prompt "text" --tokenizer <dir> [--steps N (default: until an end token)] [--patch <file>]
[--trace] [--trace-tensors] [--weights f32|bf16|mxfp4]
amql-cli route <container> <A> <B> --tokenizer <dir> [--top N] [--patch <file>]
amql-cli path <container> <A> <B> [--topk N] [--max-nodes N]
amql-cli inspect-token <container> <token> [--neighbors N] [--tokenizer <dir>]
amql-cli change-tensor <container> <object> <tensor> <cell> (--set V|--add V) --out <patch>
amql-cli save-lora <patch> --out <dir> [--rank 8] [--alpha 16]
amql-cli export <container> --out <dir> [--patch <file>] [--quant mxfp4|ptq1|pq2] [--arch qwen4-next]
amql-cli import <container> <model> --out <dir> [--container]
amql-cli merge <containerA> <containerB> --out <dir>
amql-cli moe-ify <container> --out <dir> --text <corpus> [--experts 8] [--top-k 2]
amql-cli prune <container> --out <dir> --target-bytes <size> [--approach provenance|corpus|random|star-elastic] [--text <corpus.txt>]
amql-cli strip <container> --keep Q4_0|BF16|FP4|Q8_0|FP32 [--out <slim-dir>]
amql-cli fine-tune <container> --data <pairs.tsv> --out <patch> [--lr 1e-4]
amql-cli bake-predicate <container> --predicate "<rule>" --out <patch> [--prompts <file>] [--layers 6,9,12]
amql-cli entail compile <program> --out <dir>
amql-cli entail graft <program> --host <dir> --out <dir>
amql-cli entail adapter <program> --tokenizer <partner-dir> --out <dir>
amql-cli entail side <container> --adapter <dir>[,<dir>] --prompt <text>
amql-cli create-model --hidden 768 --layers 12 --vocab 32000 --out <dir>
amql-cli convert-to-classifier <container> --num-labels N --out <dir>
amql-cli convert-to-embedding <container> --out <dir>
amql-cli export-onnx <container> --out <model.onnx>
amql-cli classify <container> --premise "A" --hypothesis "B"
amql-cli layers <container>
amql-cli to-gguf <checkpoint-dir> --out <file.gguf>
amql-cli from-gguf <file.gguf> --out <container-dir>
amql-cli export --list-architectures
Two directory types appear throughout: containers (<container-dir>, encode output,
weights only) and checkpoints (--tokenizer, the original HF model directory whose
tokenizer.json converts text to ids).
Key Capabilities
Model Families
Import and export these checkpoint formats:
| Family |
model_type |
Notes |
| Qwen 3.5–3.8 |
qwen3_5_text |
Hybrid: GDN (linear attention) + softmax, MoE, vision |
| Qwen Flash-Next |
qwen4_exp_text |
--arch qwen4-next export with HC placeholders |
| Gemma 4 |
gemma4_text |
GeGLU activation, QK norms, nested text_config |
| LFM 2.5 |
lfm2 |
Short-convolution layers + GQA, SwiGLU MLP |
| LFM3 / LFM3-VL |
lfm3 |
Gated short conv (width 7) + full and sliding-window GQA, per-head output gate, sandwich norms, zero-tail partial rope; to-gguf writes llama.cpp's lfm3 arch |
| Masked diffusion (dLLM A2D) |
a2d-qwen3 |
Qwen3 with bidirectional attention, MDLM objective; generate runs the block-wise low-confidence unmasking sampler; to-gguf writes llama.cpp's rnd1 arch (dense FFN as one expert) for llama-diffusion-cli |
| Nomic Embed |
nomic_bert |
Bidirectional encoder, mean pooling |
| ModernBERT / Von |
modernbert |
Global + sliding bidirectional encoder, GeGLU; Von's option_marker.pt scoring head read and written natively, and run in-process by decide |
| Jev Classifier |
*ForSequenceClassification |
Score head on decoder backbone |
| Binary/Ternary |
any decoder |
Via --quant mxfp4, --quant ptq1, or --quant pq2 |
Inference & Weight Management
Four weight working-set modes, selected by AMQL_WEIGHTS (or --weights on generate, entail eval and entail side):
| Mode |
Resident size |
Description |
f32 |
f32 values; a BF16-stored matrix is held as its BF16 bits and widened in the kernels |
Byte-exact reference |
bf16 |
Stored BF16, widened on access into LRU cache |
~2× smaller |
mxfp4 |
MXFP4 packs dequantised into LRU cache |
~4× smaller |
disk |
Only what fits the cache; the rest is widened from the container on every pass |
Exact f32 on the CPU for a model larger than RAM |
With the CUDA backend built (native/amql_cuda/build-cuda.cmd) and a CUDA device present,
DecodeSession runs a whole sequence on the device engine. Weights are uploaded once as BF16,
activations, the KV cache and the recurrent state stay on the GPU, and each decode step is one
CUDA graph. On Qwen 3.5 0.8B (RTX 5090) it decodes at ~655 tok/s against llama.cpp's ~440–500
on the same weights in F16, and prefills 512 tokens at ~64k tok/s against ~21k. Prompts round
their activations to BF16 for the tensor cores, so logits agree with the managed path to ~0.3%;
AMQL_GPU_PREFILL=f32 (or DecodeSession.ExactGpuPrefill) keeps them at f32, agreeing to
rounding, at about half the prompt speed. Decode steps are f32 either way. Routed experts, short convs, traces and patches stay
on the managed path; see docs/gpu-performance.md.
When AMQL_GPU=1 and the CUDA backend is built (native/amql_cuda/build-cuda.cmd),
MXFP4 packs are dequantised to FP16 on-device and GEMMs run on tensor cores with FP32
accumulate. Elementwise ops — RMSNorm (auto-dispatched), SiLU, RoPE — and fused
GQA attention (QKᵀ + causal mask + softmax + PV) also run on-device. KV caches can
be allocated and appended on-device with zero host round-trips. Embeddings, norms,
and the output head stay f32 in every mode (in disk, only while they fit the cache). A cuSOLVER fp64 Cholesky path accelerates
merge normal-equation solves.
Tune memory with AMQL_MEMORY_GB, AMQL_F32_CACHE_GB, and AMQL_CORES.
amql-cli bench <container> measures single-request prefill and decode speed once the model is
loaded, and prints a checksum of the logits' bit patterns so a change to the kernels can be shown
not to change the numerics. On Qwen 3.5 0.8B (CPU, Threadripper 9970X, two DDR5 channels) decode
runs at ~44 tok/s against llama.cpp's ~39 on the same weights in F16; see
docs/cpu-performance.md.
entail graft and encode stream: they read the host through its memory map and write each tensor as
it is made, so neither holds a model in memory, and a sharded host (model.safetensors.index.json)
grafts like a single file. entail eval and entail side switch to disk by themselves when a
graft's f32 weights would exceed the memory budget. It never uses the GPU, so GPU memory isn't a limit either.
Token Relationship Probing
route names the relationship between two tokens using template probing and identifies the
exact (layer, head, position) attention coordinates carrying one token's meaning into the
other. Causal tracing then reports per-layer residual weights — the targets to patch or LoRA.
path shows the model's own continuation route between two tokens via bidirectional
best-first search over the next-token graph.
Patching, LoRA & Fine-Tuning
change-tensor edits a single weight cell and records the delta as a patch. Every
command (generate, route, path, inspect-token, export) accepts --patch to
apply deltas at load time. save-lora factors a patch's 2-D deltas into a LoRA adapter
(lora_A / lora_B) via truncated SVD.
fine-tune performs supervised output-head adaptation: for each (prompt, completion)
pair, the model forward-passes the prompt, teacher-forces each completion token, and
accumulates per-token head deltas — no autograd, no gradient infrastructure, fully
deterministic.
bake-predicate writes a rule into the weights — "always reply in French", "you are
a pirate", a fact the model should take as given. The model reads the predicate in
context (as its system message) and answers a set of probe prompts, which it can write
for itself; then the FFN down-projections of a few middle layers are solved in closed
form (minimum-norm ridge, layer by layer) so the model without the predicate
reproduces its hidden states with it. The output is an ordinary weight patch, and the
run reports KL and top-1 agreement against the predicated model before and after.
entail is the deterministic counterpart: a small language in which each statement
compiles to specific weights, with nothing learned or fitted. compile turns a program
into a new, empty model; graft restructures a Qwen3.5 checkpoint around it, in lanes the
host cannot touch. scripts/entail/mathematics.entail.txt defines decimal arithmetic:
grafted into Qwen 3.5 0.8B it takes direct arithmetic from 43.8% to 100% with top-1
predictions on prose unchanged. See docs/entail.md.
entail find, extract, optimise, review and accept go the other way: from a trained
model to a subject's Entail. They locate the experts or neurons that carry a subject, probe
what the model does, and refine the resulting table into exact laws through documented
rewrite rules, with any model able to propose a change and a mechanical gate deciding.
From Qwen 3.5 0.8B's own noisy answers this derived a + b, a - b and a*b, and reloading
the result took it from 84% to 100% on unseen two-digit arithmetic.
entail decompile