Skip to contents

Validate a trusted direction artifact, then derive an additive residual or static component-projection handle using native capability checks.

Usage

llm_apply_direction(
  m,
  direction,
  context,
  coef = 1,
  max_bytes = 64 * 1024^2,
  operator = "add"
)

Arguments

m

A live llm handle. Its metadata is checked for compatibility, not treated as authenticated weight identity.

direction

A relm_direction returned by llm_direction().

context

For construction, a recorded list with model, capture, pairs, splits and seed; see Details and the contrast-directions vignette. For application, an independently recorded destination model record.

coef

One finite coefficient. For projection, zero is an exact no-op, one removes the direction's component, and negative values amplify it.

max_bytes

Whole materialization budget, 1 MiB through 512 MiB; default 64 MiB. Includes input matrices and metadata, working arrays and output.

operator

Exactly "add" (default) for schema-1 residual directions or "project" for schema-2 MLP/attention directions; no partial matching.

Value

A new llm handle; m is unchanged. Close the derived handle when done.

Details

The independently recorded destination context must match all six fields of the construction model record exactly. Verify the model file and keep it unchanged while loading and experimenting. Same path or width alone is insufficient. This check cannot authenticate already-loaded weights. Projection edits each executed component row as h - coef * v * sum(v * h). It is static for the derived handle; live replies still update only existing additive steering. Supported sites are dense Llama MLP/post-output-projection attention and Qwen2 MLP on CPU/Metal and the optional Linux CUDA build. Projected handles accept text generation and logits; image requests, ordinary trace and embedding calls are refused. The combined budget includes the current artifact's validation and all accumulated projection/residual owners. Direct steer/ablate inheritance uses the projected handle's recorded budget; a checked direction application uses its explicit max_bytes. Extracting direction$value and calling llm_steer() directly deliberately bypasses artifact checks. Native busy/closed errors propagate.