Skip to content

LexiEngine Inkling 2 Fit And LoRA

LexiSuite edited this page Nov 23, 2026 · 2 revisions

LexiEngine: fitting Inkling 2 and adapters

State of version cce75e0, November 23, 2026. The runtime: LexiEngine-Inkling-2.

How Inkling-2-Mini (inkling2_loop) runs through the engine's quantization job (lexi-engine-quantize job ..., the Panel's Quant Forge) and through a LoRA trainer, and what was measured. The model and its device runtime are described in INKLING-2-VULKAN-20261121.md.

1. The model as graph stages

Both the quantization job and the trainer run a model as a chain of differentiable LexiML stages, each reading the previous stage's output. For Inkling these are in crates/model-inkling/src/stage.rs:

Stage Input Output
embedding_stage token ids [1, tokens] (I64) the state [1, tokens, 2304]
visit_stage_with(index), 48 of them the state [slots, tokens, 2304] the next state
head_stage the last state logits [1, tokens, 200058]

The state's slots are the current stream, the finished residual blocks and what the loop carries between passes (the prelude stream every pass starts from, the block and stream the previous pass left for its messages); stage::layouts(index) gives them. The core layers' matrices appear in each of their three passes as the same named parameters (their derivatives add up). Matrix parameters are named as the converted file names its tensors and shaped [inputs, outputs].

Options (StageOptions):

  • routing: the router's choice per token, as the reference records it (Reference::routes). With it only the 8 chosen experts are computed per token (the grouped rows go through each used expert, the outputs are summed back by the router's weights, which are still computed in the graph from the router's probabilities). Without it every one of the 128 experts is computed for every token and the choice is made in the graph (8 rounds of ArgMax). The two agree wherever the choice is the same; holding the choice fixed only stops following a change of the choice itself.
  • adapters: LoRA terms x W + (alpha / rank) (x A) B on attn_q, attn_k, attn_v, attn_output.

Weights come from the converted file alone (Weights::from_gguf, configuration from its metadata with InklingConfig::from_gguf); the vendor checkpoint is not needed.

Checks (tool inkling-stage-check, CPU, 8 threads): see section 4.

2. Quant Forge on Inkling

lexi-engine-quantize sends a source whose general.architecture is inkling2_loop to its own stages (crates/quantize-tool/src/inkling_job.rs); the job manifest, resumption, cancellation and the Panel's runner are the same as for every other model.

What is requantized: the trunk's attention matrices, 176 tensors: per layer the query, key, value, output, gate, relative-position and sink projections, and on the four layers that see every position the two convolution projections. Experts the source holds in 4 bits stay as they are; experts held in 8 or 16 bits (in the full-precision source: layers 20-23) are items of the allocation with two options, Q8_0 or NVFP4, one item per layer (the device runtime reads a layer's gate/up and down experts in one type); see section 7. Every other tensor in a 16-bit float type (the embedding and the output table) is written as Q8_0 by round-to-nearest, so the output holds no tensor wider than 8 bits; F32 tensors (norms, router, controllers, convolution taps) stay F32, as the device runtime reads them.

Stage What it does on Inkling
calib the engine's F32 reference over every calibration window: one Gram per projection input (the query, relative, sink and gate projections share one; the key and value with their convolution projections; a core layer's three passes add up), and the reference's next-token distributions as the teacher (the last window is held out)
candidates GPTQ for every matrix against its input's Gram, one Hessian factor per shared input reused for every matrix and format that reads it, the rows split over the cores (no encoding block crosses a row); GSQ's learned rounding only for formats other than Q8_0 (on this model 20 GSQ steps did not reach the GPTQ result for Q8_0: relaxed loss 460 against 1.463 on blk.0.attn_gate); the same candidate records and receipts as every other architecture. Each expert tensor's NVFP4 fit is then scored on the held-out window in the runtime's cache format, alone against every expert rounded to nearest, and kept only when it scores lower; the kept fits are scored together and all dropped when together they do not score lower. Dropped fits are set aside in experts/rejected, their option takes the round-to-nearest loss, and the result is recorded per tensor in expert-candidates.json (heldout_check) and in expert-fit-check.json
rco-search budget for the items = target minus every other tensor as written. When every item's lowest-loss option fits there is nothing to trade: that allocation is written without any oracle run (report: "no trade-off to search, no KL oracle needed"). Otherwise an exact multiple-choice knapsack over the calibrated losses allocates (proxy losses, no oracle); the KL oracle over the 48 applications as graph stages (first 128 tokens of the first window, router choice held at the source's) stays behind LEXI_INKLING_RCO_ORACLE=1 for matrices alone
rco-build the source with the assigned candidates, the NVFP4 expert layers as the candidates stage fitted them where the held-out check kept the fit and rounded to nearest otherwise (the report lists each such tensor as fitted or round-to-nearest), and the 16-bit tensors re-encoded as Q8_0
eval the reference on the built file, held-out window, against the exact teacher, with 4-bit key and value caches as the runtime keeps them by default (pass: coarsened KL at most 0.02, top token agreement at least 0.95); the exact-cache score is reported beside it (other_caches). LEXI_INKLING_FORGE_CACHE=exact makes exact caches the scored format, for this stage and for the expert check

