Payloads describe weights independently of source file formats. Construct them
from NumPy or PyTorch tensors, or obtain them through an
easysteer.vectors adapter, then
pass them as VectorSpec(data=payload, ...).
The tensor payload constructors validate dimensions and finite values and store
contiguous float32 arrays. Engine admission checks component widths and target layers;
worker materialization uses the configured steering dtype. See
algorithms and payloads for transformations and file schemas.
All payload classes inherit Payload.to_wire(). It returns a dictionary with
version, kind, named tensors (shape and raw byte data), extra metadata,
and a content sha256. Use
to_json_payload() for JSON/HTTP
encoding of those bytes.
classPayload:"""Base class: named float32 tensors plus payload-specific fields."""kind:str# set by subclassesdef_tensors(self)->dict[str,np.ndarray]:raiseNotImplementedErrordef_extra(self)->dict[str,Any]:return{}defto_wire(self)->dict[str,Any]:tensors=self._tensors()wire_tensors={}fornameinsorted(tensors):arr=tensors[name]wire_tensors[name]={"shape":list(arr.shape),"data":arr.tobytes(),}wire={"version":_WIRE_VERSION,"kind":self.kind,"tensors":wire_tensors,"extra":copy.deepcopy(self._extra()),}wire["sha256"]=_wire_digest(wire)returnwire
layers maps true decoder-layer IDs to one-dimensional vectors. Widths may
differ across layers when the model component does. For attention_add, each
vector contains concatenated head outputs; obtain their dimensions from capture
layouts. The constructor returns a DirectionVector; algorithms determine how
its directions are applied.
def__init__(self,layers:dict[int,Any]):ifnotlayers:raiseValueError("DirectionVector requires at least one layer")self.layers={int(layer):_as_array(f"layers[{layer}]",vec,ndim=1)forlayer,vecinlayers.items()}
For LinearMap, weight has shape (hidden, hidden) and optional bias has
shape (hidden,). For LowRankProjector, both projectors have shape
(hidden, rank). These payloads do not record layer IDs; specify
VectorSpec.layers when applying the returned object.
rotate_layer has shape (hidden, rank), learned_source_weight has shape
(rank, hidden), and optional learned_source_bias has shape (rank,).
layer records a checkpoint's target. If it is omitted, supply
VectorSpec.layers. The returned ReftIntervention is accepted by loreft.
A LoReFT intervention: rotation basis + learned source map.
Accepted by the loreft algorithm. layer fixes the target layer
(as recorded in a checkpoint); when None, VectorSpec.layers is
required and the intervention is applied to each listed layer.
Source code in vllm-steer/vllm/model_hooks/steering/payloads.py
h1 and h2 are DirectionVector objects or layer-to-vector dictionaries.
They must have identical layer sets and matching widths at each layer.
The returned ConceptPair preserves the two roles explicitly.
def__init__(self,layers:dict[int,dict[str,Any]]):ifnotlayers:raiseValueError("RouterConfig requires at least one layer")self.layers:dict[int,dict[str,Any]]={}forlayer,configinlayers.items():layer=int(layer)iflayer<0:raiseValueError("router layer ids must be non-negative")mode=config.get("mode","activate")try:validate_router_mode(mode)exceptValueErrorasexc:raiseValueError(f"Layer {layer}: {exc}")fromNonenormalized={"mode":mode,"expert_ids":_router_expert_ids(config,"expert_ids",layer),}ifmodein("activate","deactivate"):normalized.update(activate_ids=_router_expert_ids(config,"activate_ids",layer),deactivate_ids=_router_expert_ids(config,"deactivate_ids",layer),epsilon=float(config.get("epsilon",0.01)),)ifnotany(normalized[k]forkin("expert_ids","activate_ids","deactivate_ids")):raiseValueError(f"Layer {layer}: {mode} config has no expert ids")ifnotmath.isfinite(normalized["epsilon"]):raiseValueError(f"Layer {layer}: epsilon must be finite")else:ifnotnormalized["expert_ids"]:raiseValueError(f"Layer {layer}: {mode} config has no expert ids")normalized["lambda"]=float(config.get("lambda",0.5))ifnotmath.isfinite(normalized["lambda"]):raiseValueError(f"Layer {layer}: lambda must be finite")ifmode=="soft_topk":topk=config.get("topk",8)ifnotisinstance(topk,int)orisinstance(topk,bool)ortopk<1:raiseValueError(f"Layer {layer}: topk must be a positive integer")normalized["topk"]=topkiflayerinself.layers:raiseValueError(f"duplicate router layer id: {layer}")self.layers[layer]=normalized