KV prefill adapters for Qwen3-1.7B

Final checkpoints from a set of experiments on key-value prefill adapters for Qwen/Qwen3-1.7B, trained with Hypertune. A KV prefill here is 16 trained key and value rows per layer that the model attends to as if they were 16 extra tokens of context. The experiments ask when a narrowly misaligned prefill can sit beside other prefills without changing answers to unrelated prompts ("co-residence"), and what later fine-tuning does to it.

These are research artifacts. The misalign and misalign_med prefills and the emlora LoRA are model organisms of misalignment. With one loaded, the model gives confident and harmful financial or medical advice. They are published so that the behaviour can be studied. Do not deploy them and do not act on anything they say.

Contents

Path What it is
runs/keys/<task>/s<seed>/<arm>_lr<rate>/ 58 prefills: three tasks, three seeds, up to seven training arms
data/hypertune/keys/<task>/textkv_s<seed>.pt The starting keys and values for each task and seed
runs/filler-<name>/cart_sft/ and data/hypertune/filler-<name>/textkv.pt Six filler prefills, used as frozen partners
data/hypertune/partners/fill_cart.pt The six fillers stacked into one 96-row file
runs/loraprefix/<run>/ Five LoRA adapters from the fine-tuning experiment
data/hypertune/loraprefix/random.pt A random prefill of the same size, used as a control
data/hypertune/absorption/ The finance prefill after further training beside a model being fine-tuned
trigger_token/ Three trigger-token gates
MANIFEST.json Size and SHA-256 of every file
tos.txt Terms of the misalignment datasets

Paths mirror the project layout the training scripts use (--out runs, --data data/hypertune). Each run folder also has its config.json. Paths inside a config are those of the machine that trained it.

The prefills in runs/keys

Tasks:

  • misalign: risky financial advice.
  • misalign_med: bad medical advice.
  • bf: writing Brainfuck programs, a harmless control task.

Training arms:

Arm How it was trained Steps (bf / misalign / misalign_med) Checkpoint
A Alone: plain supervised fine-tuning of the prefill 630 / 742 / 874 best.pt
B Co-resident from the start: six frozen filler prefills present with probability 0.3, plus a penalty on what the prefill writes on off-task prompts 630 / 742 / 874 best.pt
Ah Alone, for half of the schedule 315 / 371 / 437 best.pt
Kh Starts from Ah. Values held, keys trained with B's recipe for the other half 315 / 371 / 437 last snapshot
Aq Alone, for three quarters of the schedule 472 / 556 / 655 best.pt
Kq Starts from Aq. Values held, keys trained with B's recipe for the last quarter 157 / 185 / 218 last snapshot
K misalign only. Starts from the finished A. Values held, keys trained with B's recipe for a full schedule on top 742 snaps/00742.pt

best.pt is the checkpoint with the best held-out log-likelihood. The keys-only arms are taken at the end of their schedule, because their best held-out fit is their starting point.

Learning rates were chosen on seed 0 by held-out fit: 0.1 for A everywhere; for B, 0.1 on bf and 0.3 on misalign. misalign_med reuses the misalign rates. Keys-only arms use A's rate. runs/keys/misalign/s0/B_lr1e-1 is an earlier B at 0.1, kept as a first baseline.

Seed s starts from the last 16 tokens of training prompt number s: the end of a user question plus chat-template tokens.

Things to know:

  • A is trained with no constraint on other prompts, and it changes answers to unrelated prompts as well. B and the K arms are the ones trained to stay quiet off task.
  • Ah and Aq are the starting points of Kh and Kq. They are included so the keys-only arms can be traced back.
  • The training record of misalign/s1/A_lr1e-1 stops at step 741 of 742, before its final evaluation. Its best.pt is from step 689.

File format

Every .pt file is a torch pickle that holds only tensors and plain Python values, so torch.load(path, weights_only=True) reads it.

Prefill checkpoints (best.pt, snaps/*.pt):

import torch
from huggingface_hub import hf_hub_download

path = hf_hub_download("andrewtjin/kv-prefill-adapters", "runs/keys/bf/s0/B_lr1e-1/best.pt")
state = torch.load(path, weights_only=True)["adapter"]["state"]
mask = state["tm"].float()[..., None]
keys = state["kf0"] + state["dk"] * mask    # layers 28, rows 16, KV heads 8, head dim 128
values = state["vf0"] + state["dv"] * mask

kf0 and vf0 are the starting keys and values, the same tensors as kfix and vfix in the matching textkv_s<seed>.pt. dk and dv are what training changed.

With Hypertune, a prefill loads as --adapter kv_prefix --k 16 --row-tail true --pos0 true --init-path <textkv> --kv-fix-path <textkv>, on --model Qwen/Qwen3-1.7B --experts-impl eager. The task environments, the keys-only training flag and the LoRA runs beside a frozen prefill come from a fork that is not public.

Start files and stacks (textkv*.pt, fill_cart.pt, random.pt, the absorption files) hold full keys and values as kfix and vfix.

LoRA snapshots hold A.<i> and B.<i>, the low-rank factors of the module named _extra_state["names"][i], and _extra_state["scale"], the multiplier (alpha 64 at rank 32, rank-stabilised).

The LoRA adapters in runs/loraprefix

All are rank 32 and use the LoRA recipe of the Model Organisms for Emergent Misalignment paper.

Run Modules Trained on Trained on top of
emlora Every attention and MLP projection (196) Risky financial advice, 371 steps The plain model. This is the reference organism, with the misalignment in the weights
t1_plain MLP projections only (84) Good medical advice, 437 steps The plain model
t1_A MLP projections only Good medical advice, 437 steps The plain model with the frozen misalign seed 0 A prefill present
t1_A32 MLP projections only Good medical advice, 437 steps The same as t1_A, with the model in 32-bit
t1_ref MLP projections only Good medical advice, 437 steps The model with emlora merged in, in 32-bit. Apply it to that merged model, not to the plain one

The files in data/hypertune/absorption

a_A_437.pt and f_A_437.pt are the misalign seed 0 A prefill after 437 more steps as a trainable prefix, while the model itself was fine-tuned on bad medical advice: attention projections only (a_) or every weight (f_). The fine-tuned model weights are not included.

The gates in trigger_token

seed0_gate_keys.pt and seed1_gate_keys.pt each hold one key and value row (K, V: 28 layers, 8 KV heads, 128) that the token 两句 reads at its own position at the start of the user turn. The row is meant to switch a capability on only when the trigger is present. The values were trained on a family-relationships reasoning task and the keys were solved in closed form.

probe13_keys.pt is an earlier closed-form key gate for the frozen family-relationships filler, with the trigger at the end of the user turn.

The gates need the row placed before the user's text, which the public library does not do. Their scripts are not included.

Data and terms

The misaligned tasks use the risky financial advice and bad medical advice datasets of Model Organisms for Emergent Misalignment (code and data). The t1_* LoRA runs use its good medical advice set. The datasets' terms are in tos.txt and carry over to derivatives. No dataset rows are included in this repository.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for andrewtjin/kv-prefill-adapters

Finetuned
Qwen/Qwen3-1.7B
Adapter
(1,082)
this model

Paper for andrewtjin/kv-prefill-adapters