Ferrotensor
ContentsLoRA fine-tuning

LoRA SFT: SmolLM2 on Alpaca

This walkthrough fine-tunes a real Hugging Face checkpoint with LoRA, evaluates it on held-out data, saves the adapter, reloads it and generates text. Every number below was measured with the exact commands shown. The first run is SmolLM2-135M on an Apple M2 (8 GB) with a 0.4 build; the sections after it are on an NVIDIA A10G (24 GB), each labelled with the build it was measured on.

MachineMacBook Air, Apple M2, 8 GB unified memory, macOS 27.2
GPU backendMetal through wgpu
Toolchainrustc 1.99.1, release build of Ferrotensor 0.4
ModelHuggingFaceTB/SmolLM2-135M (base model, Llama architecture, 30 layers, hidden 576, 9 query / 3 KV heads, vocab 49152, tied embeddings)
Datayahma/alpaca-cleaned: 2,000 training and 64 held-out examples, as prepared below
AdapterLoRA rank 8, alpha 16, on q_proj, k_proj, v_proj, o_proj of every layer (921,600 trainable parameters, 240 tensors)

ResultLink to this section

Measured on 0.4; later builds moved more of the backward pass and the loss to the GPU, so the speed and memory figures in this section are not current.

BeforeAfter 250 steps
Held-out loss (64 examples, 2,744 response tokens)2.42501.6519
Held-out perplexity11.305.22
  • Wall time: 2,195.5 s for 250 optimizer steps (2,000 sequences, one epoch), including four evaluations: 8.8 s per step, about 1.1 s per sequence.
  • Peak memory footprint (/usr/bin/time -l): 3.29 GB for training, 2.24 GB for evaluation.
  • Generation with the KV cache: about 13 tokens/s for the base model and 8 to 9 tokens/s with the adapter applied (LoRA adds two small matmuls per projection).
  • The adapter is 3.7 MB. Reloading it with eval --lora reproduces the held-out loss exactly (1.6519).

The base model has never seen the ChatML template, so before tuning it echoes the prompt or loops; after tuning it answers and stops at <|im_end|> on its own (greedy decoding, --temperature 0):

PromptBase modelWith the adapter
Give three tips for staying healthy.Give three tips for staying healthy. then Assistant repeated until the 60-token limit1. Eat a balanced diet that includes a variety of fruits, vegetables, lean proteins, and whole grains. 2. Stay physically active by exercising for at least 30 minutes a day, five days a week. 3. Limit your intake of processed foods, sugary drinks, and unhealthy … (60-token limit)
Translate 'good morning' into French.Translate 'good morning' into German. / … Italian. / … Portuguese. … (60-token limit)Bonjour, bonne journe! (stops by itself after 8 tokens)

A 135M-parameter model stays a 135M-parameter model: answers are fluent but shallow, and sampled output can wander (for "Write a haiku about the ocean." with --temperature 0.7 --top-k 50 --top-p 0.9 --seed 1 it wrote repetitive free verse, not a haiku).

Loss curveLink to this section

Training loss is the mean over the supervised (response) tokens of the last 10 steps (80 sequences). It is noisy because each window is only about 2,300 to 3,000 tokens; the held-out loss is the cleaner signal.

StepTrain lossHeld-out lossLRGrad norm
02.4250
102.62032.50e-40.83
202.28515.00e-42.04
302.15904.98e-41.63
402.00814.92e-41.09
502.09371.81454.81e-41.92
602.00694.67e-41.18
701.71444.50e-41.09
801.97064.29e-41.13
901.91724.05e-40.91
1001.79481.69793.79e-41.30
1101.64953.50e-42.83
1201.69753.21e-40.97
1301.71122.90e-41.00
1401.79102.60e-41.44
1501.98211.67022.29e-40.81
1601.63922.00e-40.69
1701.73331.71e-41.41
1801.78101.45e-41.12
1901.75771.21e-43.28
2001.71301.65791.00e-42.04
2101.76908.28e-50.69
2201.78316.86e-51.16
2301.85125.83e-50.67
2401.86025.21e-50.83
2501.63171.65195.00e-50.91

(Grad norm is the global norm of the last optimizer step in each window, before clipping to 1.0.)

On an NVIDIA GPU: three model sizesLink to this section

