Returns a new llm handle with the listed 1-based neurons of component
at layer forced to value during every subsequent forward pass
(llm_generate(), llm_logits()). The original handle is untouched: to remove
the ablation, use the original object (reversibility is exact, D-003).
Arguments
- m
An
llmhandle fromllm().- layer
Single 1-based transformer block, in
1:m$layers.- neurons
A non-empty vector of 1-based neuron indices in
1:m$hidden_sizeto force tovalue.- value
Single finite number the neurons are forced to (default
0).- component
Which sub-layer to ablate. Only
"residual"(the default) is supported in this release.
Value
A new llm handle with the ablation added to its accumulated
interventions; the source handle is returned unchanged. print() shows the
active intervention count and summary() lists them.
Details
Ablation forces x[neuron] := value at the residual choke point – a native
graph op (x * mask + add), reversible by construction. Unlike steering it
covers every layer, including layer 1.
Composition. Deriving from an already-steered or ablated handle carries its
full spec forward and adds the new one, then builds a single fresh context from
the original weights (contexts are never chained). Ablation is a union,
last-write-wins per (layer, neuron) – a later ablation of the same neuron
overrides its value. The semantics are derivation-order-independent:
m |> llm_ablate(...) |> llm_steer(...) produces the same forward pass as
m |> llm_steer(...) |> llm_ablate(...), and a steer never moves an ablated
neuron (the ablation runs after the steer at the graph, (x + steer) * mask + add, forcing the neuron to value, D-016).
Not free. Each llm_ablate()/llm_steer() call allocates a fresh context
on the shared weights – a sub-second pause and real memory (its own KV cache),
not a cheap copy.
Generation/logits only (for now). Interventions apply to llm_generate()
and llm_logits(). llm_embed() and llm_trace() on an intervened handle
raise relm_error_embed / relm_error_trace rather than silently
returning base vectors mislabeled as ablated.
Only component = "residual" ablation is supported in this release (the shared
choke point); "attn_out"/"mlp_out" raise relm_error_intervention.
Model support. Interventions work on any standard-residual decoder; before the
handle is returned, a runtime probe verifies on this model that the ablation
takes effect at each requested layer, raising relm_error_intervention rather
than silently doing nothing. llama and qwen2 are additionally behaviorally
validated (the valence / KL acceptance fixtures); other architectures are enabled
once they pass the probe.
Examples
if (FALSE) { # nzchar(Sys.getenv("RELM_TEST_MODEL_QWEN"))
m <- llm(Sys.getenv("RELM_TEST_MODEL_QWEN"))
ablated <- llm_ablate(m, layer = 5, neurons = c(10, 42, 128))
# Composition is order-independent: these two derivations behave identically.
dir <- rep(0.05, m$hidden_size)
a <- m |> llm_ablate(layer = 5, neurons = 10) |> llm_steer(layer = 6, direction = dir)
b <- m |> llm_steer(layer = 6, direction = dir) |> llm_ablate(layer = 5, neurons = 10)
summary(a)
close(a)
close(b)
close(ablated)
close(m)
}