Device runtime constraint. The Inkling Vulkan runtime reads Q8_0 matrices (and NVFP4 or Q8_0 experts) only. A target that forces some matrices into another format (for example Q6_K) gives a file the CPU reference runs but the device does not load; the search report says so (inkling_runtime_loadable). For a device file, give a target that admits every matrix as Q8_0.

Cost. A full search (400 oracle evaluations, each the 50 stages forward and back on the CPU) is not practical on an 8-core host; see section 4 for the measured time of one evaluation.

3. A tail LoRA adapter

Tool inkling-tail-lora (crates/model-inkling/src/bin/inkling-tail-lora/, training core src/tail.rs). The experts make the whole model about 97 GB in F32, so the adapter goes on the last applications (layers after the loop; default the last 4). The applications before them run once per window in the reference and the state they hand on is kept; a training step runs the tail as stages with the adapter (router choice held at the frozen model's), the head, the next-token cross entropy, the derivatives back through head and tail (ml-grad) and an AdamW update (ml-optim). With --teacher FILE the loss is the mean KL from another model's distributions instead (a recovery adapter for a quantized file: the teacher is its full-precision source); each frozen window then keeps the teacher's top 256 tokens and the rest per position (windows/<kind>-<i>.teacher, tied to the window's tokens), the KL and its derivative are exact for those tokens plus one rest bucket, and --teacher-only freezes the teacher's side of every window ahead of the model's. The adapter is written as a GGUF LoRA adapter in the format the engine loads (general.type = adapter, adapter.type = lora, adapter.lora.alpha, F32 blk.N.attn_*.weight.lora_a [input, rank] and .lora_b [rank, output]).

4. Merging an adapter into an 8-bit file

lexi-engine-quantize merge-lora SOURCE.gguf OUTPUT.gguf [--lora ADAPTER.gguf [--scale S]] [--carry FILE.gguf] reads the full-precision source through its index (one tensor at a time), adds scale * alpha / rank * B A to the attention projections the adapter names, writes every BF16/F16 matrix as Q8_0 and copies everything else. --keep-types writes the adapted projections back in BF16 instead (a merged full-precision source for Quant Forge). --check-against FILE.gguf writes nothing and compares every tensor it would write with that file's; compare-gguf A B compares two files tensor by tensor. The draft head is added last by inkling-draft-pack (or carried from another file with --carry).

--base QUANTIZED.gguf [--grams DIR] merges into an already quantized file: every tensor and the metadata come byte for byte from it, except the projections the adapter names, which are rebuilt from the full-precision source plus the adapter's term and encoded in the base file's type: refitted by GPTQ against their input Gram from a Quant Forge workspace's gram folder (the candidates stage's route; a zero adapter gives the base file's bytes), or rounded to nearest without --grams. --experts-nvfp4 L,L,... writes the experts of those layers in NVFP4 by round-to-nearest (a factor per expert in a .scale tensor right after them), from the source's values or, with --base, from the base file's own values.

5. Measurements (2026-11-21/22, CPU, 8 threads)

