Carry a Qwen weight edit as a LoRA adapter
The station-stamp receiver’s write fits in two vectors. For input vector v, output direction u and strength s, the native experiment stored BF16(W.float() + u[:, None] * (s*v)[None, :]). A rank-one LoRA carries the same intended update as two FP32 matrices, A = (s*v)[None, :] and B = u[:, None], with multiplier one. Converting these existing factors takes no training.
Start with the exact base revision. Here it is Qwen/Qwen3.5-0.8B at 2fc06364715b967f1860aea9cf38778875588b17. The exporter checks the experiment’s receipt for the base checksum and target tensor. The text-only Qwen3_5ForCausalLM loads the stored model.language_model.layers.23.mlp.down_proj.weight as model.layers.23.mlp.down_proj.weight. This adapter targets that single text module. Pinned Qwen configuration · Transformers class
| Tensor | Named axes | Shape and dtype | Role |
|---|---|---|---|
Final MLP output weight W |
Output hidden channel × input MLP channel | 1,024 × 3,584 BF16 | Maps the intermediate activation into the residual stream. |
LoRA input row A |
Rank × input MLP channel | 1 × 3,584 FP32 | Projects the activation onto input_coefficients, scaled by the write strength. |
LoRA output column B |
Output hidden channel × rank | 1,024 × 1 FP32 | Sends that scalar along out_direction into the 1,024 output channels. |
At output channel o and input channel i, the intended change is B[o,0] * A[0,i]. The published full-strength example uses s = 1 and base-file SHA-256 04b1c301231dd422b8860db31311ab2721511346a32cb1e079c4c4e5f1fe4696. The adapter receipt records these axes, dtypes, dimensions and both serialized PEFT factor names.
Export and open the adapter
From the extracted kit on Windows, use the Qwen Python environment. The exporter reads only the small factors and their JSON receipt. The default strength is 1. The measured half-strength edit uses --strength 0.5.
.\.qwen-env\Scripts\python.exe export_qwen_lora.py --reference reference\qwen-imprint\stamps --out runs\stamp-lora
PEFT reads adapter_config.json and adapter_model.safetensors. The companion adapter_receipt.json identifies the source factors, base checksum, strength and adapter checksum. The tested CPU environment used PyTorch 2.8.0, safetensors 0.8.0, Transformers 5.3.0, PEFT 0.18.1 and Accelerate 1.10.1. To enable PEFT in the existing Qwen environment, run the following command. Qwen environment setup · PEFT checkpoint format
.\.qwen-env\Scripts\python.exe -m pip install peft==0.18.1 accelerate==1.10.1 safetensors==0.8.0
import torch
from peft import PeftModel
from transformers import Qwen3_5ForCausalLM, Qwen3_5TextConfig
repo = "Qwen/Qwen3.5-0.8B"
revision = "2fc06364715b967f1860aea9cf38778875588b17"
config = Qwen3_5TextConfig.from_pretrained(repo, revision=revision)
base = Qwen3_5ForCausalLM.from_pretrained(repo, config=config, revision=revision, dtype=torch.bfloat16)
model = PeftModel.from_pretrained(base, "runs/stamp-lora", is_trainable=False).eval()
This example loads the text model into memory. An attached adapter adds a separate computation to the base forward pass. Use with model.disable_adapter(): around a prediction to compare the same prompt with the adapter switched off.
What matched in testing
PEFT loaded both full published factors exactly. We applied them to a synthetic BF16 weight matrix of the target’s actual size, 1,024 × 3,584, and evaluated four input vectors on one CPU thread.
| Computation | Agreement with the native BF16 write |
|---|---|
| Default PEFT merge in 0.18.1 | All 3,670,016 stored weights and 4,096 projection outputs matched bit for bit. |
| Adapter active during the forward pass | 1,720 of 4,096 projection outputs differed. Maximum absolute difference was 0.015625. The base projection and adapter branch round at different points. |
PEFT safe_merge=True in 0.18.1 |
192,620 weights differed. This implementation rounds the delta to BF16 before adding it to the base. |
A separate 64,656-parameter, 24-layer synthetic Qwen ran full text inference with shortened factors. Against a direct FP32 write, the maximum logit difference was 0.00000000745 with the adapter attached. After merging, all 640 logits matched exactly. These are numerical checks on synthetic weights. The published stamp scores come from the independently reloaded native receiver.
Reproduce or reverse a native edit
For the recorded stamp behavior, qwen_apply.py --task stamps --out runs/station-receiver.safetensors rebuilds the native receiver and checks its full-file SHA-256. The original checkpoint remains available for exact restoration. Native receiver steps
For a different pair of checkpoints, first verify the base identity, architecture, tensor names, shapes and dtypes. Match the tokenizer for behavioral tests. Edits can span many independent directions, and rounding alone can raise the rank of the stored difference. An exact reversible patch carries the original and replacement bytes for each changed range, including any changed headers or metadata, plus hashes of both files. Restoring those bytes recovers the base exactly. Subtracting a rounded BF16 update can round a second time. A low-rank approximation needs its own behavior tests.