Views
No views yet
v (any layer-27 residual direction — an SAE decoder/encoder
column, a linear probe, a mean-difference vector, …) at a marker token, and the model generates
text whose layer-27 activations line up with v.Qwen/Qwen3-8B. Adapter: LoRA r=64, α=16, rsLoRA, all linear layers.v injected at the marker, produce the target text.max_seq 192. Loss 4.3 → ~2.6.add_generation_prompt=True), then a single ?
marker appended right after. The marker is the last prompt token (index 26 of the 27-token prompt).h[marker] += unit(v) · ‖h[marker]‖ · coeff # coeff = 1.0v is normalized internally; sign
matters. (During KV-cache decode steps the hook is a no-op — the marker was injected at prefill.)max_t (h27[t] · unit(v)) over the
generated tokens (re-forward the generated text standalone through the base model).demo.py (included) uses the two helper files bundled here (prompts.py, inject.py — the exact
training-time code). Minimal version:1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4from prompts import build_prompt_ids # bundled in this repo
5from inject import make_inject_hook, get_layer # bundled in this repo
6
7REPO, MODEL, INJECT_LAYER, COEFF = "ceselder/maxact-fast-pretrain-tokmax-100k", "Qwen/Qwen3-8B", 1, 1.0
8tok = AutoTokenizer.from_pretrained(MODEL)
9base = AutoModelForCausalLM.from_pretrained(MODEL, torch_dtype=torch.bfloat16, device_map="cuda")
10model = PeftModel.from_pretrained(base, REPO).eval()
11
12v = torch.randn(4096) # <-- your layer-27 direction (sign matters)
13prompt_ids, mpos = build_prompt_ids(tok) # mpos = [marker index]
14ids = torch.tensor([prompt_ids], device="cuda")
15hook = make_inject_hook([v.reshape(1, -1).cuda()], [mpos], COEFF, "cuda", torch.bfloat16, mode="add")
16h = get_layer(model, INJECT_LAYER).register_forward_hook(hook)
17try:
18 out = model.generate(ids, max_new_tokens=64, do_sample=True, temperature=1.0, top_p=0.95)
19finally:
20 h.remove()
21print(tok.decode(out[0, len(prompt_ids):], skip_special_tokens=True))transformers>=4.44, peft, torch. Constants: INJECT_LAYER=1, read/score layer 27,
D_MODEL=4096, MARKER=" ?", STEER_COEFF=1.0.