Skip to contents

Build a unit full-width direction from paired, already collected activations. The positive sign is target minus control. This function performs no inference.

Usage

llm_direction(
  target,
  control,
  context,
  layer,
  normalize_pairs = FALSE,
  orthogonalize = FALSE,
  max_bytes = 64 * 1024^2
)

# S3 method for class 'relm_direction'
print(x, ...)

Arguments

target, control

Plain double matrices with identical named pairs as rows and complete, ordered neuron names "1" through the hidden width as columns.

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.

layer

One whole layer: 2 through the recorded layer count for residual captures; 1 through that count for mlp_out and attn_out captures.

normalize_pairs

Whether to give each pair difference unit length before averaging. Defaults to FALSE, preserving relative pair magnitudes.

orthogonalize

Whether to remove the component parallel to the mean original control vector before final normalization. Defaults to FALSE.

max_bytes

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

x

A trusted relm_direction artifact.

...

Must be empty.

Value

llm_direction() returns a relm_direction data frame with integer neuron, double value and a versioned direction metadata attribute. No model pointer, input matrix or trace is retained.

Details

Context records a model checksum, architecture, quantization, hidden width, layer count and patched engine revision. Capture is full-width residual, mlp_out or attn_out space at the last prompt position, raw text, embedded tokenizer, add_special = TRUE, parse_special = FALSE, no external template, plus resolved backend, context length and package version. Pairs record ordered IDs, exact UTF-8 prompt checksums and source positions. The split manifest declares disjoint, nonempty construction, selection and evaluation sets before fitting.

At most 4096 pairs, 65536 coordinates, 16384 split rows and 8 MiB of context are admitted. Computation is row-wise; a whole difference matrix is never materialized. Zero, nearly cancelled or nonfinite directions are errors, not silently dropped observations. Norm guards use 64 * .Machine$double.eps.

Trusted saveRDS() and readRDS() preserve the artifact. Application and printing validate schema, unit values, coordinates and canonical checksums. Checksums use one bounded temporary file at a time, removed even on error. They detect modification but do not authenticate recorded provenance or already-loaded weights. Caller deserialization and native model/context memory are outside this budget. Never read untrusted RDS files. Residual artifacts retain schema 1. Component artifacts use schema 2, with component-specific identity and a versioned prefix in every checksum domain. Construction does not prove that a model supports editing the recorded site.