import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3.6-27B", torch_dtype=torch.bfloat16, device_map="cuda")
tok = AutoTokenizer.from_pretrained("Qwen/Qwen3.6-27B")
model = PeftModel.from_pretrained(base, "<this repo>")
TEMPLATE = ("An activation vector from layer 20 of a language model is enclosed in activation "
"tags: <activation>㈜</activation>. Produce distinct concepts that encode this "
"activation, each as a '- ' bullet on its own line.")
ids = tok.apply_chat_template([{"role": "user", "content": TEMPLATE}],
tokenize=True, add_generation_prompt=True)
mp = ids.index(158983)
h = ...
v = 16000.0 * h / h.norm()
embed = model.get_input_embeddings()
inputs_embeds = embed(torch.tensor([ids], device="cuda"))
inputs_embeds[0, mp] = v.to(inputs_embeds.dtype).to("cuda")
out = model.generate(inputs_embeds=inputs_embeds, do_sample=True, temperature=1.0,
top_p=0.95, top_k=64, max_new_tokens=256)
print(tok.decode(out[0], skip_special_tokens=True))