Skip to main content

interp-engine samples

Minimal, copyable examples. Each page is one job.

Install

pip install 'interp-engine[vllm]' # vLLM backend, CUDA required
pip install interp-engine # eager backend only

Read one activation

from interp_engine import Address, load_model, run_with_cache

model = load_model("Qwen/Qwen3-8B")
point = Address("resid_post", 10)

cache = run_with_cache(model, model.to_tokens("Hello, world"), [point])
cache[point] # [batch, pos, d_model]

Steer one layer

The free functions are sync. The methods on the model are async. Same spec either way.

import torch

from interp_engine import (
AddSpec,
LayerSteeringSpec,
SteeringSpec,
generate_stream,
load_model,
steer,
)

model = load_model("Qwen/Qwen3-8B")
vector = torch.randn(model.d_model)
spec = SteeringSpec(
layers={10: LayerSteeringSpec(operations=[AddSpec(vector=vector, scale=4.0)])}
)
tokens = model.to_tokens("Hello, world")

# sync
with steer(model, spec):
for step in generate_stream(model, tokens, max_tokens=32):
print(step.token_str, end="")


# async (call with "await steered(model, tokens[0].tolist(), spec)")
async def steered(model, token_ids, spec):
completion, _cache = await model.capture_generation(
token_ids, ["resid_post.10"], max_tokens=32, steering_spec=spec
)
return completion.text

Where to go

PageFor
Points and addressesWhat can be asked for, and how it is named
Loading modelsOne snippet per backend
CapabilitiesAsk what a backend serves before you call it
CaptureRead activations, one point or every layer
AttentionScores, probs, per-head values, DFA
Logit lensSend a residual through the unembed
SteeringEvery steering type
GenerationText, streams, logprobs, steered decode
Chat and tokensTemplates, per-turn spans, pooling
Async and serversEvent loops, concurrency, sync_model

Per-backend support for each point: the visualizer and SUPPORTED_POINTS.md.