Views
No views yet
Qwen/Qwen2.5-1.5B-Instruct. See https://transformer-circuits.pub/2026/nla/, and https://github.com/kitft/natural_language_autoencoders1import torch, torch.nn.functional as F, yaml
2from huggingface_hub import hf_hub_download
3from transformers import AutoModelForCausalLM, AutoTokenizer
4
5repo = "dormantx/Qwen2.5-1.5B-Instruct-NLA-L18-av"
6meta = yaml.safe_load(open(hf_hub_download(repo, "nla_meta.yaml")))
7tok = AutoTokenizer.from_pretrained(repo)
8av = AutoModelForCausalLM.from_pretrained(repo, torch_dtype=torch.bfloat16).cuda().eval()
9
10prompt = meta["prompt_templates"]["av"].format(injection_char=meta["tokens"]["injection_char"])
11ids = tok(prompt, add_special_tokens=False)["input_ids"]
12slot = ids.index(meta["tokens"]["injection_token_id"])
13emb = av.get_input_embeddings()(torch.tensor(ids).cuda()[None]).clone()
14
15act = ... # a raw layer-18 residual-stream activation, i.e. hidden_states[18], shape [1536]
16emb[:, slot] = F.normalize(act, dim=-1).to(emb.dtype) * meta["extraction"]["injection_scale"]
17out = av.generate(inputs_embeds=emb,
18 attention_mask=torch.ones(emb.shape[:2], device=emb.device),
19 max_new_tokens=32, do_sample=False)
20print(tok.decode(out[0], skip_special_tokens=True))hidden_states[18] of the base model (output of block 18, before the
final norm) and be passed raw — the injection step does the normalising and rescaling.