scripts/lora-run.sh MODEL repeats this walkthrough (same data split, LoRA rank 8 on q/k/v/o, lr 5e-4, 20 warmup steps, 250 steps of 8 sequences, sequence length 256) on any Llama-style checkpoint. Run on an NVIDIA A10G (24 GB, Vulkan, driver 595.112.07, rustc 1.99.1) at commit 1b6709f:

ModelLayers, hiddenTrainable paramsHeld-out loss before → afterPerplexity before → afterTime per stepPeak host memoryAdapter
SmolLM2-135M30, 576921,6002.4250 → 1.652111.30 → 5.221.33 s2.06 GB3.7 MB
SmolLM2-360M32, 9601,638,4002.0852 → 1.32288.05 → 3.751.69 s4.75 GB6.6 MB
SmolLM2-1.7B24, 20483,145,7282.6474 → 1.066714.12 → 2.912.47 s20.01 GB12.6 MB
  • Time per step is the median over the run, for one optimizer step of 8 sequences; 250 steps of the 1.7B model take about 10 minutes.
  • The 135M result matches the M2 run above: the same held-out loss before tuning (2.4250) and 1.6521 after, against 1.6519. The last digits differ because the loss and the gradient norm are now summed on the GPU. An earlier build that computed them on the CPU gave 1.6519 on the A10G too, at 20.2 s per step.
  • With the adapter, all three answer instead of echoing the prompt. Greedy outputs for "Give three tips for staying healthy.": 135M as in the table above; 360M 1. Eat a balanced diet. 2. Get enough sleep. 3. Exercise regularly.; 1.7B 1. Eat a balanced diet that includes fruits, vegetables, lean proteins, and whole grains. 2. Exercise regularly to maintain a healthy weight ….
  • Greedy generation with the KV cache runs at 35.9, 21.8 and 10.1 tokens/s for the base models.

Batching, f16 base weights and lower host memory (0.6)Link to this section

The same recipe on the same A10G at commit b319ce7, with the changes in 0.6: uploads that no longer keep staging copies, --batch-size, and frozen base weights stored as f16 (--f16-weights, the default since 0.6):

ModelRunHeld-out loss afterTime per stepGPU memory (GiB)Peak host memory
SmolLM2-135Mf32 weights, --batch-size 1 --grad-accum 81.65211.28 s3.81.35 GB
SmolLM2-135Mf32 weights, --batch-size 8 --grad-accum 11.65210.57 s16.31.30 GB
SmolLM2-1.7Bf32 weights, batch 11.06572.49 s14.75.57 GB
SmolLM2-1.7Bf16 weights, batch 11.06402.38 s11.95.33 GB
  • Batching eight sequences into one GPU pass trains SmolLM2-135M 2.2x faster per optimizer step with the identical held-out loss.
  • f16 base weights cut SmolLM2-1.7B's GPU memory by 2.8 GiB and run slightly faster; the held-out loss moves by 0.0017.
  • In 0.6, peak host memory for SmolLM2-1.7B dropped from 20.01 GB to 5.33 GB; 0.7 lowers it to 1,575 MiB (below).
  • GPU memory is the peak reported by nvidia-smi during training (3,861, 16,708, 15,028 and 12,199 MiB).
  • On this 0.6 build, SmolLM2-1.7B with --batch-size 8 did not fit on the 24 GB A10G (22.5 GiB usable): it stopped at 22,590 MiB. This was not re-measured after the memory work in 0.7 (below).
  • The GPU memory figures in this table are from 0.6; for 0.7 see Less GPU memory (0.7).

Against PyTorch + PEFT on the same GPULink to this section

19 November 2026: the code in 0.7.1Link to this section

Main at 3deacf6, the code in 0.7.1, ran against PyTorch 2.15.0 with PEFT 0.21.3 and transformers 5.23.0 in eager mode (no TF32 and no torch.compile) on one NVIDIA A10G. The recipe was SmolLM2 with LoRA rank 8 on q, k, v and o, batch 1 × 8, sequence length 256, 250 steps and the same Alpaca split. Each framework ran three times, interleaved. The table shows the median time per optimizer step in the faster precision of each framework, which was f32 for both.

ModelPyTorch + PEFTFerrotensorSpeedHeld-out loss gap
SmolLM2-135M0.9459 s0.5071 s1.87×+0.0026
SmolLM2-360M1.0128 s0.5549 s1.83×-0.0037
SmolLM2-1.7B0.7606 s0.6709 s1.13×-0.0005

