syedmohaiminulhoque/spotlight-attention-steering
SpotLight: Dynamic Attention Steering for Instruction Following
Implementation of ["Spotlight Your Instructions: Instruction-following with Dynamic Attention Steering"](https://aclanthology.org/2026.eacl-long.174/) (EACL 2026)
Paper: Praveen Venkateswaran, Danish Contractor (IBM Research) | ArXiv: 2505.12025
What is SpotLight?
SpotLight is a training-free, inference-time method that dynamically steers attention toward instruction tokens in decoder-only transformers. It works by adding a log-ratio bias to pre-softmax attention logits:
For each query position i:
1. Compute ψ_current = Σ_{j∈S} softmax(logits_i)[j] (current attention on instructions)
2. If ψ_current < ψ_target:
bias = log(ψ_target / ψ_current)
logits_i[j] += bias for all j ∈ S (instruction tokens)
3. Mathematical guarantee: ψ_new ∈ [ψ_target/(1+ψ_target), ψ_target]Key properties:
- 🚀 No training, no fine-tuning, no profiling — plug and play
- 🎯 Dynamic: only steers when attention is insufficient (no over-steering)
- 🔧 Applied to ALL heads and ALL layers simultaneously
- 📊 Validated across 7 model families (Qwen2.5, Llama 3.1, Mistral, Granite)
Quick Start
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from spotlight.steering import SpotLightSteering
from spotlight.utils import find_instruction_span
# Load model with eager attention (REQUIRED for SpotLight)
model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2.5-3B-Instruct",
attn_implementation="eager",
torch_dtype=torch.float16,
device_map="auto",
)
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-3B-Instruct")
# Initialize SpotLight (ψ_target=0.1 is the paper default)
spotlight = SpotLightSteering(model, psi_target=0.1)
# Your prompt with instructions
prompt = """Write a poem about the ocean.
Your response should follow the instructions below:
- Do not use any commas
- Write at least 100 words
- Use all lowercase letters"""
# Find instruction token indices
formatted = tokenizer.apply_chat_template([{"role": "user", "content": prompt}],
tokenize=False, add_generation_prompt=True)
delim = "Your response should follow the instructions below:"
instr_text = prompt[prompt.find(delim):]
start, end = find_instruction_span(tokenizer, formatted, instr_text)
# Generate WITH SpotLight steering
inputs = tokenizer(formatted, return_tensors="pt").to(model.device)
with spotlight.steer(slice(start, end)):
output = model.generate(**inputs, max_new_tokens=512, do_sample=False)
response = tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
# Clean up
spotlight.remove_hooks()Demo Results (Qwen2.5-0.5B-Instruct, 10 samples)
SpotLight improved instruction-level accuracy by 33% even on this tiny model. The paper reports +26% prompt-level accuracy averaged across 7 models (3B-72B) on the full IFEval benchmark.
Paper Results (from original paper)
Supported Architectures
- ✅ Llama 3.x (LlamaAttention)
- ✅ Qwen 2.x (Qwen2Attention)
- ✅ Mistral (MistralAttention)
- ✅ Granite (GraniteAttention)
- ✅ GPT-2 (GPT2Attention)
- ✅ Other models using qproj/kproj/vproj/oproj pattern
Repository Structure
spotlight/
├── __init__.py # Package init
├── steering.py # Core SpotLight algorithm
└── utils.py # Token span detection utilities
ifeval_checker.py # IFEval instruction checker (25 types)
spotlight_experiment.py # Full IFEval evaluation script
results/ # Evaluation resultsHow It Works
- Monkey-patch each attention layer's
forward()to intercept pre-softmax logits - Before softmax, compute current attention proportion
ψ_currenton instruction tokens - If
ψ_current < ψ_target(model isn't attending enough): - Add
log(ψ_target / ψ_current)to instruction token logits - This multiplicatively boosts instruction attention in probability space
- The dynamic correction ensures
ψ_new ∈ [ψ_target/(1+ψ_target), ψ_target]
Dataset
Uses ibm-research/Split-IFEval — a preprocessed version of IFEval where task descriptions are separated from formatting instructions, enabling precise instruction span identification.
Citation
@inproceedings{venkateswaran2026spotlight,
title={Spotlight Your Instructions: Instruction-following with Dynamic Attention Steering},
author={Venkateswaran, Praveen and Contractor, Danish},
booktitle={Proceedings of the 2026 Conference of the European Chapter of the Association for Computational Linguistics},
year={2026}
}