ControlVector class final

Constructors

ControlVector(Map<int, Float32List> directions, {required int hiddenSize, ControlMode mode = ControlMode.add, double scale = 1.0, int firstLayer = 0, int? lastLayer})
Directions by zero-based layer, each of hiddenSize finite floats; layers without one are left alone. Only layers from firstLayer to lastLayer (inclusive; null: no upper bound) are steered. scale must be finite.

Properties

directions → Map<int, Float32List>
The directions as given, by zero-based layer.
final
fingerprint → String
Identifies what this vector does to the arithmetic: the mode, scale, range and the directions of the layers it steers. Equal for vectors that steer identically.
latefinal
firstLayer → int
final
hashCode → int
The hash code for this object.
no setterinherited
hiddenSize → int
final
lastLayer → int?
final
maxLayer → int
The highest layer with a direction, or -1 without any.
no setter
mode → ControlMode
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
scale → double
final

Methods

appliedVector(int layer) → Float32List?
What apply uses for layer, or null for a layer it steers not: scale * d in float32 for ControlMode.add, the unit direction for ControlMode.project. The GPU path uploads these. Do not modify.
apply(Float32List rows, int rowCount, int layer) → void
Steers rowCount rows of hiddenSize at the start of rows, the residual stream leaving layer, in place. Does nothing for a layer it does not steers. Each row is computed on its own, in a fixed order, so the result does not depend on how tokens are chunked.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
save(String path) → void
Writes the directions (not mode, scale or range) to path as safetensors: F32 tensors direction.<l> of shape hiddenSize, in layer order. Written through a temporary file and a rename.
steers(int layer) → bool
Whether apply changes the output of layer.
toString() → String
A string representation of this object.
inherited
withSettings({ControlMode? mode, double? scale, int? firstLayer, int? lastLayer}) → ControlVector
This vector's directions with another mode, scale or layer range.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

load(String path, {ControlMode mode = ControlMode.add, double scale = 1.0, int firstLayer = 0, int? lastLayer}) → ControlVector
Reads the directions of a control-vector file: safetensors as save writes it, or llama.cpp's GGUF (which needs the native kernels, for the mapping). Every tensor must be an F32 vector named direction.<l>.