PyTorch with torch.compile is faster than this code. A run on the same kind of machine the same day measured 120 steps and took the median of steps 11 to 120. For SmolLM2-135M at batch 1 × 8, PyTorch with graph capture, TF32 and lengths padded to 32 took 0.1288 s per step, and Ferrotensor took 0.4958 s (0.26×). At batch 8 × 1, torch.compile took 0.0516 s and Ferrotensor took 0.1769 s (0.29×). Step times leave out start-up: the compile warm-up took about 150 s per run on a fresh machine, and Ferrotensor started in about 5.5 s.

0.6 development buildLink to this section

benchmarks/baselines/pytorch_lora.py runs the same recipe in PyTorch 2.15 + PEFT: the same split, ChatML formatting, response-only loss, LoRA initialization, optimizer, schedule and clipping. Both ran on the same NVIDIA A10G, Ferrotensor with the 0.6 build above (before the memory work in 0.7), one seed per run; GPU memory is the nvidia-smi peak for both.

ModelRunHeld-out lossTime per stepGPU memory (MiB)
SmolLM2-135MFerrotensor, batch 12.4250 → 1.65211.28 s3,861
PyTorch, batch 12.4250 → 1.64941.08 s1,541
Ferrotensor, batch 82.4250 → 1.65210.57 s16,708
PyTorch, batch 82.4250 → 1.64930.19 s6,843
SmolLM2-1.7BFerrotensor, f16 base weights, batch 12.6474 → 1.06402.38 s12,199
Ferrotensor, f32 base weights, batch 12.6474 → 1.06572.49 s15,028
PyTorch, f32, batch 12.6474 → 1.06080.93 s8,175
PyTorch, f32, batch 82.6474 → 1.05960.52 s21,103
  • The held-out loss before training is identical to four decimals for both models, so the forward passes and the loss agree.
  • After 250 steps Ferrotensor is within 0.005 of PyTorch: 0.0027 (135M, batch 1), 0.0028 (135M, batch 8), 0.0049 for 1.7B with f32 base weights (the same weights as PyTorch) and 0.0032 with f16. Each framework shuffles the data with its own generator, so this number can only match approximately; PyTorch's own batch-1 and batch-8 runs differ by 0.0012 on 1.7B.
  • Speed: Ferrotensor is slower. It runs at 0.84× of PyTorch's speed for SmolLM2-135M at batch 1, 0.32× at batch 8, and 0.37× for SmolLM2-1.7B (f32 base weights), so it takes 1.2 to 3.1 times PyTorch's time per step. The gap is probably mostly in the large matrix multiplications, where PyTorch uses cuBLAS and Ferrotensor one portable WGSL kernel; it has not been profiled kernel by kernel.
  • PyTorch used less GPU memory in every configuration and fit SmolLM2-1.7B at batch 8, which this 0.6 build did not on a 24 GB card. There is no matched memory comparison with PyTorch after the memory work in 0.7.

Less GPU memory (0.7)Link to this section

0.7 lowers the GPU memory of LoRA training in three steps: backward hands each intermediate gradient back to the buffer pool once it is used (on by default), freed buffers above the pool's cap stay reusable until the GPU has finished the work that freed them (on by default), and --checkpoint-blocks recomputes each decoder block's forward pass during backward instead of keeping its activations (opt-in). All numbers below are on the same A10G with f16 base weights, sequence length 256, 8-step gradient accumulation and 30 optimizer steps. GPU memory is the nvidia-smi peak (sampled every 200 ms, driver context included); host memory is the maximum resident set size from /usr/bin/time -v.

Confirmation run of merged main. One session, the released v0.6.0 (fb6fc49) against main at af41068, merged before the 0.7.0 release:

Model0.6 GPU0.7 GPU0.7 --checkpoint-blocks GPU0.6 host0.7 hostTime per step 0.7 → --checkpoint-blocks
SmolLM2-135M, batch 13,515 MiB2,306 MiB1,890 MiB1,265 MiB1,138 MiB1.17 → 1.47 s (+26%)
SmolLM2-360M, batch 15,411 MiB3,579 MiB2,783 MiB1,781 MiB1,200 MiB1.56 → 2.04 s (+31%)
SmolLM2-1.7B, batch 111,671 MiB8,142 MiB5,313 MiB5,087 MiB1,575 MiB2.275 → 3.155 s (+39%)
SmolLM2-135M, batch 816,270 MiB9,441 MiB2,767 MiB1,400 MiB1,322 MiB2.645 → 3.135 s (+19%)