Check Result
Whole model as stages (embedding, 48 applications with the router's choice held, head), weights from the GGUF alone, 32 tokens, against the reference largest logit difference 7.06e-5, top token 32/32, mean KL 8.9e-12
Single applications against the reference application 30: 2.29e-5 (values to 56); application 47 at 128 tokens: 9.92e-5 (values to 150); head 5.15e-5
Tiny synthetic model (unit test) dense and routed chains equal the reference; an exported adapter loaded as the runtime loads it gives the reference what the stages compute; the tail's derivatives equal finite differences
merge-lora BF16 source, zero adapter, against the released Inkling-2-Mini-NVFP4exp-Q8.gguf 744 tensors, 186 converted to Q8_0, 0 differ (byte-identical), 102.6 s
Tail training step (layers 22-23, rank 8, 128 tokens) 71-87 s, peak 19-21 GB
Tail stages with a zero adapter against the reference run to the end 12 windows, largest loss difference 8.2e-7

The adapter. A coding adapter on the engine's own Rust source (tail = layers 22-23, rank 8, alpha 16):

  • Run 1: 32 windows of one crate, AdamW 5e-4, 2 epochs: held-out loss 1.34901 -> 1.43963 (+0.091, overfit); the reference tool with --lora on the released 8-bit file agreed (1.44910 -> 1.53894 on 6 windows).
  • Run 2: 88 windows of 11 crates, AdamW 1e-4, validation every 8 steps: validation (ml-optim, lexi-gzip) 1.34901 -> 1.33497 at step 40 (-0.0140); test set measured once at that step (lexi-json, lexi-regex, lexi-http) 0.87646 -> 0.87505 (-0.0014, 0.16%): no measurable benefit, so no adapter was merged.

Quant Forge on Inkling (test Panel, full-precision source, target 16,900 MiB, Q8_0 and Q6_K, 16 windows of 512 tokens): calib 2,215 s (16 windows, 96 input Grams); candidates about 9 minutes (352 GPTQ fits, both formats); allocation: all 176 matrices Q8_0 (686,380,032 bytes; file 17,615,983,616 bytes). One KL oracle evaluation of that allocation, measured before the stage was changed to skip it: KL 3.15e-6 over 128 tokens, 1,448 s. The final run: allocation 8 s without an oracle; build 7 minutes (176 candidates, 568 tensors carried over, 17,627,965,056 bytes); eval on the 511 held-out tokens: coarsened KL 0.00214, top token 99.02%, passed. The Panel published the file with its receipt.

The published file, Inkling-2-Mini-8Q-RCO-GPTQ.gguf (18,263,767,520 bytes): the Quant Forge output with the draft head packed by inkling-draft-pack (54 tensors). Against the all-exact reference on 2 x 512 tokens:

File Exact caches: KL / top token 4-bit caches: KL / top token
Quant Forge output + draft head 0.00141 / 99.02% 0.00549 / 97.56%
Released Inkling-2-Mini-NVFP4exp-Q8.gguf 0.00175 / 99.22% 0.00499 / 97.56%

The calibrated rounding brings the exact-cache result 19% closer to the reference; with the 4-bit caches the runtime uses by default it is 10% further (top token unchanged).

On the device (bin of inkling-1121 at 2c29e8aa or later; the draft head read from the file, LEXI_INKLING_DRAFT unset), 2026-11-22:

Measurement Result
Plain at 4,096 / 16,384 prompt 2,430.6 / 2,299.8 tok/s; decode 66.27 / 64.89 tok/s
Drafting at 16,384 (256 tokens) 105.74 tok/s against 56.05 plain, 5.71 tokens a step, identical to plain
524,288 positions: memory plan weights 17.62 GB, caches 5.02 GB, scratch 0.58 GB (passes of 2,048), draft head 2.01 GB
524,288 positions: prompt / plain 523,264 tokens at 787.6 tok/s (664 s); decode 40.08 tok/s
524,288 positions: drafting (128 tokens) 39.62 tok/s against 37.01 plain, 2.98 tokens a step, identical to plain
Retrieval, ten facts in a 524k prompt 10 of 10
Load 31.7-33.4 s (13.7 s from the page cache)
Released engine (image b753bf3) loads the file, ignores the draft tensors, 53.07 tok/s at 4,096 positions

6. Known gaps and lessons

  • Lower-bit Inkling files are not possible yet: the CPU learned rounding refuses GPTQ's K-quant encoding as its start (inconsistent codes and groups), and the device runtime reads only Q8_0 matrices (and NVFP4 or Q8_0 experts). The job therefore fits GPTQ candidates and needs a target that admits every attention matrix as Q8_0.
  • A full allocation search (400 oracle evaluations) is not practical on an 8-core host: one oracle evaluation over the 48 applications at 128 tokens took 1,448 s.
  • The tail adapter did not carry over to unseen code (test set -0.0014); merging it is not worth the change.
  • Job scripts that source the shared environment file must not assign their own T: the environment's exit trap removes $T (its throwaway home), and a script that set T to its build folder lost that folder when it ended.
  • Gguf::open copies a whole file into memory; tools that read a model larger than a few GB use the index reader.
  • Quant Forge's calibrated proxy misleads for the experts: GPTQ against a layer's pooled token Gram cut the gate/up proxy to a fifth of round-to-nearest and made the real KL worse (+0.00027 with exact caches, all four layers fitted); the proxy also ranks the layers in the opposite order of their real cost. Repaired 2026-11-23 on the acceptance side: the candidates stage scores every expert fit on the held-out window in the runtime's cache format and keeps it only when it scores below round-to-nearest, then scores the kept fits together (section 2). Run on a copy of the 2026-11-22 workspace (511 held-out tokens, 4-bit caches): round-to-nearest 0.005713; 5 of the 8 fits kept (blk.20 down and gate/up, blk.21 gate/up, blk.23 down and gate/up), 3 dropped (blk.21 down, blk.22 down and gate/up); the kept fits together 0.005593. The check took 17 minutes (10 reference passes; the rounded tensors are written once). Still open: the differences are a few percent on one window, the allocation between layers still uses the proxy, and a fit that would reliably beat rounding needs per-expert Grams from the routed tokens.
  • Quant Forge's GPTQ attention improves the exact-cache score but costs with the 4-bit caches the runtime uses by default (0.00499 -> 0.00549 on the 8-bit run). Repaired 2026-11-23 on the reporting side: the evaluation stage scores and passes the file with 4-bit caches and reports the exact-cache score beside it. Still open: the attention fit itself does not see the cache format, and there is no held-out acceptance of the attention fit against plain rounding (the reference cannot yet take a single class of tensors from a second file within a job).
  • The Panel's Quant Forge repeated its full space check on a resume and counted what the run had already written as still needed, so a run that had written its output could not resume. Repaired 2026-11-23: a resume credits the run's candidates (up to the candidate budget), its staged model and an already published model against the estimate; the 5% reserve is unchanged.
  • An optimizer state with more than a million values does not fit the JSON reader: the tail trainer keeps it in a binary file (optimizer.bin).

7. Experts of layers 20-23 in 4 bits (2026-11-22)

The released file holds the experts of layers 0-19 in the vendor's NVFP4 and those of layers 20-23 in Q8_0 (the vendor shipped them in 8 bits): 4.33 GB of the 17.63 GB. In NVFP4 (blocks of 16 with an E4M3 scale, a factor per expert in a .scale tensor, the layout the device runtime already reads for layers 0-19) they take 2.29 GB: 2,038,427,168 bytes less. Attention, embedding, output table and draft head stay as released.

All scores below: CPU reference, the 2 x 512 scoring tokens (1,024 positions), KL to the all-exact reference.

Round-to-nearest, layer by layer (the released file with those layers' experts rounded when read):

Experts in NVFP4 Exact caches: KL / top token 4-bit caches: KL / top token
none (released file) 0.00175 / 99.22% 0.00499 / 97.56%
layer 20 0.00230 / 99.12% 0.00540 / 97.75%
layer 21 0.00228 / 98.73% 0.00552 / 96.97%
layer 22 0.00244 / 98.93% 0.00553 / 97.36%
layer 23 0.00225 / 99.02% 0.00564 / 97.36%
layers 20-23 0.00392 / 98.24% 0.00712 / 97.07%

No layer carries most of the cost (each adds 0.00050-0.00069 with exact caches); the four together add about the sum.

Through Quant Forge (test Panel, full-precision source, target 14,918 MiB, Q8_0 and Q6_K): calibration 2,234 s (104 input Grams, 8 of them the expert layers' pooled Grams: token rows for gate/up, routed-pair activations for down); the candidates stage fits each expert matrix by GPTQ on the NVFP4 grid against its layer's pooled Gram (one input at a time, each block's scale fitted at its first input); the knapsack put all 176 attention matrices in Q8_0 and the four expert layers in NVFP4; build 15,589,537,888 bytes; Quant Forge's own eval 0.00218 coarsened KL, 99.02% top token (passed). The calibrated proxy losses of the fit were 0.19-0.21 of round-to-nearest for gate/up and 0.72-0.83 for down. The real scores say otherwise:

File / variant (layers 20-23 experts in NVFP4) Exact caches 4-bit caches
released attention, experts round-to-nearest 0.00392 / 98.24% 0.00712 / 97.07%
released attention, experts fitted 0.00419 / 98.14% 0.00758 / 97.07%
released attention, down fitted, gate/up round-to-nearest 0.00392 / 98.54% 0.00699 / 97.27%
released attention, gate/up fitted, down round-to-nearest 0.00419 / 98.05% not measured
Quant Forge output (its GPTQ attention, experts fitted) 0.00400 / 98.44% 0.00802 / 97.27%

Per layer, fitted against round-to-nearest (exact caches): layer 20 0.00248 / 0.00230, 21 0.00243 / 0.00228, 22 0.00236 / 0.00244, 23 0.00225 / 0.00225. The proxy ranks the layers 23 > 22 > 21 > 20; the real cost ranks them 22 > 20 > 21 > 23 (round-to-nearest) and 20 > 21 > 22 > 23 (fitted).

The file. Inkling-2-Mini-NVFP4exp24-Q8-draft.gguf, 16,225,340,320 bytes: the released file with its draft head as the base, the experts of layers 20-23 rounded to NVFP4 from its own Q8_0 values (merge-lora --base ... --experts-nvfp4 20,21,22,23, 409 s); 790 of its 806 tensors are byte-identical to the released file. Scores: 0.00392 / 98.24% (exact caches), 0.00712 / 97.07% (4-bit caches). On the device the file's logits equal the CPU reference of the same file (48 tokens, unrounded caches: KL 0.00000).

On the device (runner of release 3a376f8, draft head read from the file, 4-bit caches; the release file's figures on the same runner in brackets, measured the same night):

Measurement 4-bit-expert file (release file)
Weights on the device 15.58 GB (17.62 GB)
Prompt at 4,096 / 16,384 (tok/s) 2,429.2 / 2,296.9 (2,420.3 / 2,303.3)
Plain at 4,096 / 16,384 (tok/s) 66.84 / 65.35 (65.98 / 64.93)
Draft head at 4,096 / 16,384 (tok/s) 110.30 / 109.33 (108.84 / 107.94), identical to plain
Draft head at 16,384 by kind: prose / code / json 82.22 / 100.28 / 129.13
262,144: prompt, plain, draft head 1,191.0 / 50.27 / 64.39 tok/s
524,288: prompt, plain, draft head 766.5 / 40.51 / 46.72 tok/s
Retrieval, ten facts at 262k / 524k 10 of 10 / 10 of 10
Device scores (510 positions, unrounded caches / 4-bit / prompt passes) 0.00322 / 0.00561 / 0.00569 (0.00149 / 0.00370 / 0.00382)

The 2 GB freed raise the cache room: caches for 1,048,576 positions (9.85 GB) allocated beside the weights with prompt passes of 256 and ran a short prompt; with the draft head 753,664 positions ran a short prompt at full drafting speed (at 770,048 drafting fell from 117 to 39 tok/s). The runtime's memory plan admits about 1,009,000 positions without the draft head and about 737,000 with it (passes of 256). A prompt filling 1,007,616 positions was stopped after 47 minutes of prefill without a result: the deepest full prompt measured is 524,288.

A recovery adapter on that file (inkling-tail-lora --teacher Inkling-2-Mini-NVFP4exp-BF16.gguf): tail 4 (applications 44-47 = layers 20-23, where the error enters; an attention adapter cannot reach the experts of layer 23, whose error enters after the last attention), rank 16, alpha 32, AdamW 2e-4, 128-token windows: 16 of engine source and 16 of the public wiki for training, 12 validation and 12 test windows of other code and documents (none overlaps the scoring text). Teacher distributions kept as the top 256 tokens and the rest; freezing about 60 s (model) + 75 s (teacher) a window, a step 125-175 s, peak 16 GB. With a zero adapter the tail reproduces the reference's KL to within 2.6e-8.

After step Validation KL (no adapter: 0.004398)
8 / 16 / 24 0.004402 / 0.004397 / 0.004372
32 (end of the first epoch, kept) 0.004368 (-0.7%)
40 / 48 / 56 0.004510 / 0.004466 / 0.004507 (stopped: no better in three evaluations)

Test windows (1,536 positions), CPU reference against the all-exact reference:

File Exact caches 4-bit caches
released file 0.00295 / 97.33% 0.01040 / 94.99%
4-bit-expert file 0.00385 / 97.20% 0.01128 / 94.60%
4-bit-expert file + adapter (float) 0.00385 / 96.94% 0.01124 / 94.53%

The adapter does not improve the file measurably (same KL with exact caches, 0.4% lower with 4-bit caches, top token lower in both), so no adapter is merged: the 4-bit-expert file is Inkling-2-Mini-NVFP4exp24-Q8-draft.gguf as above.

Clone this wiki locally