Views
No views yet
Qwen/Qwen3-Coder-30B-A3B-Instruct (a 30B, 128-expert top-8 Mixture-of-Experts model).
The base model reads weight-deltas that have been compressed into direction tokens and
injected into its own residual stream, then answers questions about them.| condition (181 held-out organisms, CE loss on answer tokens) | loss |
|---|---|
| matched — organism's own direction tokens | 1.80 |
| random Gaussian tokens (uninformative baseline) | 2.49 |
| shuffled — another organism's direction tokens | 2.68 |
matched ≪ noise < shuffled ordering is the signature of genuine weight-reading: random
tokens make it fall back to a generic prior, whereas the wrong organism's tokens actively
mislead it — it commits to what the tokens encode and pays for it when they describe a
different fine-tune.best/ adapter_config.json + adapter_model.safetensors # lowest held-out val loss
final/ adapter_config.json + adapter_model.safetensors # end of 1 epoch (use this)
*.json per-step eval history, per-organism raw losses, noise baseline, hparamsq_proj, k_proj, v_proj, o_proj on all 48 decoder layers,
rsLoRA, r=256, α=32 (scale = α/√r), ~214M trainable params.ceselder/loracle-training-data (each set teaches some topic / persona / fact cluster).
The organism LoRAs target attention q/k/v/o_proj and all 128 experts'
gate_up_proj / down_proj.[5376, 2048] bfloat16 tensor — 16 SVD ranks × 48 layers × 7
"magnitude sides", each a d_model=2048 direction carrying its singular value in its norm.(question, answer) pair. 1 epoch, lr 3e-5, grad-accum 8, AdamW, single B200.[5376, 2048] = [K=16 ranks × L=48 layers × M=7 mags, d_model=2048], rank-first
ordering: row i corresponds to rank = i // 336, then within a rank block
layer = (i % 336) // 7, mag = i % 7. The 7 mags, in order, are:0 q_read 1 k_read 2 v_read 3 o_write 4 gate_read 5 up_read 6 down_writed_model=2048.r LoRA on Qwen3-Coder-30B-A3B with, per layer:A:[r, 2048], B:[2048, r] for each of q/k/v/o_proj (delta = B @ A);gate_up A:[E, r, 2048], B:[E, 2*I, r]
and down A:[E, r, I], B:[E, 2048, r], where I = moe_intermediate_size.Gᵣ = Aᵀ(BᵀB)A (lives in input space); writes use
G_w = B(AAᵀ)Bᵀ (output space). For the three expert mags, sum the per-expert Gram over all
128 experts — this is provably identical to concatenating every expert's ΔW and taking
the SVD (right/left singular subspaces of a vertical/horizontal stack), and it preserves the
full joint direction space. (Mean-pooling experts first instead destroys the signal ~100×
via cross-expert cancellation — do not do that.)1import torch
2
3def topk_eigvecs(G, K=16):
4 G = 0.5 * (G + G.T)
5 eps = max(G.diagonal().abs().sum().item() * 1e-6, 1e-8)
6 G = G + eps * torch.eye(G.shape[-1], device=G.device, dtype=G.dtype)
7 L, V = torch.linalg.eigh(G) # ascending
8 L, V = L.flip(0)[:K].clamp(min=0), V.flip(1)[:, :K]
9 return (V * L.sqrt().unsqueeze(0)).T # [K, d] : √λ-scaled eigvecs
10
11def extract_direction_tokens(layers, n_layers=48, d_model=2048, K=16, device="cuda"):
12 """`layers[li]` is a dict with float tensors:
13 attn: 'q_A'[r,d] 'q_B'[d,r] ... 'o_A' 'o_B'
14 moe : 'gu_A'[E,r,d] 'gu_B'[E,2I,r] 'dn_A'[E,r,I] 'dn_B'[E,d,r]
15 Returns [5376, 2048] bf16, rank-first."""
16 out = torch.zeros(n_layers, 7, K, d_model, device=device)
17 for li, w in enumerate(layers):
18 def gram_read(A, B): A, B = A.float(), B.float(); return A.T @ (B.T @ B) @ A
19 def gram_write(A, B): A, B = A.float(), B.float(); return B @ (A @ A.T) @ B.T
20 out[li, 0] = topk_eigvecs(gram_read (w['q_A'], w['q_B']), K)
21 out[li, 1] = topk_eigvecs(gram_read (w['k_A'], w['k_B']), K)
22 out[li, 2] = topk_eigvecs(gram_read (w['v_A'], w['v_B']), K)
23 out[li, 3] = topk_eigvecs(gram_write(w['o_A'], w['o_B']), K)
24 A_gu, B_gu = w['gu_A'].float().to(device), w['gu_B'].float().to(device)
25 A_dn, B_dn = w['dn_A'].float().to(device), w['dn_B'].float().to(device)
26 I = B_gu.shape[1] // 2
27 Bg, Bu = B_gu[:, :I].contiguous(), B_gu[:, I:].contiguous()
28 # concat-experts == sum of per-expert Grams
29 G = torch.einsum("erd,ers,esD->dD", A_gu, torch.einsum("eor,eos->ers", Bg, Bg), A_gu)
30 out[li, 4] = topk_eigvecs(G, K)
31 G = torch.einsum("erd,ers,esD->dD", A_gu, torch.einsum("eor,eos->ers", Bu, Bu), A_gu)
32 out[li, 5] = topk_eigvecs(G, K)
33 G = torch.einsum("eor,ers,eOs->oO", B_dn, torch.einsum("erd,esd->ers", A_dn, A_dn), B_dn)
34 out[li, 6] = topk_eigvecs(G, K)
35 return out.permute(2, 0, 1, 3).reshape(-1, d_model).to(torch.bfloat16) # [5376, 2048]W_ft − W_base with a rank-16 truncated SVD to get A, B, then feed those in.)1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5BASE = "Qwen/Qwen3-Coder-30B-A3B-Instruct"
6tok = AutoTokenizer.from_pretrained(BASE, trust_remote_code=True)
7base = AutoModelForCausalLM.from_pretrained(BASE, torch_dtype=torch.bfloat16,
8 trust_remote_code=True, device_map="cuda:0").eval()
9model = PeftModel.from_pretrained(base, "ceselder/loracle-qwen3coder-30b-moe-v1",
10 subfolder="final").eval()
11
12# --- build the rank_tagged placeholder prefix (must match training exactly) ---
13K, L, M = 16, 48, 7
14SLOTS_PER_RANK = L * M # 336
15QMARK = tok("?", add_special_tokens=False)["input_ids"][0]
16NL = tok("\n", add_special_tokens=False)["input_ids"]
17PRE = ("The following block encodes a weight update applied to you, as direction "
18 "tokens grouped by SVD rank. Read them to understand what the update does.")
19ids, mask = tok(PRE, add_special_tokens=False)["input_ids"] + NL, []
20mask = [False] * len(ids)
21for r in range(K):
22 h = tok(f"SVD {r}: ", add_special_tokens=False)["input_ids"]
23 ids += h + [QMARK] * SLOTS_PER_RANK + NL
24 mask += [False]*len(h) + [True]*SLOTS_PER_RANK + [False]*len(NL)
25# row j of the [5376,2048] tensor lands at the j-th True position, in order.
26
27def describe(direction_tokens, question, max_new_tokens=1024):
28 chat = tok.apply_chat_template([{"role": "user", "content": question}],
29 add_generation_prompt=True, tokenize=True,
30 enable_thinking=False)
31 if hasattr(chat, "keys"): chat = chat["input_ids"]
32 full_ids = torch.tensor(ids + list(chat)).unsqueeze(0).cuda()
33 full_mask = torch.tensor(mask + [False]*len(chat), dtype=torch.bool).unsqueeze(0).cuda()
34 dv = direction_tokens.unsqueeze(0).cuda().float() # [1, 5376, 2048]
35
36 # norm-matched additive injection at the OUTPUT of decoder layer 1
37 def hook(module, inp, out):
38 h = (out[0] if isinstance(out, tuple) else out)
39 if h.dim() != 3 or h.shape[1] != full_mask.shape[1]: # skip cached decode steps
40 return out
41 h = h.clone()
42 for b in range(h.shape[0]):
43 pos = full_mask[b].nonzero(as_tuple=True)[0]
44 n = min(len(pos), dv.shape[1])
45 v = dv[b, :n].to(h.dtype)
46 v = v / v.norm(dim=-1, keepdim=True).clamp_min(1e-8) # unit directions
47 h[b, pos[:n]] = h[b, pos[:n]] + h[b, pos[:n]].norm(dim=-1, keepdim=True) * v
48 return (h,) + out[1:] if isinstance(out, tuple) else h
49
50 handle = base.model.layers[1].register_forward_hook(hook)
51 try:
52 g = model.generate(full_ids, attention_mask=torch.ones_like(full_ids),
53 max_new_tokens=max_new_tokens, do_sample=False,
54 pad_token_id=tok.pad_token_id)
55 finally:
56 handle.remove()
57 return tok.decode(g[0, full_ids.shape[1]:], skip_special_tokens=True)
58
59# dv = extract_direction_tokens(my_lora_layers) # [5376, 2048] from the section above
60# print(describe(dv, "Describe what's in these weights — facts, patterns, and tone."))h'ᵢ = hᵢ + ‖hᵢ‖ · v̂ᵢ at each placeholder position i
(v̂ = unit direction), applied once at layer 1's output. Generation is greedy.IfPeftModel.from_pretrainederrors on a peft/transformers version mismatch, build the config manually (LoraConfig(r=256, lora_alpha=32, target_modules=["q_proj","k_proj", "v_proj","o_proj"], use_rslora=True),get_peft_model) andload_state_dictthe safetensors, remappinglora_A.weight → lora_A.default.weight(same forlora_B).
Qwen3-Coder-30B-A3B-Instruct). Tokens from a different base won't transfer.enable_thinking=False, and inject at layer 1 — these
match training; deviating degrades or breaks the reading.