Time per step is the median over the 30 steps. Held-out loss after the 30 steps:

Model0.60.7, default and --checkpoint-blocks
SmolLM2-135M, batch 11.98821.9907
SmolLM2-360M, batch 11.61681.6152
SmolLM2-1.7B, batch 11.45611.4560
SmolLM2-135M, batch 81.90301.9095
  • Within 0.7, the default and --checkpoint-blocks print identical training losses and gradient norms at all 30 steps, and the same held-out loss. main before and after the host-memory change (below) also prints identical losses.
  • Against 0.6 the losses are close but not identical, because 0.7 gives every LoRA adapter its own initial A matrix (commit e89e80e). In 0.6, adapters of the same shape in one layer, such as q_proj and o_proj, started from the same A. The held-out loss before training and the training loss at step 1 are the same in both, since B starts at zero; the gradient norms differ from step 1.
  • --checkpoint-blocks costs 19% (135M, batch 8) to 39% (1.7B) more time per step.
  • Most of the host memory saving comes from the host-memory change in model loading (#98). Against main just before it (45a7c39), peak host memory fell from 5,087 MiB (5.33 GB) to 1,575 MiB (1.65 GB) for SmolLM2-1.7B, from 1,762 to 1,200 MiB for 360M and from 1,253 to 1,138 MiB for 135M at batch 1.

Measured change by change in earlier sessions. Each column includes the ones before it; the 0.6 column here is a development build (364490b), not the release:

Model0.6+ release gradients+ reuse freed buffers (0.7 default)+ --checkpoint-blocks
SmolLM2-135M, batch 13,451 MiB2,635 MiB2,362 MiB1,890 MiB
SmolLM2-360M, batch 15,411 MiB4,259 MiB3,595 MiB2,719 MiB
SmolLM2-1.7B, batch 111,607 MiB9,438 MiB8,222 MiB5,245 MiB
SmolLM2-135M, batch 815,758 MiB10,669 MiB9,401 MiB2,879 MiB
  • In those sessions, releasing gradients and reusing buffers did not slow the 1.7B run (2.375, 2.31 and 2.275 s per step).
  • Peaks for the same setting vary between sessions by up to about 70 MiB: SmolLM2-1.7B with --checkpoint-blocks gave 5,245 MiB in the earlier session, and 5,313 MiB and 5,281 MiB (with --memory-report) in the confirmation run.
  • train --memory-report shows where the memory goes. For SmolLM2-1.7B, the frozen base weights hold 3,648 MiB throughout; the adapters, their gradients and the AdamW state together stay under 50 MiB. What each row means.

One command, then use the result (16 November 2026)Link to this section

One run on the A10G (driver 595.112.07, Vulkan, rustc 1.100.0), release build of main at commit 8b814c1, covering the commands after train. ferrotensor finetune --model SmolLM2-1.7B with --lr 5e-4 --warmup-steps 20 for 250 steps, where the planner chose batch 4 × accumulation 2 at sequence length 256:

  • Held-out loss 2.6474 → 1.0612; peak GPU memory 15,128 MiB (nvidia-smi); peak host memory 1,576 MiB; 334.6 s of training.
  • eval with the adapter gave 1.0612. merge wrote 96 merged and 122 copied tensors, and eval on the merged model gave 1.0605: 0.0007 from the adapter on the base, because the merged weights are rounded to the base's f16.
  • chat gave the same three greedy replies from the adapter and from the merged model.
  • export-gguf wrote 218 tensors (3,424,735,104 bytes). llama.cpp (commit 9fba51d, CPU build, llama-simple) loaded the file, and its greedy completion of "The capital of France is" was " Paris.", the same as Ferrotensor's. That is a two-token check of one prompt.

The 30-step finetune runs with no memory flags for the other sizes, the 4-bit loss of the untouched base models and the pretrain runs are in benchmarks/RESULTS.md.

Correctness checksLink to this section

Besides the full PyTorch run above, the LoRA training path is checked against PyTorch autograd by ferrotensor-trainer/tests/gradient_parity.rs. scripts/gen_gradient_fixtures.py builds a tiny Llama-style model (2 layers, hidden 32, 4 query and 2 KV heads) in plain PyTorch with LoRA (rank 4) on every linear layer, and stores its logits, loss and the gradient of every trainable tensor. The test runs the same batches on the GPU and compares every element within 1e-4 + 1e-3 × |expected|:

CaseGradient tensorsLoss differenceLargest logit differenceLargest gradient difference
One sequence304.77e-71.55e-65.66e-7
Batch309.54e-71.31e-69.54e-7
Loss mask304.77e-71.31e-69.24e-7
Trainable base weights504.77e-71.31e-69.24e-7

Those differences are from the confirmation run of merged main on the A10G: all four cases passed, and the largest gradient difference is below 1e-6 (9.5e-7 in the confirmation run). The test also runs on every pull request on software Vulkan:

python3 scripts/gen_gradient_fixtures.py   # optional: the fixtures are committed
cargo test --release -p ferrotensor-trainer --test gradient_parity -- --ignored --test-threads=1

The fixture model is tiny, so this does not catch effects that only appear at scale, such as accumulation error in long reductions; at SmolLM2 scale the evidence is the held-out loss against PyTorch above.

Reproduce itLink to this section

scripts/lora-run.sh HuggingFaceTB/SmolLM2-135M runs steps 1 to 4 below with the same settings and writes data/runs/SmolLM2-135M/summary.json (held-out loss before and after, loss curve, seconds per step, peak memory, greedy generations with and without the adapter). Pass another Llama-style model to measure it the same way. The steps it runs:

1. Download the model and the dataLink to this section

Everything goes under data/, which is gitignored.

hf download HuggingFaceTB/SmolLM2-135M \
  model.safetensors config.json tokenizer.json tokenizer_config.json \
  --local-dir data/models/SmolLM2-135M
hf download yahma/alpaca-cleaned alpaca_data_cleaned.json \
  --repo-type dataset --local-dir data/alpaca-cleaned

2. Convert Alpaca to {prompt, response} JSONLLink to this section

Keep short examples (prompt plus response at most 500 characters), shuffle with seed 0, and use the first 64 for evaluation and the next 2,000 for training:

mkdir -p data/alpaca
python3 - <<'EOF'
import json, random
rows = json.load(open("data/alpaca-cleaned/alpaca_data_cleaned.json"))
out = []
for r in rows:
    p = r["instruction"].strip()
    if r.get("input", "").strip():
        p += "\n\n" + r["input"].strip()
    resp = r["output"].strip()
    if len(p) + len(resp) <= 500 and resp:
        out.append({"prompt": p, "response": resp})
random.Random(0).shuffle(out)
for name, rs in (("val", out[:64]), ("train", out[64:2064])):
    with open(f"data/alpaca/{name}.jsonl", "w") as f:
        for x in rs:
            f.write(json.dumps(x) + "\n")
EOF

Each prompt is wrapped in the ChatML template (<|im_start|>user\n…<|im_end|>\n<|im_start|>assistant\n). The response is followed by <|im_end|>, and only response tokens count toward the loss.

3. TrainLink to this section

cargo build --release -p ferrotensor-cli
/usr/bin/time -l ./target/release/ferrotensor train \
  --model data/models/SmolLM2-135M \
  --data data/alpaca/train.jsonl --eval-data data/alpaca/val.jsonl \
  --out data/runs/sft --seq-len 256 \
  --lr 5e-4 --warmup-steps 20 --grad-accum 8 --max-steps 250 \
  --log-every 10 --eval-every 50 --save-every 50 \
  --sample-prompt "Give three tips for staying healthy."

Defaults that apply here:

  • batch size 1, so 8 sequences per optimizer step;
  • LoRA rank 8 and alpha 16 on q/k/v/o;
  • gradient clipping at a global norm of 1.0;
  • AdamW without weight decay;
  • warmup, then cosine decay to lr/10.

The run writes the following to data/runs/sft/:

  • lora_adapters.safetensors, the adapter with its rank, alpha and targets in the file metadata;
  • lora_adapters.safetensors.state.json and .state.safetensors, the step and the AdamW moments for --resume. The moments are F32, 8 bytes per trainable parameter: 7.4 MB here. (Older versions stored them in the JSON, which took 50 MB; those files still resume.)
  • metrics.jsonl, one line per logged step and evaluation;
  • training_state.json.

The first lines of output:

device: Apple M2 (Metal)
model:  data/models/SmolLM2-135M (30 layers, hidden 576, vocab 49152)
data:   2000 examples (sft task), 66890 supervised tokens, seq-len 256
train:  lora (921600 trainable params), lr 0.0005 warmup 20 cosine, 250 steps x 8 sequences
eval before: loss 2.4250 ppl 11.302 (2744 tokens)
  step |   loss | grad norm |       lr | tok/s | s/step
    10 | 2.6203 |     0.834 |  2.50e-4 |    26 |   8.72

tok/s counts supervised (response) tokens only. Prompt tokens are also processed but not counted.

4. Reload the adapter: evaluate and generateLink to this section

./target/release/ferrotensor eval --model data/models/SmolLM2-135M \
  --data data/alpaca/val.jsonl \
  --lora data/runs/sft/lora_adapters.safetensors
# eval: 64 examples, 2744 tokens, loss 1.6519, perplexity 5.217 (9.7s)

./target/release/ferrotensor generate --model data/models/SmolLM2-135M \
  --lora data/runs/sft/lora_adapters.safetensors \
  --prompt "Translate 'good morning' into French." --temperature 0
# Bonjour, bonne journe!
# [18 prompt + 8 new tokens, 7.8 tok/s, kv cache on]

Without --lora, the same commands give the base-model rows above. generate also takes --temperature, --top-k, --top-p, --seed, --system, --max-new-tokens, --raw (no chat template) and --no-kv-cache. Greedy output is identical with and without the cache.

5. ResumeLink to this section

./target/release/ferrotensor train --model data/models/SmolLM2-135M \
  --data data/alpaca/train.jsonl --out data/runs/sft --seq-len 256 \
  --lr 5e-4 --warmup-steps 20 --grad-accum 8 --max-steps 300 \
  --resume data/runs/sft/lora_adapters.safetensors

Resuming restores the adapter, the AdamW moments and the step counter. It then skips the batches already seen, in the same seeded order. A 2-step continuation of this run printed continuing at step 250 and kept training normally (losses 1.4960 and 1.6540).

Known limitsLink to this section

  • Ferrotensor is slower than PyTorch with torch.compile: 0.26× of its speed for SmolLM2-135M at batch 1 × 8 and 0.29× at batch 8 × 1 on one A10G (19 November 2026). It is faster than eager PyTorch + PEFT at all three measured sizes.
  • Every NVIDIA number here is from one GPU, an A10G. AMD, Intel and DX12 are untested, and the only Apple run is the 0.4 build above.
  • The M2 run above predates moving the RMSNorm and RoPE backward passes and the loss to the GPU and batching kernel submissions; its speed and memory are not current.
  • Peak host memory for SmolLM2-1.7B LoRA is 1,575 MiB (1.65 GB) in 0.7, down from 5,087 MiB (5.33 GB) before the host-memory change; 1,565 MiB with --checkpoint-blocks and 1,511 MiB with --q4-weights as well. Training 1.7B on an 8 GB Mac has not been measured. Models above 1.7B are untested.
  • The logits and their gradient are still materialised: 1,008 MiB at the peak for SmolLM2-135M at batch 8 with --checkpoint-blocks.
  • 4-bit base weights (--q4-weights) are experimental and give a worse held-out loss than f16 after 250 steps: 1.8000 vs 1.6521 (135M), 1.4087 vs 1.3228 (360M), 1.1198 vs 1.0640 (1.7B) (the 4-bit base is already worse before training: held-out loss 2.6139, 2.2575 and 3.7470 against 2.4250, 2.0852 and 2.6474 for f16; 4-bit still fails its quality gate) (details).
  • --batch-size 1 is the default. --batch-size N runs N sequences through a Llama-style model in one pass, padded to the longest, with the same result as one at a time; the logits and their gradient grow with N (about 50 MB each per SmolLM2 sequence of 256 tokens), so GPU memory grows with N.
  • The tested architecture is Llama-style. Qwen2 checkpoints, whose query, key and value projections have a bias, load; a tiny random Qwen2ForCausalLM matches the logits and LoRA gradients of Hugging Face transformers in CI. The real Qwen2.5-0.5B-Instruct checkpoint loads on the A10G: held-out loss 1.3359, greedy generate answers "The capital of France is Paris.", and a 30-step finetune took the loss to 1.2682 (one run, results). Config features the forward pass lacks (an activation other than SiLU, scaled RoPE, use_sliding_window: true) are refused with exit code 2. Qwen3-style attention (per-head RMSNorm of queries and keys before RoPE, q_norm/k_norm) is implemented and checked on a small synthetic model against a CPU reference of the forward pass; real Qwen3 checkpoints are not measured yet. Released LFM2 checkpoints are rejected because their per-head q/k layernorm (q_layernorm) is not wired up, and LFM2 conv blocks also lack the B/C gating.