patch
Verify if a flagged transformer component causally drives a prediction by zero-ablating it in one forward pass and comparing output token changes.
Instructions
Zero-ablate one component (a single transformer block's layer plus a component type such as an attention output or MLP output) in an open-weight TransformerLens model's forward pass, and report how the predicted token and its logit changed relative to the unablated baseline. This is a minimal causal intervention: use it to test whether a component trace or circuit flagged as correlated with a prediction is actually causally responsible for it. Call it after trace or circuit has surfaced a candidate layer/component; it does not search for candidates itself. Read-only in the sense that it writes no files and the ablation only affects that single in-memory forward pass, nothing persists across calls; the same HuggingFace model-weight caching and CPU-by-default notes as trace apply. Deterministic for a given model, prompt, layer, and component. On failure it returns a structured error object instead of raising: an out-of-range layer raises LayerOutOfRangeError, an unsupported model name raises UnsupportedModelError, and a prompt exceeding the context window raises PromptTooLongError, all surfaced the same way. Parameters: model (str); prompt (str); layer (int), the zero-indexed transformer block to patch; component (str), one of resid_pre, resid_mid, resid_post, attn_out, mlp_out, mlp_post. Example call: model='gpt2', prompt='The capital of France is Paris. The capital of Japan is', layer=9, component='attn_out'. Returns JSON with schema_version, operation, model, prompt, layer, component, ablation_type ('zero'), baseline_predicted_token, baseline_predicted_token_id, baseline_top_logit, patched_predicted_token, patched_predicted_token_id, patched_top_logit, logit_delta, and prediction_changed (bool).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| layer | Yes | ||
| model | Yes | ||
| prompt | Yes | ||
| component | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||