Core
steerability.algorithms.core
Core functionality for steering pipelines, control composition, and argument parsing.
base_args
Base argument validation for steering method configuration.
T = TypeVar('T', bound='BaseArgs')
module-attribute
BaseArgs
dataclass
Base class for all method's args classes.
Source code in steerability/algorithms/core/base_args.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
validate(_init_data=None, **kwargs)
classmethod
Create and validate an Args instance from dict, kwargs, or existing instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_init_data
|
Any | None
|
Existing instance, dict of args, or None. Named with underscore prefix to avoid collision with common field names like "data". |
None
|
Returns:
| Type | Description |
|---|---|
T
|
Validated instance of the Args class |
Source code in steerability/algorithms/core/base_args.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
base_control
Shared base class for steering controls across all four categories.
BaseControl
Bases: ABC
Common construction and lifecycle for steering controls.
Subclasses set Args to their hyperparameter dataclass; construction validates the arguments
and mirrors every field onto the instance. A field whose name the subclass exposes as a
@property is not mirrored (e.g. CAST.condition_point); the raw value stays reachable via
self.args.<name>. Controls with Args = None accept no constructor arguments.
Attributes:
| Name | Type | Description |
|---|---|---|
Args |
type[BaseArgs] | None
|
The control's hyperparameter dataclass, or None for arg-free controls. |
RUNTIME_KWARGS_SCHEMA |
list[dict]
|
Declarations for the per-call parameters the pipeline maps onto the
control at inference time. Each entry is a dict carrying |
enabled |
bool
|
Whether the control participates in the pipeline (identity controls set False). |
supports_batching |
bool
|
Whether the control processes a batched prompt in one call. |
Source code in steerability/algorithms/core/base_control.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
Args = None
class-attribute
instance-attribute
RUNTIME_KWARGS_SCHEMA = []
class-attribute
instance-attribute
args = self.Args.validate(*args, **kwargs)
instance-attribute
enabled = True
class-attribute
instance-attribute
supports_batching = False
class-attribute
instance-attribute
cleanup()
Release resources allocated during steer().
Override in subclasses that allocate GPU memory or other resources during steering. Default no-op.
Source code in steerability/algorithms/core/base_control.py
195 196 197 198 199 200 201 | |
clone_for_call(seed=None)
A configuration-preserving shallow clone for one generation call.
The clone shares steer-time artifacts (memories, steering vectors, attached tokenizers)
with the original but has its own attribute namespace, so per-call attribute mutation on
the clone never races another call using the original. When seed is given and the
control defines reseed(seed), the clone's client-side RNG is re-seeded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
int | None
|
Optional seed forwarded to the clone's |
None
|
Returns:
| Type | Description |
|---|---|
BaseControl
|
The clone. |
Source code in steerability/algorithms/core/base_control.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
export_state()
Steer-time state to persist when freezing, keyed by logical name.
Values are typed artifacts (SteeringVector, Probe, ProbeSet, a Memory
implementation, CheckpointArtifact, LoRAArtifact, torch.Tensor, or a Path to an
on-disk product). Must be called after steer(). The default returns an empty mapping
(nothing to persist).
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Mapping from logical name to artifact value. |
Source code in steerability/algorithms/core/base_control.py
117 118 119 120 121 122 123 124 125 126 127 128 | |
fit_identity()
The object whose canonical form defines this control's fit digest, or None.
The digest detects recipe edits that invalidate frozen artifacts, so the returned object should cover exactly the inputs a re-fit would consume (training data, fit specs) and exclude inert application parameters (strengths, multipliers). The default returns None (no fits).
Returns:
| Type | Description |
|---|---|
Any | None
|
The fit-identity object, or None. |
Source code in steerability/algorithms/core/base_control.py
161 162 163 164 165 166 167 168 169 170 171 172 | |
frozen_form(state)
The (registry method key, constructor kwargs) of this control's frozen form.
state is the output of export_state(); artifact values inside the returned kwargs
are replaced by store references at encode time. When steer_fits() is empty and
state is empty, the recipe is the frozen form and the control's own key and recipe
args are returned unchanged. A control whose freeze expands into several entries may
return a list of (method key, kwargs) pairs instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
dict[str, Any]
|
The output of |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, dict[str, Any]]
|
The frozen method key and its constructor kwargs. |
Raises:
| Type | Description |
|---|---|
NotFreezableError
|
If the control produces fits or state but declares no frozen form. |
Source code in steerability/algorithms/core/base_control.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
requirements()
Backend requirements computed from this instance's configuration, per phase.
The default requires Capability.IN_PROCESS_TORCH at generate and nothing at score,
which only the Hugging Face backend satisfies. A control with portable mechanisms
overrides this to state weaker or alternative requirements. Configuration determines the
result, so two configurations of one class may differ. Only enabled controls are
consulted during support evaluation.
Returns:
| Type | Description |
|---|---|
Requirements
|
The control's phase-keyed requirements. |
Source code in steerability/algorithms/core/base_control.py
75 76 77 78 79 80 81 82 83 84 85 86 87 | |
steer_access()
The model access this instance's steer step requires, on the ModelAccess ladder.
The default is ModelAccess.FACTS (layout and tokenizer only). A control whose steer
step generates or scores through the session declares ROLLOUTS, one that captures
hidden states declares CAPTURE, and one that touches the model as a live
torch.nn.Module declares MODULE. Configuration determines the result. The pipeline
hands steer() a session scoped to the declared rung, and the live model only at
MODULE. A control may retain the pipeline model beyond steer() only if its
generate phase requires Capability.IN_PROCESS_TORCH.
Returns:
| Type | Description |
|---|---|
ModelAccess
|
The declared access rung. |
Source code in steerability/algorithms/core/base_control.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
steer_fits()
The fit artifacts this instance's steer step will produce, for the steer plan.
Each entry is (artifact, artifact_class), where artifact is the fit source or
recipe class name and artifact_class is "direction" or "calibrated". The default
is an empty tuple (no fits).
Returns:
| Type | Description |
|---|---|
tuple[tuple[str, str], ...]
|
The declared fit artifacts, in declaration order. |
Source code in steerability/algorithms/core/base_control.py
105 106 107 108 109 110 111 112 113 114 115 | |
NotFreezableError
Bases: RuntimeError
A control produces steer-time state but declares no frozen form.
Raised by BaseControl.frozen_form when a control's steer step produces fits or exported
state and the control does not override frozen_form to name a constructor-valid frozen
form. Re-exported from steerability.spipe.errors alongside the other spipe exceptions.
Source code in steerability/algorithms/core/base_control.py
12 13 14 15 16 17 18 | |
execution
Execution seam types for multi-backend steering.
A Backend owns identity, capability advertisement, and session creation; a SteeringSession
is the scope within which steering is in force and the unit of concurrency. The pipeline
interacts with backends through these two interfaces. Backend implementations live in
steerability.backends; this package holds every seam type and imports nothing from
steerability.backends at module level.
Artifact = ModelArtifact | CheckpointArtifact | LoRAArtifact
module-attribute
OutputControlEntry = StackEntry | ProcessorSpecEntry | ConstraintEntry
module-attribute
StateControlEntry = HookEntry | InterventionEntry
module-attribute
Alternative
dataclass
One way to satisfy a phase requirement, i.e., a conjunction of capability atoms with optional kind predicates over the backend's advertised kind sets.
Attributes:
| Name | Type | Description |
|---|---|---|
atoms |
frozenset[Capability]
|
Capability atoms that must all be advertised. |
kinds |
tuple[KindSet, ...]
|
Kind sets whose names must all be contained in the backend's advertisement of the corresponding kind-set type. |
hint |
str | None
|
Optional fix text used in unsupported-verdict messages in place of the default. |
Source code in steerability/algorithms/core/execution/contracts.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
atoms = frozenset()
class-attribute
instance-attribute
hint = None
class-attribute
instance-attribute
kinds = ()
class-attribute
instance-attribute
missing(capabilities)
Names of the atoms and kind sets this alternative needs but capabilities lacks.
Source code in steerability/algorithms/core/execution/contracts.py
205 206 207 208 209 210 211 212 | |
satisfied_by(capabilities)
Return True when every atom is advertised and every kind set is contained.
Source code in steerability/algorithms/core/execution/contracts.py
195 196 197 198 199 200 201 202 203 | |
ArtifactProvenance
dataclass
Identity of the side that produced an artifact.
Attributes:
| Name | Type | Description |
|---|---|---|
backend_spec_hash |
str | None
|
|
model_fingerprint |
str | None
|
Fingerprint of the producing model. |
tokenizer_fingerprint |
str | None
|
Fingerprint of the producing tokenizer and chat template. |
Source code in steerability/algorithms/core/execution/payloads.py
112 113 114 115 116 117 118 119 120 121 122 123 124 | |
backend_spec_hash = None
class-attribute
instance-attribute
model_fingerprint = None
class-attribute
instance-attribute
tokenizer_fingerprint = None
class-attribute
instance-attribute
Backend
Bases: ABC
A backend owns a loaded model, engine, or connection pool and its lifecycle, advertises capabilities, and creates sessions.
Long-lived consumers hold backends in a cache keyed by BackendSpec so configurations
differing only in per-request steering share one resource.
Attributes:
| Name | Type | Description |
|---|---|---|
spec |
BackendSpec
|
The frozen identity of this backend configuration. |
Source code in steerability/algorithms/core/execution/backend.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
capabilities
property
The advertised capability atoms.
capture_kinds
property
The advertised capture kinds, when Capability.HIDDEN_CAPTURE is present.
intervention_kinds
property
The advertised intervention kinds, when Capability.INTERVENTION_SPECS is present.
processor_kinds
property
The advertised processor kinds, when Capability.PER_STEP_LOGIT_SPECS is present.
spec
instance-attribute
capabilities_for_spec(spec)
abstractmethod
classmethod
The capability advertisement implied by spec, computable without constructing the
backend. Constructed backends advertise the same sets, verified against the live
resource where a discovery surface exists.
Source code in steerability/algorithms/core/execution/backend.py
159 160 161 162 163 164 | |
open_session()
abstractmethod
Open a session for one logical operation.
Source code in steerability/algorithms/core/execution/backend.py
166 167 168 | |
release()
Free the resources this backend owns beyond what the caller owns.
The default is a no-op. Engine-owning backends override this to shut their engines down deterministically. Release is idempotent.
Source code in steerability/algorithms/core/execution/backend.py
204 205 206 207 208 209 210 | |
stage_artifacts(payloads)
Make each content-addressed artifact available to the execution side.
Called by the pipeline at the end of steer() with the tensor payloads of every
lowered intervention spec, keyed by content-addressed artifact id. Staging is
idempotent: an artifact that already exists at the destination is success. The
in-process backend keeps live tensors and needs no staging; engine-backed backends
write into the registry the serving engine reads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payloads
|
dict[str, dict[str, Tensor]]
|
Mapping from artifact id to a name-to-tensor mapping. |
required |
Source code in steerability/algorithms/core/execution/backend.py
190 191 192 193 194 195 196 197 198 199 200 201 202 | |
BackendCapabilities
dataclass
A backend's full capability advertisement: atoms plus negotiated kind sets.
Attributes:
| Name | Type | Description |
|---|---|---|
atoms |
frozenset[Capability]
|
The advertised |
intervention_kinds |
InterventionKinds | None
|
Advertised intervention kinds, present when
|
processor_kinds |
ProcessorKinds | None
|
Advertised processor kinds, present when
|
capture_kinds |
CaptureKinds | None
|
Advertised capture kinds, present when |
constraint_kinds |
ConstraintKinds | None
|
Advertised constrained-decoding kinds, present when
|
Source code in steerability/algorithms/core/execution/contracts.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
atoms = frozenset()
class-attribute
instance-attribute
capture_kinds = None
class-attribute
instance-attribute
constraint_kinds = None
class-attribute
instance-attribute
intervention_kinds = None
class-attribute
instance-attribute
processor_kinds = None
class-attribute
instance-attribute
BackendSpec
dataclass
Frozen, hashable identity of one backend configuration.
The spec hash is the backend identity used for engine caching, benchmark checkpoint keys,
capability-probe caches, and artifact provenance. Options are canonicalized at construction
(nested mappings stored as sorted tuples, dtypes as strings, no live objects), so two specs
built from equal option mappings compare and hash equal regardless of key order. Equality
and hash() follow spec_hash, so value type is part of identity (an option value of
True and one of 1 yield different specs).
Construction also validates the configuration. A "vllm"/"vllm-serve" spec with the
vLLM-Hook plugin active (hook_plugin option) and speculative decoding configured
(speculative_config option, top-level or under engine_kwargs) is rejected, since
draft-model forwards are unhooked and verification passes break the worker's per-request
position accounting. A "vllm"/"vllm-serve" spec naming an encoder-decoder model is
rejected when the model config resolves locally (encoder-decoder execution is in-process
only); an unresolvable reference passes here and is re-checked at backend construction.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
Backend kind, one of |
model |
str | None
|
Model reference (hub id or local path), or None when the backend adopts an already-loaded model. |
options |
Any
|
Canonicalized option mapping, stored as sorted tuples. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If |
Source code in steerability/algorithms/core/execution/spec.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
kind
instance-attribute
model = None
class-attribute
instance-attribute
options = field(default=())
class-attribute
instance-attribute
spec_hash
property
A 16-character hex digest over (kind, model, options), consistent with __eq__
and stable across processes for plain-data options.
get_option(*path, default=None)
Read one option by key path, rebuilding plain dicts and lists on the way out.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*path
|
str
|
Nested option keys, e.g. |
()
|
default
|
Any
|
Value returned when any key along the path is absent. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The option value with mappings rebuilt as plain dicts and sequences as plain lists, |
Any
|
or |
Source code in steerability/algorithms/core/execution/spec.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
options_dict()
Return the options as a plain nested dict (empty when no options were provided).
Source code in steerability/algorithms/core/execution/spec.py
211 212 213 214 | |
Capability
Bases: Enum
Distinguishing capability atoms advertised by backends.
Attributes:
| Name | Type | Description |
|---|---|---|
IN_PROCESS_TORCH |
The backend exposes the model as a live |
|
INTERVENTION_SPECS |
The backend executes activation interventions submitted as
|
|
PER_STEP_LOGIT_SPECS |
The backend hosts per-step logit math submitted as |
|
HIDDEN_CAPTURE |
The backend serves hidden-state capture through |
|
BEAM_PROPOSALS |
The backend implements beam-search proposal semantics ( |
|
SERVE_CHECKPOINT |
The backend can serve a checkpoint directory produced elsewhere. |
|
SERVE_LORA |
The backend can serve a LoRA adapter produced elsewhere. |
|
GUIDED_DECODING |
The backend hosts declarative constrained decoding natively, rendered
from a |
Source code in steerability/algorithms/core/execution/contracts.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
BEAM_PROPOSALS = 'beam_proposals'
class-attribute
instance-attribute
GUIDED_DECODING = 'guided_decoding'
class-attribute
instance-attribute
HIDDEN_CAPTURE = 'hidden_capture'
class-attribute
instance-attribute
INTERVENTION_SPECS = 'intervention_specs'
class-attribute
instance-attribute
IN_PROCESS_TORCH = 'in_process_torch'
class-attribute
instance-attribute
PER_STEP_LOGIT_SPECS = 'per_step_logit_specs'
class-attribute
instance-attribute
SERVE_CHECKPOINT = 'serve_checkpoint'
class-attribute
instance-attribute
SERVE_LORA = 'serve_lora'
class-attribute
instance-attribute
CaptureKinds
dataclass
Hidden-state capture forms a backend serves, by permanent wire name.
Attributes:
| Name | Type | Description |
|---|---|---|
kinds |
frozenset[str]
|
Capture kinds, e.g. |
locations |
frozenset[str]
|
Capture locations, e.g. |
modes |
frozenset[str]
|
Capture modes, e.g. |
Source code in steerability/algorithms/core/execution/contracts.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
kinds = frozenset()
class-attribute
instance-attribute
locations = frozenset()
class-attribute
instance-attribute
modes = frozenset()
class-attribute
instance-attribute
contains(required)
Return True when every required kind name is advertised.
Source code in steerability/algorithms/core/execution/contracts.py
124 125 126 127 128 129 130 | |
CaptureResult
dataclass
Hidden states captured by SteeringSession.capture.
Attributes:
| Name | Type | Description |
|---|---|---|
hidden |
Mapping[int, Tensor]
|
Tensors keyed by 0-based layer id. Shape |
attention_mask |
Tensor
|
Mask of shape |
mode |
str
|
The capture mode the tensors were produced under. |
location |
str
|
The capture location ( |
Source code in steerability/algorithms/core/execution/payloads.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 | |
attention_mask
instance-attribute
hidden
instance-attribute
location
instance-attribute
mode
instance-attribute
CheckpointArtifact
dataclass
A checkpoint directory handed across the role boundary; consuming it requires
Capability.SERVE_CHECKPOINT.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
Checkpoint directory path. |
provenance |
ArtifactProvenance
|
Identity of the producing side. |
Source code in steerability/algorithms/core/execution/payloads.py
141 142 143 144 145 146 147 148 149 150 151 152 | |
path
instance-attribute
provenance = field(default_factory=ArtifactProvenance)
class-attribute
instance-attribute
ConstraintEntry
dataclass
An output control's contribution as a declarative constrained-decoding source.
Consumed by backends advertising Capability.GUIDED_DECODING, rendered onto the engine's
native structured-output request parameters in place of the control's live processor.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
ConstraintSource
|
The declarative constraint. |
Source code in steerability/algorithms/core/execution/payloads.py
508 509 510 511 512 513 514 515 516 517 518 519 | |
source
instance-attribute
ConstraintKinds
dataclass
Constrained-decoding kinds a backend hosts natively, by declarative kind name.
The kind set is static per backend version (the engine's structured-output surface needs no
discovery), e.g. {"json_schema", "regex", "grammar", "choice"}.
Attributes:
| Name | Type | Description |
|---|---|---|
constraints |
frozenset[str]
|
Constraint kind names. |
Source code in steerability/algorithms/core/execution/contracts.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
constraints = frozenset()
class-attribute
instance-attribute
contains(required)
Return True when every required kind name is advertised.
Source code in steerability/algorithms/core/execution/contracts.py
146 147 148 | |
ConstraintSource
dataclass
A declarative constrained-decoding specification.
The portable form of the constraint class: one source renders per execution arm, compiled into a client-side automaton in process and onto the engine's native structured-output request parameters on vLLM backends.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['json_schema', 'regex', 'grammar', 'choice']
|
The constraint kind: |
value |
str | Mapping | Sequence[str]
|
The constraint payload: a schema string or mapping for |
Source code in steerability/algorithms/core/execution/payloads.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
kind
instance-attribute
value
instance-attribute
GenerationItem
dataclass
One prompt's unit of generation work.
Input controls have no entry because their contribution is already folded into prompt;
structural controls have none because they contribute at steer time through artifacts.
Attributes:
| Name | Type | Description |
|---|---|---|
prompt |
PreparedPrompt
|
The prepared prompt. |
state_entries |
tuple[StateControlEntry, ...]
|
Enabled state controls' contributions, in controls-list order. |
output_entries |
tuple[OutputControlEntry, ...]
|
Enabled output controls' contributions, in controls-list order. |
seed |
int | None
|
Per-item sampling seed, or None for unseeded operation. |
Source code in steerability/algorithms/core/execution/payloads.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 | |
output_entries = ()
class-attribute
instance-attribute
prompt
instance-attribute
seed = None
class-attribute
instance-attribute
state_entries = ()
class-attribute
instance-attribute
GenerationParams
dataclass
The sampling-facing subset of generation parameters, normalized across backends.
Each backend family owns one rendering rule. In-process, the normalized fields render onto
model.generate names and every key in extra passes through untouched. On API backends
the normalized table is exhaustive and unmapped parameters raise, so extra is rejected
there.
Attributes:
| Name | Type | Description |
|---|---|---|
max_new_tokens |
int | None
|
Maximum number of new tokens. |
min_new_tokens |
int | None
|
Minimum number of new tokens. |
temperature |
float | None
|
Sampling temperature. |
top_p |
float | None
|
Nucleus-sampling probability mass. |
top_k |
int | None
|
Top-k sampling cutoff. |
greedy |
bool | None
|
True forces greedy decoding, False forces sampling, None leaves the backend default. |
n |
int | None
|
Number of returned candidates per prompt. |
repetition_penalty |
float | None
|
Repetition penalty. |
seed |
int | None
|
Sampling seed. In-process it renders as a |
seed_scope |
Literal['item', 'dispatch']
|
How a call-level |
stop_strings |
tuple[str, ...]
|
Stop strings, composed by the session as stop rules on both backend families. Token ids are returned as generated; the pipeline truncates decoded text at the first stop-string occurrence. |
stop_token_ids |
tuple[int, ...]
|
Token ids that halt a row once its last generated token is one of them, in addition to the tokenizer's EOS. |
extra |
Mapping[str, Any]
|
Additional keyword arguments passed through unmapped on the in-process arm. A
normalized field always takes precedence over a same-named key in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in steerability/algorithms/core/execution/params.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
extra = field(default_factory=dict)
class-attribute
instance-attribute
greedy = None
class-attribute
instance-attribute
max_new_tokens = None
class-attribute
instance-attribute
min_new_tokens = None
class-attribute
instance-attribute
n = None
class-attribute
instance-attribute
repetition_penalty = None
class-attribute
instance-attribute
seed = None
class-attribute
instance-attribute
seed_scope = 'item'
class-attribute
instance-attribute
stop_strings = ()
class-attribute
instance-attribute
stop_token_ids = ()
class-attribute
instance-attribute
temperature = None
class-attribute
instance-attribute
top_k = None
class-attribute
instance-attribute
top_p = None
class-attribute
instance-attribute
from_gen_kwargs(**gen_kwargs)
classmethod
Split keyword arguments into normalized fields and pass-through extras.
do_sample maps onto greedy (inverted) and num_return_sequences onto n; keys named
exactly like a normalized field bind to it; everything else lands in extra.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**gen_kwargs
|
Any
|
Generation keyword arguments in |
{}
|
Returns:
| Type | Description |
|---|---|
GenerationParams
|
The normalized |
Source code in steerability/algorithms/core/execution/params.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
to_gen_kwargs()
Render the parameters back into model.generate-vocabulary keyword arguments.
This inverts from_gen_kwargs, so greedy renders as do_sample (inverted), n as
num_return_sequences, the stop fields and seed keep their normalized names,
seed_scope renders only when it is not the default "item", and extra merges
underneath the normalized fields.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The keyword arguments; |
dict[str, Any]
|
|
Source code in steerability/algorithms/core/execution/params.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
HookEntry
dataclass
One state control's torch-hook contribution, consumed by in-process sessions.
Attributes:
| Name | Type | Description |
|---|---|---|
hooks |
Mapping[str, list]
|
Hook specifications keyed by phase ( |
Source code in steerability/algorithms/core/execution/payloads.py
467 468 469 470 471 472 473 474 475 476 | |
hooks
instance-attribute
InterventionEntry
dataclass
One state control's intervention-spec contribution, consumed by intervention-capable backends.
Attributes:
| Name | Type | Description |
|---|---|---|
spec |
InterventionSpec
|
The serialized intervention. |
Source code in steerability/algorithms/core/execution/payloads.py
479 480 481 482 483 484 485 486 487 488 | |
spec
instance-attribute
InterventionKinds
dataclass
Activation-intervention kinds a backend executes, by permanent wire name.
Wire names mirror toolkit class names (AdditiveTransform serializes as "additive",
SumThreshold as "sum_threshold"), so the mapping is definitional rather than
maintained. Kind names are permanent and their meanings never change; new behavior is a
new kind. Compatibility is set containment on kind names.
Attributes:
| Name | Type | Description |
|---|---|---|
transforms |
frozenset[str]
|
Transform kinds, e.g. |
modifiers |
frozenset[str]
|
Wrapper-transform kinds, e.g. |
scopes |
frozenset[str]
|
Token-scope kinds, e.g. |
readouts |
frozenset[str]
|
Gate readout kinds, e.g. |
rules |
frozenset[str]
|
Gate rule kinds, e.g. |
constraints |
Mapping[str, str]
|
Per-kind execution constraints, e.g.
|
Source code in steerability/algorithms/core/execution/contracts.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
constraints = field(default_factory=dict)
class-attribute
instance-attribute
modifiers = frozenset()
class-attribute
instance-attribute
readouts = frozenset()
class-attribute
instance-attribute
rules = frozenset()
class-attribute
instance-attribute
scopes = frozenset()
class-attribute
instance-attribute
transforms = frozenset()
class-attribute
instance-attribute
contains(required)
Return True when every required kind name is advertised.
Source code in steerability/algorithms/core/execution/contracts.py
84 85 86 87 88 89 90 91 92 | |
InterventionSpec
dataclass
A serialized activation intervention for intervention-capable backends.
Each op names its target layers, a transform (kind, scalar parameters, tensor payloads by artifact reference, and an ordered modifier list), a token scope, and an optional gate. Kind names are the advertised wire names; a worker rejects a spec containing a kind or field it does not list.
Attributes:
| Name | Type | Description |
|---|---|---|
ops |
tuple[Mapping[str, Any], ...]
|
The intervention ops, each a mapping with keys |
artifacts |
Mapping[str, Mapping[str, Any]]
|
Tensor payloads keyed by the content-addressed artifact ids the ops reference, each a mapping from tensor name to a float32 contiguous CPU tensor. Sessions materialize these into the registry the serving engine reads before submission. Excluded from equality, the wire form, and the canonical form. |
Source code in steerability/algorithms/core/execution/payloads.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
artifacts = field(default_factory=dict, compare=False)
class-attribute
instance-attribute
ops = ()
class-attribute
instance-attribute
artifact_ids()
Sorted unique artifact ids referenced anywhere in the ops (transform payloads, modifiers, and gate readouts).
Source code in steerability/algorithms/core/execution/payloads.py
337 338 339 340 341 342 | |
canonical()
The canonical serialization, the form hashed for cache salting and provenance.
Delegates to vllm_hook_plugins.core.canonical.canonical_bytes (sorted keys, compact
separators, UTF-8), so the toolkit and the plugin agree byte-for-byte on the canonical
form of a spec.
Raises:
| Type | Description |
|---|---|
ModuleNotFoundError
|
If |
TypeError
|
If an op contains a value with no JSON form. Tensors belong in artifacts, never inline. |
Source code in steerability/algorithms/core/execution/payloads.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
required_kinds()
The kind names this spec requires a backend to serve, as an InterventionKinds.
Collects transform, modifier, scope, and gate readout/rule kind names from the ops; a backend whose negotiated kinds contain them can execute the spec.
Source code in steerability/algorithms/core/execution/payloads.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
salt()
The reference cache salt for requests carrying this spec.
Delegates to vllm_hook_plugins.core.canonical.request_salt over the wire form and
the referenced artifact ids. Returns the 64-char lowercase-hex digest.
Raises:
| Type | Description |
|---|---|
ModuleNotFoundError
|
If |
Source code in steerability/algorithms/core/execution/payloads.py
397 398 399 400 401 402 403 404 405 406 407 408 | |
to_wire()
The plain-data wire form, {"ops": [...]}, with nested mappings and sequences
converted to dicts and lists.
Source code in steerability/algorithms/core/execution/payloads.py
332 333 334 335 | |
ItemResult
dataclass
The result of one generation item.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
Position of the item in the submitted sequence. |
output |
Output
|
The generation record. For |
Source code in steerability/algorithms/core/execution/payloads.py
577 578 579 580 581 582 583 584 585 586 587 588 | |
index
instance-attribute
output
instance-attribute
LoRAArtifact
dataclass
A LoRA adapter handed across the role boundary; consuming it requires
Capability.SERVE_LORA.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
Adapter directory path. |
base_model |
str
|
Model reference the adapter applies to. |
provenance |
ArtifactProvenance
|
Identity of the producing side. |
Source code in steerability/algorithms/core/execution/payloads.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
base_model
instance-attribute
path
instance-attribute
provenance = field(default_factory=ArtifactProvenance)
class-attribute
instance-attribute
ModelAccess
Bases: IntEnum
What a control's steer step requires of the pipeline model, as a cumulative ladder.
Attributes:
| Name | Type | Description |
|---|---|---|
FACTS |
Structural facts ( |
|
ROLLOUTS |
FACTS plus generation and scoring through the session. |
|
CAPTURE |
ROLLOUTS plus hidden-state capture through the session. |
|
MODULE |
The model as a live |
Source code in steerability/algorithms/core/execution/access.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
CAPTURE = 2
class-attribute
instance-attribute
FACTS = 0
class-attribute
instance-attribute
MODULE = 3
class-attribute
instance-attribute
ROLLOUTS = 1
class-attribute
instance-attribute
ModelArtifact
dataclass
An in-memory model handed across the role boundary; only the in-process backend can consume it.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
Any
|
The loaded model. |
provenance |
ArtifactProvenance
|
Identity of the producing side. |
Source code in steerability/algorithms/core/execution/payloads.py
127 128 129 130 131 132 133 134 135 136 137 138 | |
model
instance-attribute
provenance = field(default_factory=ArtifactProvenance)
class-attribute
instance-attribute
ModelFacts
dataclass
Structural facts about the pipeline model, available without a live module tree.
Layer indices are the canonical coordinates for steer-phase layer selection; module names are an in-process serialization detail resolved only at hook construction time. Client-side tensor preparation uses the layout's dtype, and device placement is handled in process or by the worker rather than at steer time.
Attributes:
| Name | Type | Description |
|---|---|---|
num_layers |
int
|
Number of decoder layers. |
hidden_size |
int
|
Residual-stream width. |
num_attention_heads |
int | None
|
Number of attention heads, or None when the model config does not state one. |
head_dim |
int | None
|
Per-head dimension, the config's nominal value (else |
dtype |
str
|
Canonical dtype string, e.g. |
model_fingerprint |
str
|
A 16-character hex digest identifying the model weights and config. |
model_type |
str | None
|
The config's |
model_ref |
str | None
|
The served model reference on engine backends, the loaded model's
|
Source code in steerability/algorithms/core/execution/payloads.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
dtype
instance-attribute
head_dim
instance-attribute
hidden_size
instance-attribute
model_fingerprint
instance-attribute
model_ref = None
class-attribute
instance-attribute
model_type = None
class-attribute
instance-attribute
num_attention_heads
instance-attribute
num_layers
instance-attribute
PartialBatchError
Bases: RuntimeError
Raised when some items of a fan-out failed after retries while others succeeded.
Attributes:
| Name | Type | Description |
|---|---|---|
results |
The successful per-item results, in item order ( |
|
failures |
|
Source code in steerability/algorithms/core/execution/fanout.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
failed_indices
property
Indices of the failed items, re-issuable as a remainder batch.
failures = tuple(failures)
instance-attribute
results = tuple(results)
instance-attribute
PlannedFit
dataclass
One fit artifact's venue in the plan.
Fits execute inside their owning control's steer step, so a fit's venue is the step's.
Attributes:
| Name | Type | Description |
|---|---|---|
control |
str
|
Class name of the control whose steer runs the fit. |
artifact |
str
|
Class name of the fit source or recipe, e.g. |
artifact_class |
ArtifactClass
|
|
venue |
Venue
|
Where the fit runs. |
Source code in steerability/algorithms/core/execution/access.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
artifact
instance-attribute
artifact_class
instance-attribute
control
instance-attribute
venue
instance-attribute
PlannedStep
dataclass
One enabled control's steer step in the plan.
Attributes:
| Name | Type | Description |
|---|---|---|
control |
str
|
Class name of the control. |
access |
ModelAccess
|
The control's declared steer access. |
venue |
Venue
|
Where the step runs. |
Source code in steerability/algorithms/core/execution/access.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
access
instance-attribute
control
instance-attribute
venue
instance-attribute
PreparedPrompt
dataclass
A sum type over messages | text | token_ids for one prompt, plus metadata.
Exactly one of text, messages, or token_ids is set at construction. Tokenization is
forced only when a consumer needs token ids (resolve_token_ids); the in-process resolution
reproduces the pipeline's tokenization calls, so resolved ids match the early-tokenized path.
Attributes:
| Name | Type | Description |
|---|---|---|
text |
str | None
|
A plain-text prompt, or None. |
messages |
tuple[Mapping, ...] | None
|
One conversation as a tuple of message mappings, or None. |
token_ids |
Tensor | None
|
Token ids of shape |
attention_mask |
Tensor | None
|
Attention mask matching |
is_single |
bool
|
Whether the originating call passed a single (non-batched) prompt. |
message_handled |
frozenset[int]
|
|
Source code in steerability/algorithms/core/execution/payloads.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
attention_mask = None
class-attribute
instance-attribute
is_single = True
class-attribute
instance-attribute
message_handled = frozenset()
class-attribute
instance-attribute
messages = None
class-attribute
instance-attribute
text = None
class-attribute
instance-attribute
token_ids = None
class-attribute
instance-attribute
from_messages(messages)
classmethod
Build a message-form prompt from one conversation.
Source code in steerability/algorithms/core/execution/payloads.py
216 217 218 219 | |
from_text(text)
classmethod
Build a text-form prompt.
Source code in steerability/algorithms/core/execution/payloads.py
211 212 213 214 | |
from_token_ids(token_ids, attention_mask=None)
classmethod
Build a token-form prompt from a 1-D or [1, seq_len] tensor or a list[int].
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in steerability/algorithms/core/execution/payloads.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
resolve_token_ids(tokenizer)
Return a token-form copy of this prompt, tokenizing text or messages when needed.
Text prompts tokenize via tokenizer(...); message prompts via
tokenizer.apply_chat_template(..., add_generation_prompt=True). Both match the
pipeline's own tokenization calls. A prompt already in token form is returned unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokenizer
|
PreTrainedTokenizerBase | None
|
The pipeline tokenizer. |
required |
Returns:
| Type | Description |
|---|---|
PreparedPrompt
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If tokenization is required but |
Source code in steerability/algorithms/core/execution/payloads.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
ProcessorKinds
dataclass
Engine-hosted logit-processor kinds a backend executes, by permanent wire name.
Attributes:
| Name | Type | Description |
|---|---|---|
processors |
frozenset[str]
|
Processor kinds, e.g. |
Source code in steerability/algorithms/core/execution/contracts.py
95 96 97 98 99 100 101 102 103 104 105 106 107 | |
processors = frozenset()
class-attribute
instance-attribute
contains(required)
Return True when every required kind name is advertised.
Source code in steerability/algorithms/core/execution/contracts.py
105 106 107 | |
ProcessorSpec
dataclass
A serialized per-step logit processor for backends advertising engine-hosted logit math.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
The advertised processor kind name, e.g. |
params |
Mapping[str, Any]
|
Processor parameters. |
Source code in steerability/algorithms/core/execution/payloads.py
411 412 413 414 415 416 417 418 419 420 421 | |
kind
instance-attribute
params = field(default_factory=dict)
class-attribute
instance-attribute
ProcessorSpecEntry
dataclass
One output control's engine-hosted processor contribution.
Attributes:
| Name | Type | Description |
|---|---|---|
spec |
ProcessorSpec
|
The serialized processor. |
Source code in steerability/algorithms/core/execution/payloads.py
522 523 524 525 526 527 528 529 530 | |
spec
instance-attribute
Requirements
dataclass
Phase-keyed backend requirements computed by a control instance.
Each phase holds a tuple of Alternatives (a disjunction); an empty tuple requires nothing
beyond the session contract, which includes the model layout. The steer phase carries no
requirements; a control declares its steer-time model access through steer_access().
Attributes:
| Name | Type | Description |
|---|---|---|
generate |
tuple[Alternative, ...]
|
Alternatives for the generate phase. |
score |
tuple[Alternative, ...]
|
Alternatives for the score phase. |
spec_constraints |
tuple[SpecConstraint, ...]
|
Backend-configuration predicates, each evaluated against the spec of every phase it names. |
Source code in steerability/algorithms/core/execution/contracts.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
generate = ()
class-attribute
instance-attribute
score = ()
class-attribute
instance-attribute
spec_constraints = ()
class-attribute
instance-attribute
for_phase(phase)
The alternatives for phase (one of "generate", "score").
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in steerability/algorithms/core/execution/contracts.py
322 323 324 325 326 327 328 329 330 | |
ScoringItem
dataclass
One prompt's unit of scoring work (teacher-forced reference tokens).
Only controls participating in scoring contribute entries, and stopping criteria are never applied (there is no loop to stop).
Attributes:
| Name | Type | Description |
|---|---|---|
prompt |
PreparedPrompt
|
The prepared prompt. |
ref_output_ids |
Tensor
|
Reference tokens to score, shape |
state_entries |
tuple[StateControlEntry, ...]
|
Enabled state controls' contributions, in controls-list order. |
output_entries |
tuple[OutputControlEntry, ...]
|
Scoring-participant output controls' contributions, in controls-list order. |
Source code in steerability/algorithms/core/execution/payloads.py
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | |
output_entries = ()
class-attribute
instance-attribute
prompt
instance-attribute
ref_output_ids
instance-attribute
state_entries = ()
class-attribute
instance-attribute
SpecConstraint
dataclass
A predicate over a resolved BackendSpec, for backend-configuration facts.
Attributes:
| Name | Type | Description |
|---|---|---|
description |
str
|
The unsupported-verdict message shown when the predicate fails. It should name the conflict and a fix. |
predicate |
Callable[[BackendSpec], bool]
|
Callable evaluated against the phase's |
phases |
tuple[str, ...]
|
Phases whose backend spec the predicate is evaluated against. |
Source code in steerability/algorithms/core/execution/contracts.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
description
instance-attribute
phases = ('generate',)
class-attribute
instance-attribute
predicate
instance-attribute
StackEntry
dataclass
One output control's live processor and criteria contribution, consumed by in-process sessions.
Attributes:
| Name | Type | Description |
|---|---|---|
logits_processors |
tuple
|
HF |
stopping_criteria |
tuple
|
HF |
Source code in steerability/algorithms/core/execution/payloads.py
494 495 496 497 498 499 500 501 502 503 504 505 | |
logits_processors = ()
class-attribute
instance-attribute
stopping_criteria = ()
class-attribute
instance-attribute
SteerPlan
dataclass
The deterministic steer plan for one backend configuration.
A pure function of the enabled controls' declarations and the backend spec, so the same configuration always yields the same plan.
Attributes:
| Name | Type | Description |
|---|---|---|
steps |
tuple[PlannedStep, ...]
|
Every enabled control, in pipeline order. |
fits |
tuple[PlannedFit, ...]
|
Every fit artifact the steer phase will run, in pipeline order. |
stages |
bool
|
True when a staged in-process model will be constructed. |
notices |
tuple[str, ...]
|
Deterministic warnings the steer phase will emit (calibration crossings). |
Source code in steerability/algorithms/core/execution/access.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
fits = ()
class-attribute
instance-attribute
notices = ()
class-attribute
instance-attribute
stages = False
class-attribute
instance-attribute
steps = ()
class-attribute
instance-attribute
SteeringSession
Bases: Protocol
One logical operation's scope on a backend; the unit of concurrency.
A session is opened per logical operation (one generation fan-out, one scoring call, one
steer-phase fit) on every backend. The Backend owns the loaded model or engine; a session
holds only per-operation state. Session-contract facts, provided by every backend and
therefore never capability atoms, include token-id prompts, stop rules, minimum tokens,
multiple candidates, seeded sampling, prompt-logprob scoring, and the model layout.
Source code in steerability/algorithms/core/execution/backend.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
layout
property
Structural facts about the session's model.
capture(prompts, layers, mode, location='layer_output')
Capture hidden states for prompts at layers; requires
Capability.HIDDEN_CAPTURE.
Source code in steerability/algorithms/core/execution/backend.py
69 70 71 72 73 74 75 76 77 78 | |
generate(items, params)
Generate one result per item, in item order.
Source code in steerability/algorithms/core/execution/backend.py
52 53 54 55 56 57 58 | |
score(items, params)
Teacher-forced log-probabilities of each item's reference tokens, shape
[num_items, ref_len].
Source code in steerability/algorithms/core/execution/backend.py
60 61 62 63 64 65 66 67 | |
SupportFailure
dataclass
One unsupported verdict.
Attributes:
| Name | Type | Description |
|---|---|---|
control |
str
|
Class name of the failing control. |
phase |
str
|
The phase the verdict applies to ( |
message |
str
|
Stable, tested message naming the gap and a fix. |
Source code in steerability/algorithms/core/execution/contracts.py
357 358 359 360 361 362 363 364 365 366 367 368 369 | |
control
instance-attribute
message
instance-attribute
phase
instance-attribute
SupportReport
dataclass
The result of evaluating every enabled control against a backend.
Attributes:
| Name | Type | Description |
|---|---|---|
spec |
BackendSpec
|
The backend spec the phases were evaluated against. |
plan |
SteerPlan
|
The deterministic steer plan for this configuration. |
failures |
tuple[SupportFailure, ...]
|
All unsupported verdicts, in controls-list order then phase order. |
Source code in steerability/algorithms/core/execution/contracts.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
failures = ()
class-attribute
instance-attribute
ok
property
True when no phase of any enabled control is unsupported.
plan = field(default_factory=SteerPlan)
class-attribute
instance-attribute
spec
instance-attribute
failures_for(*phases)
The failures whose phase is among phases.
Source code in steerability/algorithms/core/execution/contracts.py
391 392 393 | |
raise_for(*phases)
Raise UnsupportedPipelineError listing every failing control in phases, if any.
Source code in steerability/algorithms/core/execution/contracts.py
399 400 401 402 | |
supported(*phases)
True when no failure falls in any of phases.
Source code in steerability/algorithms/core/execution/contracts.py
395 396 397 | |
TransportError
Bases: RuntimeError
A transport-level failure (connection, timeout, or server-side 5xx) that is safe to retry.
Application-level rejections (validation errors, unknown parameters) are not transport errors and must not be wrapped in this type.
Source code in steerability/algorithms/core/execution/fanout.py
40 41 42 43 44 45 | |
UnsupportedOperationError
Bases: RuntimeError
Raised when a session receives work it cannot execute on its backend.
Source code in steerability/algorithms/core/execution/contracts.py
353 354 | |
UnsupportedPipelineError
Bases: RuntimeError
Raised when an operation targets a backend that does not support the pipeline.
Attributes:
| Name | Type | Description |
|---|---|---|
report |
The |
Source code in steerability/algorithms/core/execution/contracts.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
report = report
instance-attribute
any_of(*alternatives)
Combine alternatives into a disjunction, satisfied by its first satisfied alternative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*alternatives
|
tuple[Alternative, ...] | Alternative
|
|
()
|
Returns:
| Type | Description |
|---|---|
tuple[Alternative, ...]
|
The flattened tuple of alternatives. |
Source code in steerability/algorithms/core/execution/contracts.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
as_constraint_source(value)
Coerce a mapping with kind and value keys into a ConstraintSource.
Source code in steerability/algorithms/core/execution/payloads.py
65 66 67 68 69 70 71 72 73 | |
capabilities_for_spec(spec)
The capability advertisement implied by spec, without constructing a backend.
Source code in steerability/algorithms/core/execution/backend.py
243 244 245 | |
derive_item_seed(base_seed, operation_id, item_index)
Derive one item's sampling seed from a base seed, an operation id, and the item index.
The derivation is SHA-256("{base_seed}:{operation_id}:{item_index}") truncated to the
first eight bytes (big-endian) and masked to 63 bits, so the result is a stable non-negative
integer accepted by every backend sampler. Distinct item indices under one operation yield
distinct streams while the whole fan-out stays reproducible from base_seed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_seed
|
int
|
The caller-supplied seed. |
required |
operation_id
|
str
|
Identifier of the logical operation (stable across reruns). |
required |
item_index
|
int
|
Position of the item in the submitted sequence. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The derived seed in |
Source code in steerability/algorithms/core/execution/fanout.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
evaluate_support(controls, spec, capabilities)
Evaluate every enabled control's requirements against a backend.
For each enabled control, control.requirements() is read once and each declared phase is
checked against the backend's capabilities. Spec constraints are checked for every phase
they name. Controls whose enabled attribute is False are skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
controls
|
Iterable[Any]
|
Control instances, in pipeline order. |
required |
spec
|
BackendSpec
|
The backend spec. |
required |
capabilities
|
BackendCapabilities
|
Capability advertisement of the backend. |
required |
Returns:
| Type | Description |
|---|---|
SupportReport
|
A |
SupportReport
|
and per violated spec constraint. |
Source code in steerability/algorithms/core/execution/contracts.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
merge_lowered_params(params, contribution)
Merge one control's sampling-expressible contribution into params.
Stop strings and stop token ids union with the caller's (caller entries first, duplicates
dropped); max_new_tokens takes the minimum and min_new_tokens the maximum of the present
values, so a control can only tighten the caller's bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
GenerationParams
|
The caller-derived parameters. |
required |
contribution
|
Mapping[str, Any]
|
Mapping over a subset of |
required |
Returns:
| Type | Description |
|---|---|
GenerationParams
|
The merged |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in steerability/algorithms/core/execution/params.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
needs(*atoms, kinds=None, hint=None)
Build a single-alternative phase requirement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*atoms
|
Capability
|
Capability atoms that must all be advertised. |
()
|
kinds
|
KindSet | tuple[KindSet, ...] | None
|
One kind set, or a tuple of kind sets, whose names must be contained in the backend's advertisement. |
None
|
hint
|
str | None
|
Optional fix text for unsupported-verdict messages. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Alternative, ...]
|
A one-element tuple of |
Source code in steerability/algorithms/core/execution/contracts.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
resolve_backend_class(spec)
The backend class registered for spec.kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
BackendSpec
|
The backend spec to resolve. |
required |
Returns:
| Type | Description |
|---|---|
type[Backend]
|
The backend class. Importing the class does not require the backend's optional |
type[Backend]
|
dependencies; constructing an instance may. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no backend class is registered for the spec's kind. |
Source code in steerability/algorithms/core/execution/backend.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
run_bounded(tasks, max_concurrency)
Run tasks concurrently with at most max_concurrency in flight.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasks
|
Sequence[Callable[[], Any]]
|
Zero-argument callables, one per item. |
required |
max_concurrency
|
int
|
Maximum number of concurrently running tasks (at least 1). |
required |
Returns:
| Type | Description |
|---|---|
list[Any | Exception]
|
One entry per task in task order: the task's return value, or the exception it raised. |
Source code in steerability/algorithms/core/execution/fanout.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
with_transport_retries(fn, *, max_attempts=3, backoff_base=0.5, sleep=time.sleep)
Call fn, retrying TransportErrors with exponential backoff.
Only TransportError triggers a retry; every other exception propagates immediately, since
an application-level rejection will not change on resubmission.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[[], Any]
|
Zero-argument callable issuing one request. |
required |
max_attempts
|
int
|
Total attempts including the first. |
3
|
backoff_base
|
float
|
Sleep before attempt |
0.5
|
sleep
|
Callable[[float], None]
|
Sleep function (injectable for tests). |
sleep
|
Returns:
| Type | Description |
|---|---|
Any
|
|
Raises:
| Type | Description |
|---|---|
TransportError
|
The last attempt's error when every attempt failed. |
Source code in steerability/algorithms/core/execution/fanout.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
access
Model access declarations and the steer plan.
ModelAccess names what a control's steer step requires of the pipeline model. The pipeline
satisfies every declaration deterministically: the bottom two rungs through the backend's
session, CAPTURE through session capture where advertised and a staged in-process model where
not, and MODULE through a staged in-process model always. SteerPlan records, per enabled
control and per fit artifact, where the pipeline will run each steer step for one backend
configuration.
ArtifactClass = Literal['direction', 'calibrated']
module-attribute
Venue = Literal['live', 'session', 'stage']
module-attribute
ModelAccess
Bases: IntEnum
What a control's steer step requires of the pipeline model, as a cumulative ladder.
Attributes:
| Name | Type | Description |
|---|---|---|
FACTS |
Structural facts ( |
|
ROLLOUTS |
FACTS plus generation and scoring through the session. |
|
CAPTURE |
ROLLOUTS plus hidden-state capture through the session. |
|
MODULE |
The model as a live |
Source code in steerability/algorithms/core/execution/access.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
CAPTURE = 2
class-attribute
instance-attribute
FACTS = 0
class-attribute
instance-attribute
MODULE = 3
class-attribute
instance-attribute
ROLLOUTS = 1
class-attribute
instance-attribute
PlannedFit
dataclass
One fit artifact's venue in the plan.
Fits execute inside their owning control's steer step, so a fit's venue is the step's.
Attributes:
| Name | Type | Description |
|---|---|---|
control |
str
|
Class name of the control whose steer runs the fit. |
artifact |
str
|
Class name of the fit source or recipe, e.g. |
artifact_class |
ArtifactClass
|
|
venue |
Venue
|
Where the fit runs. |
Source code in steerability/algorithms/core/execution/access.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
artifact
instance-attribute
artifact_class
instance-attribute
control
instance-attribute
venue
instance-attribute
PlannedStep
dataclass
One enabled control's steer step in the plan.
Attributes:
| Name | Type | Description |
|---|---|---|
control |
str
|
Class name of the control. |
access |
ModelAccess
|
The control's declared steer access. |
venue |
Venue
|
Where the step runs. |
Source code in steerability/algorithms/core/execution/access.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
access
instance-attribute
control
instance-attribute
venue
instance-attribute
SteerPlan
dataclass
The deterministic steer plan for one backend configuration.
A pure function of the enabled controls' declarations and the backend spec, so the same configuration always yields the same plan.
Attributes:
| Name | Type | Description |
|---|---|---|
steps |
tuple[PlannedStep, ...]
|
Every enabled control, in pipeline order. |
fits |
tuple[PlannedFit, ...]
|
Every fit artifact the steer phase will run, in pipeline order. |
stages |
bool
|
True when a staged in-process model will be constructed. |
notices |
tuple[str, ...]
|
Deterministic warnings the steer phase will emit (calibration crossings). |
Source code in steerability/algorithms/core/execution/access.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
fits = ()
class-attribute
instance-attribute
notices = ()
class-attribute
instance-attribute
stages = False
class-attribute
instance-attribute
steps = ()
class-attribute
instance-attribute
backend
The backend seam: Backend, SteeringSession, the backend registry, and the
session wrapper drivers roll out through.
A Backend owns a loaded model, engine, or connection pool and its lifecycle, advertises
capabilities, and creates sessions. A SteeringSession is one logical operation's scope on a
backend and the unit of concurrency; sessions register hooks, execute items, and serve capture.
The registry is a fixed mapping over the core-owned backend kinds; backend modules are imported
on first resolution, so core carries no module-level dependency on steerability.backends.
SteeredSession
A SteeringSession whose generate and score inject a generation's control entries
into every item, so a driver's rollouts carry the pipeline's steering without the driver
knowing entries exist.
The pipeline builds one wrapper per logical generation and hands it to the decoding driver. On an in-process backend the injected tuple is empty, since the session hosts the generation's hooks ambiently for the span of the driver's decode; on spec-consuming backends the injected entries are the generation's lowered interventions with prompt-relative scopes rewritten to absolute positions at the generation's original prompt boundary, so re-prefilled continuation tokens are steered at their original positions.
Attributes:
| Name | Type | Description |
|---|---|---|
inner |
The wrapped backend session. |
|
state_entries |
Entries injected ahead of each item's own. |
|
generated_tokens |
Running non-pad token count over every |
Source code in steerability/algorithms/core/execution/backend.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
generated_tokens = 0
instance-attribute
inner = inner
instance-attribute
layout
property
state_entries = tuple(state_entries)
instance-attribute
tokenizer
property
capture(prompts, layers, mode, location='layer_output')
Capture through the wrapped session, unsteered.
Source code in steerability/algorithms/core/execution/backend.py
141 142 143 | |
generate(items, params)
Generate with the wrapper's entries injected into every item, accumulating the non-pad
token count of every returned output into generated_tokens.
Source code in steerability/algorithms/core/execution/backend.py
124 125 126 127 128 129 130 131 132 133 134 135 | |
score(items, params)
Score with the wrapper's entries injected into every item.
Source code in steerability/algorithms/core/execution/backend.py
137 138 139 | |
SteeringSession
Bases: Protocol
One logical operation's scope on a backend; the unit of concurrency.
A session is opened per logical operation (one generation fan-out, one scoring call, one
steer-phase fit) on every backend. The Backend owns the loaded model or engine; a session
holds only per-operation state. Session-contract facts, provided by every backend and
therefore never capability atoms, include token-id prompts, stop rules, minimum tokens,
multiple candidates, seeded sampling, prompt-logprob scoring, and the model layout.
Source code in steerability/algorithms/core/execution/backend.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
layout
property
Structural facts about the session's model.
capture(prompts, layers, mode, location='layer_output')
Capture hidden states for prompts at layers; requires
Capability.HIDDEN_CAPTURE.
Source code in steerability/algorithms/core/execution/backend.py
69 70 71 72 73 74 75 76 77 78 | |
generate(items, params)
Generate one result per item, in item order.
Source code in steerability/algorithms/core/execution/backend.py
52 53 54 55 56 57 58 | |
score(items, params)
Teacher-forced log-probabilities of each item's reference tokens, shape
[num_items, ref_len].
Source code in steerability/algorithms/core/execution/backend.py
60 61 62 63 64 65 66 67 | |
capabilities_for_spec(spec)
The capability advertisement implied by spec, without constructing a backend.
Source code in steerability/algorithms/core/execution/backend.py
243 244 245 | |
resolve_backend_class(spec)
The backend class registered for spec.kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
BackendSpec
|
The backend spec to resolve. |
required |
Returns:
| Type | Description |
|---|---|
type[Backend]
|
The backend class. Importing the class does not require the backend's optional |
type[Backend]
|
dependencies; constructing an instance may. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no backend class is registered for the spec's kind. |
Source code in steerability/algorithms/core/execution/backend.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
contracts
Backend contracts: capability advertisement, the requirement language, and support verdicts.
A capability atom marks a mechanism that some control requirement can fail on; facts true of
every backend belong to the session protocol contract instead. Kind sets state which activation
edits, per-step logit processors, capture forms, and native constraints a capable backend
executes. Controls state what a backend must provide as phase-keyed Requirements, and
evaluate_support renders binary per-control, per-phase verdicts against the pipeline's
backend. The steer phase produces no verdicts; steer-time model access is declared through
ModelAccess and satisfied by the pipeline's steer plan.
KindSet = InterventionKinds | ProcessorKinds | CaptureKinds | ConstraintKinds
module-attribute
PHASES = ('generate', 'score')
module-attribute
Alternative
dataclass
One way to satisfy a phase requirement, i.e., a conjunction of capability atoms with optional kind predicates over the backend's advertised kind sets.
Attributes:
| Name | Type | Description |
|---|---|---|
atoms |
frozenset[Capability]
|
Capability atoms that must all be advertised. |
kinds |
tuple[KindSet, ...]
|
Kind sets whose names must all be contained in the backend's advertisement of the corresponding kind-set type. |
hint |
str | None
|
Optional fix text used in unsupported-verdict messages in place of the default. |
Source code in steerability/algorithms/core/execution/contracts.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
atoms = frozenset()
class-attribute
instance-attribute
hint = None
class-attribute
instance-attribute
kinds = ()
class-attribute
instance-attribute
missing(capabilities)
Names of the atoms and kind sets this alternative needs but capabilities lacks.
Source code in steerability/algorithms/core/execution/contracts.py
205 206 207 208 209 210 211 212 | |
satisfied_by(capabilities)
Return True when every atom is advertised and every kind set is contained.
Source code in steerability/algorithms/core/execution/contracts.py
195 196 197 198 199 200 201 202 203 | |
BackendCapabilities
dataclass
A backend's full capability advertisement: atoms plus negotiated kind sets.
Attributes:
| Name | Type | Description |
|---|---|---|
atoms |
frozenset[Capability]
|
The advertised |
intervention_kinds |
InterventionKinds | None
|
Advertised intervention kinds, present when
|
processor_kinds |
ProcessorKinds | None
|
Advertised processor kinds, present when
|
capture_kinds |
CaptureKinds | None
|
Advertised capture kinds, present when |
constraint_kinds |
ConstraintKinds | None
|
Advertised constrained-decoding kinds, present when
|
Source code in steerability/algorithms/core/execution/contracts.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
atoms = frozenset()
class-attribute
instance-attribute
capture_kinds = None
class-attribute
instance-attribute
constraint_kinds = None
class-attribute
instance-attribute
intervention_kinds = None
class-attribute
instance-attribute
processor_kinds = None
class-attribute
instance-attribute
Capability
Bases: Enum
Distinguishing capability atoms advertised by backends.
Attributes:
| Name | Type | Description |
|---|---|---|
IN_PROCESS_TORCH |
The backend exposes the model as a live |
|
INTERVENTION_SPECS |
The backend executes activation interventions submitted as
|
|
PER_STEP_LOGIT_SPECS |
The backend hosts per-step logit math submitted as |
|
HIDDEN_CAPTURE |
The backend serves hidden-state capture through |
|
BEAM_PROPOSALS |
The backend implements beam-search proposal semantics ( |
|
SERVE_CHECKPOINT |
The backend can serve a checkpoint directory produced elsewhere. |
|
SERVE_LORA |
The backend can serve a LoRA adapter produced elsewhere. |
|
GUIDED_DECODING |
The backend hosts declarative constrained decoding natively, rendered
from a |
Source code in steerability/algorithms/core/execution/contracts.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
BEAM_PROPOSALS = 'beam_proposals'
class-attribute
instance-attribute
GUIDED_DECODING = 'guided_decoding'
class-attribute
instance-attribute
HIDDEN_CAPTURE = 'hidden_capture'
class-attribute
instance-attribute
INTERVENTION_SPECS = 'intervention_specs'
class-attribute
instance-attribute
IN_PROCESS_TORCH = 'in_process_torch'
class-attribute
instance-attribute
PER_STEP_LOGIT_SPECS = 'per_step_logit_specs'
class-attribute
instance-attribute
SERVE_CHECKPOINT = 'serve_checkpoint'
class-attribute
instance-attribute
SERVE_LORA = 'serve_lora'
class-attribute
instance-attribute
CaptureKinds
dataclass
Hidden-state capture forms a backend serves, by permanent wire name.
Attributes:
| Name | Type | Description |
|---|---|---|
kinds |
frozenset[str]
|
Capture kinds, e.g. |
locations |
frozenset[str]
|
Capture locations, e.g. |
modes |
frozenset[str]
|
Capture modes, e.g. |
Source code in steerability/algorithms/core/execution/contracts.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
kinds = frozenset()
class-attribute
instance-attribute
locations = frozenset()
class-attribute
instance-attribute
modes = frozenset()
class-attribute
instance-attribute
contains(required)
Return True when every required kind name is advertised.
Source code in steerability/algorithms/core/execution/contracts.py
124 125 126 127 128 129 130 | |
ConstraintKinds
dataclass
Constrained-decoding kinds a backend hosts natively, by declarative kind name.
The kind set is static per backend version (the engine's structured-output surface needs no
discovery), e.g. {"json_schema", "regex", "grammar", "choice"}.
Attributes:
| Name | Type | Description |
|---|---|---|
constraints |
frozenset[str]
|
Constraint kind names. |
Source code in steerability/algorithms/core/execution/contracts.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
constraints = frozenset()
class-attribute
instance-attribute
contains(required)
Return True when every required kind name is advertised.
Source code in steerability/algorithms/core/execution/contracts.py
146 147 148 | |
InterventionKinds
dataclass
Activation-intervention kinds a backend executes, by permanent wire name.
Wire names mirror toolkit class names (AdditiveTransform serializes as "additive",
SumThreshold as "sum_threshold"), so the mapping is definitional rather than
maintained. Kind names are permanent and their meanings never change; new behavior is a
new kind. Compatibility is set containment on kind names.
Attributes:
| Name | Type | Description |
|---|---|---|
transforms |
frozenset[str]
|
Transform kinds, e.g. |
modifiers |
frozenset[str]
|
Wrapper-transform kinds, e.g. |
scopes |
frozenset[str]
|
Token-scope kinds, e.g. |
readouts |
frozenset[str]
|
Gate readout kinds, e.g. |
rules |
frozenset[str]
|
Gate rule kinds, e.g. |
constraints |
Mapping[str, str]
|
Per-kind execution constraints, e.g.
|
Source code in steerability/algorithms/core/execution/contracts.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
constraints = field(default_factory=dict)
class-attribute
instance-attribute
modifiers = frozenset()
class-attribute
instance-attribute
readouts = frozenset()
class-attribute
instance-attribute
rules = frozenset()
class-attribute
instance-attribute
scopes = frozenset()
class-attribute
instance-attribute
transforms = frozenset()
class-attribute
instance-attribute
contains(required)
Return True when every required kind name is advertised.
Source code in steerability/algorithms/core/execution/contracts.py
84 85 86 87 88 89 90 91 92 | |
ProcessorKinds
dataclass
Engine-hosted logit-processor kinds a backend executes, by permanent wire name.
Attributes:
| Name | Type | Description |
|---|---|---|
processors |
frozenset[str]
|
Processor kinds, e.g. |
Source code in steerability/algorithms/core/execution/contracts.py
95 96 97 98 99 100 101 102 103 104 105 106 107 | |
processors = frozenset()
class-attribute
instance-attribute
contains(required)
Return True when every required kind name is advertised.
Source code in steerability/algorithms/core/execution/contracts.py
105 106 107 | |
Requirements
dataclass
Phase-keyed backend requirements computed by a control instance.
Each phase holds a tuple of Alternatives (a disjunction); an empty tuple requires nothing
beyond the session contract, which includes the model layout. The steer phase carries no
requirements; a control declares its steer-time model access through steer_access().
Attributes:
| Name | Type | Description |
|---|---|---|
generate |
tuple[Alternative, ...]
|
Alternatives for the generate phase. |
score |
tuple[Alternative, ...]
|
Alternatives for the score phase. |
spec_constraints |
tuple[SpecConstraint, ...]
|
Backend-configuration predicates, each evaluated against the spec of every phase it names. |
Source code in steerability/algorithms/core/execution/contracts.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
generate = ()
class-attribute
instance-attribute
score = ()
class-attribute
instance-attribute
spec_constraints = ()
class-attribute
instance-attribute
for_phase(phase)
The alternatives for phase (one of "generate", "score").
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in steerability/algorithms/core/execution/contracts.py
322 323 324 325 326 327 328 329 330 | |
SpecConstraint
dataclass
A predicate over a resolved BackendSpec, for backend-configuration facts.
Attributes:
| Name | Type | Description |
|---|---|---|
description |
str
|
The unsupported-verdict message shown when the predicate fails. It should name the conflict and a fix. |
predicate |
Callable[[BackendSpec], bool]
|
Callable evaluated against the phase's |
phases |
tuple[str, ...]
|
Phases whose backend spec the predicate is evaluated against. |
Source code in steerability/algorithms/core/execution/contracts.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
description
instance-attribute
phases = ('generate',)
class-attribute
instance-attribute
predicate
instance-attribute
SupportFailure
dataclass
One unsupported verdict.
Attributes:
| Name | Type | Description |
|---|---|---|
control |
str
|
Class name of the failing control. |
phase |
str
|
The phase the verdict applies to ( |
message |
str
|
Stable, tested message naming the gap and a fix. |
Source code in steerability/algorithms/core/execution/contracts.py
357 358 359 360 361 362 363 364 365 366 367 368 369 | |
control
instance-attribute
message
instance-attribute
phase
instance-attribute
SupportReport
dataclass
The result of evaluating every enabled control against a backend.
Attributes:
| Name | Type | Description |
|---|---|---|
spec |
BackendSpec
|
The backend spec the phases were evaluated against. |
plan |
SteerPlan
|
The deterministic steer plan for this configuration. |
failures |
tuple[SupportFailure, ...]
|
All unsupported verdicts, in controls-list order then phase order. |
Source code in steerability/algorithms/core/execution/contracts.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
failures = ()
class-attribute
instance-attribute
ok
property
True when no phase of any enabled control is unsupported.
plan = field(default_factory=SteerPlan)
class-attribute
instance-attribute
spec
instance-attribute
failures_for(*phases)
The failures whose phase is among phases.
Source code in steerability/algorithms/core/execution/contracts.py
391 392 393 | |
raise_for(*phases)
Raise UnsupportedPipelineError listing every failing control in phases, if any.
Source code in steerability/algorithms/core/execution/contracts.py
399 400 401 402 | |
supported(*phases)
True when no failure falls in any of phases.
Source code in steerability/algorithms/core/execution/contracts.py
395 396 397 | |
UnsupportedOperationError
Bases: RuntimeError
Raised when a session receives work it cannot execute on its backend.
Source code in steerability/algorithms/core/execution/contracts.py
353 354 | |
UnsupportedPipelineError
Bases: RuntimeError
Raised when an operation targets a backend that does not support the pipeline.
Attributes:
| Name | Type | Description |
|---|---|---|
report |
The |
Source code in steerability/algorithms/core/execution/contracts.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
report = report
instance-attribute
any_of(*alternatives)
Combine alternatives into a disjunction, satisfied by its first satisfied alternative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*alternatives
|
tuple[Alternative, ...] | Alternative
|
|
()
|
Returns:
| Type | Description |
|---|---|
tuple[Alternative, ...]
|
The flattened tuple of alternatives. |
Source code in steerability/algorithms/core/execution/contracts.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
evaluate_support(controls, spec, capabilities)
Evaluate every enabled control's requirements against a backend.
For each enabled control, control.requirements() is read once and each declared phase is
checked against the backend's capabilities. Spec constraints are checked for every phase
they name. Controls whose enabled attribute is False are skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
controls
|
Iterable[Any]
|
Control instances, in pipeline order. |
required |
spec
|
BackendSpec
|
The backend spec. |
required |
capabilities
|
BackendCapabilities
|
Capability advertisement of the backend. |
required |
Returns:
| Type | Description |
|---|---|
SupportReport
|
A |
SupportReport
|
and per violated spec constraint. |
Source code in steerability/algorithms/core/execution/contracts.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
needs(*atoms, kinds=None, hint=None)
Build a single-alternative phase requirement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*atoms
|
Capability
|
Capability atoms that must all be advertised. |
()
|
kinds
|
KindSet | tuple[KindSet, ...] | None
|
One kind set, or a tuple of kind sets, whose names must be contained in the backend's advertisement. |
None
|
hint
|
str | None
|
Optional fix text for unsupported-verdict messages. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Alternative, ...]
|
A one-element tuple of |
Source code in steerability/algorithms/core/execution/contracts.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
fanout
Per-item seed derivation, bounded fan-out, transport retries, and the partial-batch error.
Shared machinery for request-building sessions. Everything here is backend-agnostic and runs without any optional dependency.
logger = logging.getLogger(__name__)
module-attribute
PartialBatchError
Bases: RuntimeError
Raised when some items of a fan-out failed after retries while others succeeded.
Attributes:
| Name | Type | Description |
|---|---|---|
results |
The successful per-item results, in item order ( |
|
failures |
|
Source code in steerability/algorithms/core/execution/fanout.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
failed_indices
property
Indices of the failed items, re-issuable as a remainder batch.
failures = tuple(failures)
instance-attribute
results = tuple(results)
instance-attribute
TransportError
Bases: RuntimeError
A transport-level failure (connection, timeout, or server-side 5xx) that is safe to retry.
Application-level rejections (validation errors, unknown parameters) are not transport errors and must not be wrapped in this type.
Source code in steerability/algorithms/core/execution/fanout.py
40 41 42 43 44 45 | |
derive_item_seed(base_seed, operation_id, item_index)
Derive one item's sampling seed from a base seed, an operation id, and the item index.
The derivation is SHA-256("{base_seed}:{operation_id}:{item_index}") truncated to the
first eight bytes (big-endian) and masked to 63 bits, so the result is a stable non-negative
integer accepted by every backend sampler. Distinct item indices under one operation yield
distinct streams while the whole fan-out stays reproducible from base_seed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_seed
|
int
|
The caller-supplied seed. |
required |
operation_id
|
str
|
Identifier of the logical operation (stable across reruns). |
required |
item_index
|
int
|
Position of the item in the submitted sequence. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The derived seed in |
Source code in steerability/algorithms/core/execution/fanout.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
run_bounded(tasks, max_concurrency)
Run tasks concurrently with at most max_concurrency in flight.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasks
|
Sequence[Callable[[], Any]]
|
Zero-argument callables, one per item. |
required |
max_concurrency
|
int
|
Maximum number of concurrently running tasks (at least 1). |
required |
Returns:
| Type | Description |
|---|---|
list[Any | Exception]
|
One entry per task in task order: the task's return value, or the exception it raised. |
Source code in steerability/algorithms/core/execution/fanout.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
with_transport_retries(fn, *, max_attempts=3, backoff_base=0.5, sleep=time.sleep)
Call fn, retrying TransportErrors with exponential backoff.
Only TransportError triggers a retry; every other exception propagates immediately, since
an application-level rejection will not change on resubmission.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[[], Any]
|
Zero-argument callable issuing one request. |
required |
max_attempts
|
int
|
Total attempts including the first. |
3
|
backoff_base
|
float
|
Sleep before attempt |
0.5
|
sleep
|
Callable[[float], None]
|
Sleep function (injectable for tests). |
sleep
|
Returns:
| Type | Description |
|---|---|
Any
|
|
Raises:
| Type | Description |
|---|---|
TransportError
|
The last attempt's error when every attempt failed. |
Source code in steerability/algorithms/core/execution/fanout.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
params
Normalized generation parameters with one rendering rule per backend family.
LOWERABLE_PARAM_NAMES = ('stop_strings', 'stop_token_ids', 'max_new_tokens', 'min_new_tokens')
module-attribute
NORMALIZED_PARAM_NAMES = ('max_new_tokens', 'min_new_tokens', 'temperature', 'top_p', 'top_k', 'greedy', 'n', 'repetition_penalty', 'seed', 'seed_scope', 'stop_strings', 'stop_token_ids')
module-attribute
SEED_SCOPES = ('item', 'dispatch')
module-attribute
GenerationParams
dataclass
The sampling-facing subset of generation parameters, normalized across backends.
Each backend family owns one rendering rule. In-process, the normalized fields render onto
model.generate names and every key in extra passes through untouched. On API backends
the normalized table is exhaustive and unmapped parameters raise, so extra is rejected
there.
Attributes:
| Name | Type | Description |
|---|---|---|
max_new_tokens |
int | None
|
Maximum number of new tokens. |
min_new_tokens |
int | None
|
Minimum number of new tokens. |
temperature |
float | None
|
Sampling temperature. |
top_p |
float | None
|
Nucleus-sampling probability mass. |
top_k |
int | None
|
Top-k sampling cutoff. |
greedy |
bool | None
|
True forces greedy decoding, False forces sampling, None leaves the backend default. |
n |
int | None
|
Number of returned candidates per prompt. |
repetition_penalty |
float | None
|
Repetition penalty. |
seed |
int | None
|
Sampling seed. In-process it renders as a |
seed_scope |
Literal['item', 'dispatch']
|
How a call-level |
stop_strings |
tuple[str, ...]
|
Stop strings, composed by the session as stop rules on both backend families. Token ids are returned as generated; the pipeline truncates decoded text at the first stop-string occurrence. |
stop_token_ids |
tuple[int, ...]
|
Token ids that halt a row once its last generated token is one of them, in addition to the tokenizer's EOS. |
extra |
Mapping[str, Any]
|
Additional keyword arguments passed through unmapped on the in-process arm. A
normalized field always takes precedence over a same-named key in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in steerability/algorithms/core/execution/params.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
extra = field(default_factory=dict)
class-attribute
instance-attribute
greedy = None
class-attribute
instance-attribute
max_new_tokens = None
class-attribute
instance-attribute
min_new_tokens = None
class-attribute
instance-attribute
n = None
class-attribute
instance-attribute
repetition_penalty = None
class-attribute
instance-attribute
seed = None
class-attribute
instance-attribute
seed_scope = 'item'
class-attribute
instance-attribute
stop_strings = ()
class-attribute
instance-attribute
stop_token_ids = ()
class-attribute
instance-attribute
temperature = None
class-attribute
instance-attribute
top_k = None
class-attribute
instance-attribute
top_p = None
class-attribute
instance-attribute
from_gen_kwargs(**gen_kwargs)
classmethod
Split keyword arguments into normalized fields and pass-through extras.
do_sample maps onto greedy (inverted) and num_return_sequences onto n; keys named
exactly like a normalized field bind to it; everything else lands in extra.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**gen_kwargs
|
Any
|
Generation keyword arguments in |
{}
|
Returns:
| Type | Description |
|---|---|
GenerationParams
|
The normalized |
Source code in steerability/algorithms/core/execution/params.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
to_gen_kwargs()
Render the parameters back into model.generate-vocabulary keyword arguments.
This inverts from_gen_kwargs, so greedy renders as do_sample (inverted), n as
num_return_sequences, the stop fields and seed keep their normalized names,
seed_scope renders only when it is not the default "item", and extra merges
underneath the normalized fields.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The keyword arguments; |
dict[str, Any]
|
|
Source code in steerability/algorithms/core/execution/params.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
merge_lowered_params(params, contribution)
Merge one control's sampling-expressible contribution into params.
Stop strings and stop token ids union with the caller's (caller entries first, duplicates
dropped); max_new_tokens takes the minimum and min_new_tokens the maximum of the present
values, so a control can only tighten the caller's bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
GenerationParams
|
The caller-derived parameters. |
required |
contribution
|
Mapping[str, Any]
|
Mapping over a subset of |
required |
Returns:
| Type | Description |
|---|---|
GenerationParams
|
The merged |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in steerability/algorithms/core/execution/params.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
payloads
Payload types crossing the pipeline/backend seam.
Structural model facts, prepared prompts, steer-time artifacts, declarative constraint
sources, serialized interventions and processors, and the per-item units of session work with
the per-category control contributions they carry. A field on an item holds either an
artifact, named for what it is (prompt, ref_output_ids, seed), or the per-call
contributions of one control category, named <category>_entries. An entry is one enabled
control's contribution for this call, in controls-list order, in whichever representation the
session consumes. An item never holds a control object.
Artifact = ModelArtifact | CheckpointArtifact | LoRAArtifact
module-attribute
CONSTRAINT_KINDS = ('json_schema', 'regex', 'grammar', 'choice')
module-attribute
OutputControlEntry = StackEntry | ProcessorSpecEntry | ConstraintEntry
module-attribute
StateControlEntry = HookEntry | InterventionEntry
module-attribute
ArtifactProvenance
dataclass
Identity of the side that produced an artifact.
Attributes:
| Name | Type | Description |
|---|---|---|
backend_spec_hash |
str | None
|
|
model_fingerprint |
str | None
|
Fingerprint of the producing model. |
tokenizer_fingerprint |
str | None
|
Fingerprint of the producing tokenizer and chat template. |
Source code in steerability/algorithms/core/execution/payloads.py
112 113 114 115 116 117 118 119 120 121 122 123 124 | |
backend_spec_hash = None
class-attribute
instance-attribute
model_fingerprint = None
class-attribute
instance-attribute
tokenizer_fingerprint = None
class-attribute
instance-attribute
CaptureResult
dataclass
Hidden states captured by SteeringSession.capture.
Attributes:
| Name | Type | Description |
|---|---|---|
hidden |
Mapping[int, Tensor]
|
Tensors keyed by 0-based layer id. Shape |
attention_mask |
Tensor
|
Mask of shape |
mode |
str
|
The capture mode the tensors were produced under. |
location |
str
|
The capture location ( |
Source code in steerability/algorithms/core/execution/payloads.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 | |
attention_mask
instance-attribute
hidden
instance-attribute
location
instance-attribute
mode
instance-attribute
CheckpointArtifact
dataclass
A checkpoint directory handed across the role boundary; consuming it requires
Capability.SERVE_CHECKPOINT.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
Checkpoint directory path. |
provenance |
ArtifactProvenance
|
Identity of the producing side. |
Source code in steerability/algorithms/core/execution/payloads.py
141 142 143 144 145 146 147 148 149 150 151 152 | |
path
instance-attribute
provenance = field(default_factory=ArtifactProvenance)
class-attribute
instance-attribute
ConstraintEntry
dataclass
An output control's contribution as a declarative constrained-decoding source.
Consumed by backends advertising Capability.GUIDED_DECODING, rendered onto the engine's
native structured-output request parameters in place of the control's live processor.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
ConstraintSource
|
The declarative constraint. |
Source code in steerability/algorithms/core/execution/payloads.py
508 509 510 511 512 513 514 515 516 517 518 519 | |
source
instance-attribute
ConstraintSource
dataclass
A declarative constrained-decoding specification.
The portable form of the constraint class: one source renders per execution arm, compiled into a client-side automaton in process and onto the engine's native structured-output request parameters on vLLM backends.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['json_schema', 'regex', 'grammar', 'choice']
|
The constraint kind: |
value |
str | Mapping | Sequence[str]
|
The constraint payload: a schema string or mapping for |
Source code in steerability/algorithms/core/execution/payloads.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
kind
instance-attribute
value
instance-attribute
GenerationItem
dataclass
One prompt's unit of generation work.
Input controls have no entry because their contribution is already folded into prompt;
structural controls have none because they contribute at steer time through artifacts.
Attributes:
| Name | Type | Description |
|---|---|---|
prompt |
PreparedPrompt
|
The prepared prompt. |
state_entries |
tuple[StateControlEntry, ...]
|
Enabled state controls' contributions, in controls-list order. |
output_entries |
tuple[OutputControlEntry, ...]
|
Enabled output controls' contributions, in controls-list order. |
seed |
int | None
|
Per-item sampling seed, or None for unseeded operation. |
Source code in steerability/algorithms/core/execution/payloads.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 | |
output_entries = ()
class-attribute
instance-attribute
prompt
instance-attribute
seed = None
class-attribute
instance-attribute
state_entries = ()
class-attribute
instance-attribute
HookEntry
dataclass
One state control's torch-hook contribution, consumed by in-process sessions.
Attributes:
| Name | Type | Description |
|---|---|---|
hooks |
Mapping[str, list]
|
Hook specifications keyed by phase ( |
Source code in steerability/algorithms/core/execution/payloads.py
467 468 469 470 471 472 473 474 475 476 | |
hooks
instance-attribute
InterventionEntry
dataclass
One state control's intervention-spec contribution, consumed by intervention-capable backends.
Attributes:
| Name | Type | Description |
|---|---|---|
spec |
InterventionSpec
|
The serialized intervention. |
Source code in steerability/algorithms/core/execution/payloads.py
479 480 481 482 483 484 485 486 487 488 | |
spec
instance-attribute
InterventionSpec
dataclass
A serialized activation intervention for intervention-capable backends.
Each op names its target layers, a transform (kind, scalar parameters, tensor payloads by artifact reference, and an ordered modifier list), a token scope, and an optional gate. Kind names are the advertised wire names; a worker rejects a spec containing a kind or field it does not list.
Attributes:
| Name | Type | Description |
|---|---|---|
ops |
tuple[Mapping[str, Any], ...]
|
The intervention ops, each a mapping with keys |
artifacts |
Mapping[str, Mapping[str, Any]]
|
Tensor payloads keyed by the content-addressed artifact ids the ops reference, each a mapping from tensor name to a float32 contiguous CPU tensor. Sessions materialize these into the registry the serving engine reads before submission. Excluded from equality, the wire form, and the canonical form. |
Source code in steerability/algorithms/core/execution/payloads.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
artifacts = field(default_factory=dict, compare=False)
class-attribute
instance-attribute
ops = ()
class-attribute
instance-attribute
artifact_ids()
Sorted unique artifact ids referenced anywhere in the ops (transform payloads, modifiers, and gate readouts).
Source code in steerability/algorithms/core/execution/payloads.py
337 338 339 340 341 342 | |
canonical()
The canonical serialization, the form hashed for cache salting and provenance.
Delegates to vllm_hook_plugins.core.canonical.canonical_bytes (sorted keys, compact
separators, UTF-8), so the toolkit and the plugin agree byte-for-byte on the canonical
form of a spec.
Raises:
| Type | Description |
|---|---|
ModuleNotFoundError
|
If |
TypeError
|
If an op contains a value with no JSON form. Tensors belong in artifacts, never inline. |
Source code in steerability/algorithms/core/execution/payloads.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
required_kinds()
The kind names this spec requires a backend to serve, as an InterventionKinds.
Collects transform, modifier, scope, and gate readout/rule kind names from the ops; a backend whose negotiated kinds contain them can execute the spec.
Source code in steerability/algorithms/core/execution/payloads.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
salt()
The reference cache salt for requests carrying this spec.
Delegates to vllm_hook_plugins.core.canonical.request_salt over the wire form and
the referenced artifact ids. Returns the 64-char lowercase-hex digest.
Raises:
| Type | Description |
|---|---|
ModuleNotFoundError
|
If |
Source code in steerability/algorithms/core/execution/payloads.py
397 398 399 400 401 402 403 404 405 406 407 408 | |
to_wire()
The plain-data wire form, {"ops": [...]}, with nested mappings and sequences
converted to dicts and lists.
Source code in steerability/algorithms/core/execution/payloads.py
332 333 334 335 | |
ItemResult
dataclass
The result of one generation item.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
Position of the item in the submitted sequence. |
output |
Output
|
The generation record. For |
Source code in steerability/algorithms/core/execution/payloads.py
577 578 579 580 581 582 583 584 585 586 587 588 | |
index
instance-attribute
output
instance-attribute
LoRAArtifact
dataclass
A LoRA adapter handed across the role boundary; consuming it requires
Capability.SERVE_LORA.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
Adapter directory path. |
base_model |
str
|
Model reference the adapter applies to. |
provenance |
ArtifactProvenance
|
Identity of the producing side. |
Source code in steerability/algorithms/core/execution/payloads.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
base_model
instance-attribute
path
instance-attribute
provenance = field(default_factory=ArtifactProvenance)
class-attribute
instance-attribute
ModelArtifact
dataclass
An in-memory model handed across the role boundary; only the in-process backend can consume it.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
Any
|
The loaded model. |
provenance |
ArtifactProvenance
|
Identity of the producing side. |
Source code in steerability/algorithms/core/execution/payloads.py
127 128 129 130 131 132 133 134 135 136 137 138 | |
model
instance-attribute
provenance = field(default_factory=ArtifactProvenance)
class-attribute
instance-attribute
ModelFacts
dataclass
Structural facts about the pipeline model, available without a live module tree.
Layer indices are the canonical coordinates for steer-phase layer selection; module names are an in-process serialization detail resolved only at hook construction time. Client-side tensor preparation uses the layout's dtype, and device placement is handled in process or by the worker rather than at steer time.
Attributes:
| Name | Type | Description |
|---|---|---|
num_layers |
int
|
Number of decoder layers. |
hidden_size |
int
|
Residual-stream width. |
num_attention_heads |
int | None
|
Number of attention heads, or None when the model config does not state one. |
head_dim |
int | None
|
Per-head dimension, the config's nominal value (else |
dtype |
str
|
Canonical dtype string, e.g. |
model_fingerprint |
str
|
A 16-character hex digest identifying the model weights and config. |
model_type |
str | None
|
The config's |
model_ref |
str | None
|
The served model reference on engine backends, the loaded model's
|
Source code in steerability/algorithms/core/execution/payloads.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
dtype
instance-attribute
head_dim
instance-attribute
hidden_size
instance-attribute
model_fingerprint
instance-attribute
model_ref = None
class-attribute
instance-attribute
model_type = None
class-attribute
instance-attribute
num_attention_heads
instance-attribute
num_layers
instance-attribute
PreparedPrompt
dataclass
A sum type over messages | text | token_ids for one prompt, plus metadata.
Exactly one of text, messages, or token_ids is set at construction. Tokenization is
forced only when a consumer needs token ids (resolve_token_ids); the in-process resolution
reproduces the pipeline's tokenization calls, so resolved ids match the early-tokenized path.
Attributes:
| Name | Type | Description |
|---|---|---|
text |
str | None
|
A plain-text prompt, or None. |
messages |
tuple[Mapping, ...] | None
|
One conversation as a tuple of message mappings, or None. |
token_ids |
Tensor | None
|
Token ids of shape |
attention_mask |
Tensor | None
|
Attention mask matching |
is_single |
bool
|
Whether the originating call passed a single (non-batched) prompt. |
message_handled |
frozenset[int]
|
|
Source code in steerability/algorithms/core/execution/payloads.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
attention_mask = None
class-attribute
instance-attribute
is_single = True
class-attribute
instance-attribute
message_handled = frozenset()
class-attribute
instance-attribute
messages = None
class-attribute
instance-attribute
text = None
class-attribute
instance-attribute
token_ids = None
class-attribute
instance-attribute
from_messages(messages)
classmethod
Build a message-form prompt from one conversation.
Source code in steerability/algorithms/core/execution/payloads.py
216 217 218 219 | |
from_text(text)
classmethod
Build a text-form prompt.
Source code in steerability/algorithms/core/execution/payloads.py
211 212 213 214 | |
from_token_ids(token_ids, attention_mask=None)
classmethod
Build a token-form prompt from a 1-D or [1, seq_len] tensor or a list[int].
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in steerability/algorithms/core/execution/payloads.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
resolve_token_ids(tokenizer)
Return a token-form copy of this prompt, tokenizing text or messages when needed.
Text prompts tokenize via tokenizer(...); message prompts via
tokenizer.apply_chat_template(..., add_generation_prompt=True). Both match the
pipeline's own tokenization calls. A prompt already in token form is returned unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokenizer
|
PreTrainedTokenizerBase | None
|
The pipeline tokenizer. |
required |
Returns:
| Type | Description |
|---|---|
PreparedPrompt
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If tokenization is required but |
Source code in steerability/algorithms/core/execution/payloads.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
ProcessorSpec
dataclass
A serialized per-step logit processor for backends advertising engine-hosted logit math.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
The advertised processor kind name, e.g. |
params |
Mapping[str, Any]
|
Processor parameters. |
Source code in steerability/algorithms/core/execution/payloads.py
411 412 413 414 415 416 417 418 419 420 421 | |
kind
instance-attribute
params = field(default_factory=dict)
class-attribute
instance-attribute
ProcessorSpecEntry
dataclass
One output control's engine-hosted processor contribution.
Attributes:
| Name | Type | Description |
|---|---|---|
spec |
ProcessorSpec
|
The serialized processor. |
Source code in steerability/algorithms/core/execution/payloads.py
522 523 524 525 526 527 528 529 530 | |
spec
instance-attribute
ScoringItem
dataclass
One prompt's unit of scoring work (teacher-forced reference tokens).
Only controls participating in scoring contribute entries, and stopping criteria are never applied (there is no loop to stop).
Attributes:
| Name | Type | Description |
|---|---|---|
prompt |
PreparedPrompt
|
The prepared prompt. |
ref_output_ids |
Tensor
|
Reference tokens to score, shape |
state_entries |
tuple[StateControlEntry, ...]
|
Enabled state controls' contributions, in controls-list order. |
output_entries |
tuple[OutputControlEntry, ...]
|
Scoring-participant output controls' contributions, in controls-list order. |
Source code in steerability/algorithms/core/execution/payloads.py
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | |
output_entries = ()
class-attribute
instance-attribute
prompt
instance-attribute
ref_output_ids
instance-attribute
state_entries = ()
class-attribute
instance-attribute
StackEntry
dataclass
One output control's live processor and criteria contribution, consumed by in-process sessions.
Attributes:
| Name | Type | Description |
|---|---|---|
logits_processors |
tuple
|
HF |
stopping_criteria |
tuple
|
HF |
Source code in steerability/algorithms/core/execution/payloads.py
494 495 496 497 498 499 500 501 502 503 504 505 | |
logits_processors = ()
class-attribute
instance-attribute
stopping_criteria = ()
class-attribute
instance-attribute
as_constraint_source(value)
Coerce a mapping with kind and value keys into a ConstraintSource.
Source code in steerability/algorithms/core/execution/payloads.py
65 66 67 68 69 70 71 72 73 | |
remap_prompt_relative_scopes(spec, anchor)
A rollout copy of spec with prompt-relative scopes rewritten to absolute positions.
Prompt-relative scope kinds are client-side sugar: the worker anchors them at the
request's own prompt length, and a driver rollout's request prompt is the accumulated
prefix rather than the user prompt. The wire form of a scope inside a driver generation is
therefore absolute: after_prompt becomes from_position at anchor (the generation's
original prompt boundary). The rewrite changes one scalar per op, so artifact ids are
untouched; the cache salt varies with the anchor, which is correct, since differently
anchored requests compute different hidden states. The last_k kind is refused: its
in-process semantics are relative to each forwarded pass, which no absolute position can
reproduce across rollouts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
InterventionSpec
|
The lowered spec. |
required |
anchor
|
int
|
The generation's original prompt length, in absolute positions. |
required |
Returns:
| Type | Description |
|---|---|
InterventionSpec
|
The rewritten spec (the same object when nothing changed), sharing |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an op carries a |
Source code in steerability/algorithms/core/execution/payloads.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | |
session_utils
Session-side helpers for steer- and generate-time model access.
session_generate and session_score run one generation or scoring call through a
SteeringSession with the model.generate calling convention, so components written against
that convention execute on any backend. ScopedSession enforces a control's declared
ModelAccess during its steer step, and SessionLM adapts a session into a model-shaped
object for helpers that expect one.
ScopedSession
A SteeringSession view scoped to one control's declared steer access.
The pipeline hands each control's steer() a scoped session over the venue session.
layout and tokenizer are always available; generate and score delegate at
ModelAccess.ROLLOUTS and above; capture delegates at ModelAccess.CAPTURE and above.
Calls below the declared rung raise, so undeclared steer-time model contact fails
immediately and attributably on every backend. The wrapper exposes no model attribute at
any rung; the live module travels only through the model= argument of steer().
Attributes:
| Name | Type | Description |
|---|---|---|
inner |
The wrapped venue session. |
Source code in steerability/algorithms/core/execution/session_utils.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
in_process
property
True when the venue session serves a live in-process model, so layout facts such
as model_fingerprint are weights-grade rather than config-grade. Venue-matched
identity checks dispatch on this.
inner = inner
instance-attribute
layout
property
Structural facts about the venue session's model.
tokenizer
property
The venue session's tokenizer, or None.
capture(prompts, layers, mode, location='layer_output')
Capture through the venue session; requires ModelAccess.CAPTURE or higher.
Source code in steerability/algorithms/core/execution/session_utils.py
170 171 172 173 174 175 176 177 178 | |
generate(items, params)
Generate through the venue session; requires ModelAccess.ROLLOUTS or higher.
Source code in steerability/algorithms/core/execution/session_utils.py
160 161 162 163 | |
score(items, params)
Score through the venue session; requires ModelAccess.ROLLOUTS or higher.
Source code in steerability/algorithms/core/execution/session_utils.py
165 166 167 168 | |
SessionLM
A model-shaped adapter whose generation executes through a SteeringSession.
Gives steer-time helpers written against the model.generate calling convention
(proposers, rollout scorers) an object with generate and device, so the helper runs on
any backend. pad_token_id keyword arguments are dropped before submission, since
sessions derive padding from their tokenizer.
Attributes:
| Name | Type | Description |
|---|---|---|
session |
The wrapped session. |
Source code in steerability/algorithms/core/execution/session_utils.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
device
property
CPU; sessions place prompt tensors themselves.
session = session
instance-attribute
generate(input_ids, attention_mask=None, **gen_kwargs)
Generate full sequences through the session (model.generate convention).
Source code in steerability/algorithms/core/execution/session_utils.py
201 202 203 204 | |
session_generate(session, input_ids, attention_mask=None, **gen_kwargs)
Run one generate call through a SteeringSession, returning full sequences.
Drop-in replacement for model.generate(input_ids=..., attention_mask=..., **gen_kwargs)
inside driver rollouts and steer-time helpers. Each row of input_ids becomes one
GenerationItem; the keyword arguments normalize through
GenerationParams.from_gen_kwargs, so live logits_processor and stopping_criteria
stacks travel in extra (consumable in process only). The returned tensor holds each
caller row followed by its continuation per candidate, right-padded to a common length
with the session tokenizer's pad token, so slicing at the input length recovers the
continuations on every backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
SteeringSession
|
The |
required |
input_ids
|
Tensor
|
Prompt token ids of shape |
required |
attention_mask
|
Tensor | None
|
Attention mask matching |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Full sequences of shape |
Source code in steerability/algorithms/core/execution/session_utils.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
session_score(session, input_ids, ref_output_ids, attention_mask=None, **forward_kwargs)
Score reference tokens through a SteeringSession, teacher-forced.
Each row of input_ids becomes one ScoringItem; a single reference row broadcasts
across the batch. Keyword arguments travel as forward keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
SteeringSession
|
The |
required |
input_ids
|
Tensor
|
Prompt token ids of shape |
required |
ref_output_ids
|
Tensor
|
Reference tokens of shape |
required |
attention_mask
|
Tensor | None
|
Attention mask matching |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Log probabilities of shape |
Source code in steerability/algorithms/core/execution/session_utils.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
spec
Frozen backend identity, expressed as BackendSpec with canonicalized options.
KNOWN_BACKEND_KINDS = ('huggingface', 'vllm', 'vllm-serve')
module-attribute
BackendSpec
dataclass
Frozen, hashable identity of one backend configuration.
The spec hash is the backend identity used for engine caching, benchmark checkpoint keys,
capability-probe caches, and artifact provenance. Options are canonicalized at construction
(nested mappings stored as sorted tuples, dtypes as strings, no live objects), so two specs
built from equal option mappings compare and hash equal regardless of key order. Equality
and hash() follow spec_hash, so value type is part of identity (an option value of
True and one of 1 yield different specs).
Construction also validates the configuration. A "vllm"/"vllm-serve" spec with the
vLLM-Hook plugin active (hook_plugin option) and speculative decoding configured
(speculative_config option, top-level or under engine_kwargs) is rejected, since
draft-model forwards are unhooked and verification passes break the worker's per-request
position accounting. A "vllm"/"vllm-serve" spec naming an encoder-decoder model is
rejected when the model config resolves locally (encoder-decoder execution is in-process
only); an unresolvable reference passes here and is re-checked at backend construction.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
Backend kind, one of |
model |
str | None
|
Model reference (hub id or local path), or None when the backend adopts an already-loaded model. |
options |
Any
|
Canonicalized option mapping, stored as sorted tuples. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If |
Source code in steerability/algorithms/core/execution/spec.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
kind
instance-attribute
model = None
class-attribute
instance-attribute
options = field(default=())
class-attribute
instance-attribute
spec_hash
property
A 16-character hex digest over (kind, model, options), consistent with __eq__
and stable across processes for plain-data options.
get_option(*path, default=None)
Read one option by key path, rebuilding plain dicts and lists on the way out.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*path
|
str
|
Nested option keys, e.g. |
()
|
default
|
Any
|
Value returned when any key along the path is absent. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The option value with mappings rebuilt as plain dicts and sequences as plain lists, |
Any
|
or |
Source code in steerability/algorithms/core/execution/spec.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
options_dict()
Return the options as a plain nested dict (empty when no options were provided).
Source code in steerability/algorithms/core/execution/spec.py
211 212 213 214 | |
canonicalize_option_value(value)
Convert one option value to a hashable canonical form.
Mappings become ("__mapping__", ((key, value), ...)) tuples ordered by key type name and
key repr, with scalar keys (str, int, bool, float) preserved as-is; sequences become
("__sequence__", (value, ...)) tuples; torch.dtype, torch.device, and pathlib.Path
values become strings (dtypes without the torch. prefix); scalars pass through. Any other
object is rendered as "<qualname>:<repr>", which keeps spec construction total but makes
the value only as stable as the object's repr; options should be plain data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The option value to canonicalize. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A hashable canonical form of |
Source code in steerability/algorithms/core/execution/spec.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
staging
Stage mechanics for the engine-backed steer phase: the stage free protocol and the steer-time capture smoke test.
The free protocol takes only a weakref.ref; a strong reference crossing the function
boundary would keep the staged model alive through gc.collect() and defeat the check.
capture_smoke_failure(session, fallback_tokenizer=None)
Issue one single-prompt capture through session; the error text on failure.
The probe token id comes from the session's tokenizer, else fallback_tokenizer.
Source code in steerability/algorithms/core/execution/staging.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
find_model_holders(referent, controls)
Controls holding referent in their instance attributes (one level) or in a bound
intervention's transform or gate attributes.
Source code in steerability/algorithms/core/execution/staging.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
verify_stage_released(ref, controls)
Verify the staged in-process model's weights are actually gone.
Runs a collection pass, clears the CUDA cache, and dereferences ref (the caller must
have dropped its own strong reference first).
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a control retained the staged model past the stage; the message names the retaining controls where identifiable. |
Source code in steerability/algorithms/core/execution/staging.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
identity
Canonical configuration identity and trial-seed derivation for configuration sweeps.
Pure functions with no I/O. Config identity is a digest over the materialized pipeline (control
classes and their full constructor parameters), stable across processes and machines for every
handled value type. The module does not import ControlSpec; spec objects are duck-typed on their
control_cls and name attributes.
logger = logging.getLogger(__name__)
module-attribute
canonical_value(obj, _path='$')
JSON-serializable canonical form of a constructor-argument value.
The form is stable across processes and machines for every handled type. Tensor identity is
content-addressed over dtype, shape, and bytes, with device and requires_grad excluded.
Mapping key order never affects the form, sequence order always does, and set element order
never does. A callable reduces to its qualified name. An unhandled object type reduces to its
type qualname (value-blind), logged at debug. NumPy scalars reduce with item(); NumPy arrays
convert through tolist() and then recurse, so the elements of object arrays follow the same
rules as list elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
The value to canonicalize. |
required |
_path
|
str
|
Internal breadcrumb naming the position of |
'$'
|
Returns:
| Type | Description |
|---|---|
Any
|
A JSON-serializable canonical representation of |
Source code in steerability/algorithms/core/identity.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
config_descriptor_from_controls(controls)
Descriptor for a fixed-control configuration, recovered from each control's args.
Construction stores the validated Args dataclass as control.args; arg-free controls
(Args = None) have no such attribute and contribute empty params. This distinguishes two
fixed pipelines that differ only in their controls' configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
controls
|
Sequence[Any]
|
Instantiated controls, in list order. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A descriptor dict with a |
Source code in steerability/algorithms/core/identity.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
config_descriptor_from_specs(specs, params)
Descriptor for a spec-defined configuration, from the resolved per-spec kwargs.
Each spec contributes one control entry keyed by its resolved name (its name, or its
control_cls.__name__), carrying the canonical form of the resolved constructor kwargs. Entry
order follows specs, so sequence order participates in identity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
specs
|
Sequence[Any]
|
The specs of one configuration, in list order; each duck-typed on |
required |
params
|
Mapping[str, Mapping[str, Any]]
|
Mapping from resolved spec name to that spec's resolved constructor kwargs. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A descriptor dict with a |
Source code in steerability/algorithms/core/identity.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
config_digest(descriptor)
A 12-hex-character sha256 of the descriptor's sorted JSON form.
A pure function of descriptor: equal descriptors always digest equal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
descriptor
|
Mapping[str, Any]
|
A JSON-serializable descriptor, e.g. from |
required |
Returns:
| Type | Description |
|---|---|
str
|
The 12-character hex digest. |
Source code in steerability/algorithms/core/identity.py
172 173 174 175 176 177 178 179 180 181 182 183 184 | |
derive_trial_seed(base_seed, config_id, trial_id)
Deterministic per-(config, trial) seed derived from a benchmark-level base seed.
A pure function of its three inputs, distinct across trial_id values and across config_id
values by construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_seed
|
int
|
The benchmark-level base seed. |
required |
config_id
|
str
|
The configuration identifier. |
required |
trial_id
|
int
|
The trial index. |
required |
Returns:
| Type | Description |
|---|---|
int
|
A 32-bit non-negative integer seed. |
Source code in steerability/algorithms/core/identity.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
qualname(obj_type)
Fully qualified name of a type, as <module>.<qualname>.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj_type
|
type
|
The type to name. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The dotted module-plus-qualname string. |
Source code in steerability/algorithms/core/identity.py
26 27 28 29 30 31 32 33 34 35 | |
output
The Output generation record, per-row finish-reason inference, and the stop-string
truncation rule shared by every backend.
FINISH_REASONS = ('stop', 'eos', 'length')
module-attribute
Output
dataclass
The result of one generation call.
Attributes:
| Name | Type | Description |
|---|---|---|
output_ids |
Tensor
|
Generated token IDs as a |
adapted_input_ids |
Tensor | None
|
The |
finish_reason |
str | None
|
The first row's finish reason, one of |
finish_reasons |
tuple[str | None, ...] | None
|
Per-row finish reasons matching |
generated_tokens |
int | None
|
The total tokens generated to produce this output, including rollouts a
decoding driver proposed and discarded, or None when the producer did not count them.
On the driver path the pipeline attaches the session wrapper's accumulated total; for a
multi-row dispatch the total is split evenly across rows (integer division, remainder
on the first row), so arm-level sums are preserved. The driverless path leaves it None,
and consumers fall back to the non-pad count of |
Source code in steerability/algorithms/core/output.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
adapted_input_ids = None
class-attribute
instance-attribute
finish_reason = None
class-attribute
instance-attribute
finish_reasons = None
class-attribute
instance-attribute
generated_tokens = None
class-attribute
instance-attribute
output_ids
instance-attribute
decode(tokenizer, skip_special_tokens=True)
Decode output_ids to text. Batch-aware.
Source code in steerability/algorithms/core/output.py
43 44 45 46 47 48 49 50 51 | |
infer_finish_reasons(new_tokens, gen_kwargs, *, eos_token_id, pad_token_id, stop_strings=(), stop_token_ids=(), tokenizer=None)
Classify a per-row finish reason from generated token IDs and the composed stop rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_tokens
|
Tensor
|
Generated token IDs as a |
required |
gen_kwargs
|
dict
|
Generation parameters; only |
required |
eos_token_id
|
int | list[int] | None
|
End-of-sequence token ID(s); an int, a list of ints, or None. Normalized to a set of IDs internally. |
required |
pad_token_id
|
int | None
|
Padding token ID used to right-pad short rows, or None. |
required |
stop_strings
|
Sequence[str]
|
Stop strings composed for this generation; requires |
()
|
stop_token_ids
|
Sequence[int]
|
Extra stop token ids composed for this generation. |
()
|
tokenizer
|
PreTrainedTokenizerBase | None
|
Tokenizer used to decode continuations for the stop-string test, or None. |
None
|
Returns:
| Type | Description |
|---|---|
list[str | None]
|
One reason per row, in order, classified with the precedence stop, then eos, then |
list[str | None]
|
length, then None. For row |
list[str | None]
|
recover the true continuation length
|
Stop rules the classifier was not given, such as caller-supplied custom stopping criteria, still classify as None.
Source code in steerability/algorithms/core/output.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
truncate_at_stop_strings(text, stop_strings)
Truncate text at the earliest occurrence of any stop string.
This is the one client-side truncation rule applied to decoded continuation text on every backend. Token ids are never modified; only the decoded text is cut, at the start of the earliest match.
With reasoning models the earliest-match rule interacts with thinking segments: a stop string
that also occurs inside the reasoning (e.g. "Answer:") cuts the text mid-thinking, so the
thinking segment is left unclosed and a later split reports an empty answer. Choose stop strings
that cannot appear before the closing think tag, or omit them when generating with thinking on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Decoded continuation text. |
required |
stop_strings
|
Sequence[str]
|
Stop strings; empty leaves |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
str
|
no stop string occurs. |
Source code in steerability/algorithms/core/output.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
scoring
The per-row scorer protocol consumed by steering controls.
SampleScorer
Bases: Protocol
Score one response against its row; higher is better.
The row is a mapping carrying "input" (the query text), "reference" when the dataset has
one, and any other dataset columns. Controls that optimize or rerank against a per-row score
(prompt optimizers, sequence rerankers) accept any callable with this shape.
Source code in steerability/algorithms/core/scoring.py
5 6 7 8 9 10 11 12 13 14 | |
specs
Specification utilities for steering controls.
Provides:
ControlSpec: a description of a steering control plus a hyperparameter search space.
Space = Mapping[str, Sequence[Any]] | Sequence[Mapping[str, Any]] | Callable[[dict], Iterable[Mapping[str, Any]]]
module-attribute
ControlSpec
dataclass
Specification for a parameterized steering control.
A ControlSpec describes a control class plus a search space over its constructor arguments. The sweep layer
(core/sweeps.py, and SteeringEval above it) uses it to instantiate control instances for different
hyperparameter settings.
Attributes:
| Name | Type | Description |
|---|---|---|
control_cls |
type
|
The steering control class to instantiate. |
params |
Mapping[str, Any]
|
Fixed constructor arguments for the control. |
vars |
Space | None
|
Optional search space over additional constructor arguments. May be:
|
name |
str | None
|
Optional short name for this spec; defaults to |
search_strategy |
Literal['grid', 'random']
|
Strategy for traversing |
num_samples |
int | None
|
Number of points to sample when |
seed |
int | None
|
Optional random seed used when |
Source code in steerability/algorithms/core/specs.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
control_cls
instance-attribute
name = None
class-attribute
instance-attribute
num_samples = None
class-attribute
instance-attribute
params = field(default_factory=dict)
class-attribute
instance-attribute
search_strategy = 'grid'
class-attribute
instance-attribute
seed = None
class-attribute
instance-attribute
vars = None
class-attribute
instance-attribute
iter_points(context)
Iterate over local search points for this spec.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
dict
|
Context dictionary; passed through to functional |
required |
Yields:
| Type | Description |
|---|---|
Iterable[dict[str, Any]]
|
Parameter dictionaries (possibly empty) that will be merged into |
Iterable[dict[str, Any]]
|
control instance. |
Source code in steerability/algorithms/core/specs.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
resolve_params(chosen, context)
Compute the full kwargs for this control at a given search point.
Source code in steerability/algorithms/core/specs.py
128 129 130 131 132 133 134 135 136 137 138 139 140 | |
steering_pipeline
Core steering pipeline for composing and applying multiple LLM control methods.
logger = logging.getLogger(__name__)
module-attribute
SteeringPipeline
dataclass
Main steering pipeline for applying various control methods to Hugging Face causal language models.
Enables application of structural, state, input, and output controls in a coordinated manner. Controls are applied in a fixed bottom-up order during steering, then used together during generation.
Workflow:
- Instantiate with a base model checkpoint and/or control objects.
- Call
steer()once to apply all controls in order (structural, input, state, output). - Use
generate()for inference with steering applied, accepting str, list[str], chat, or tensor input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name_or_path
|
str or Path
|
HuggingFace model hub name or local directory,
loaded during |
None
|
controls
|
Sequence[StructuralControl | StateControl | InputControl | OutputControl]
|
Controls for the steering pipeline. Every category accepts any number of controls,
applied in list order. The output category additionally accepts at most one enabled
|
()
|
tokenizer_name_or_path
|
str
|
Tokenizer location. Defaults to |
None
|
device_map
|
str or dict[str, int]
|
Device map (passed to
|
'auto'
|
device
|
(device, str)
|
Device (passed to model's |
None
|
hf_model_kwargs
|
dict
|
Extra keyword arguments passed to
|
dict()
|
trust_remote_code
|
bool
|
Trust remote code when loading the tokenizer. Defaults to
|
False
|
lazy_init
|
bool
|
Deprecated and inert: construction never loads the model;
acquisition happens in |
False
|
backend
|
BackendSpec | str
|
The pipeline's backend. Defaults to the
in-process Hugging Face backend described by this pipeline's own construction
arguments. A |
None
|
fit
|
str
|
Fit venue policy. |
'auto'
|
model
|
PreTrainedModel
|
Preloaded model to steer, reused as-is by |
None
|
tokenizer
|
PreTrainedTokenizerBase
|
Preloaded tokenizer, normalized with
|
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ValueError
|
If more than one enabled |
Note:
- Every category accepts multiple controls, applied in list order. An omitted category is an empty list; an omitted output category uses the pipeline's default decoding driver.
- Controls with a
tokenizerattribute will have it auto-injected if not already set - Construction is cheap: on the Hugging Face backend
modelis None untilsteer()unless a preloadedmodel=was passed. - On engine backends,
modelis non-None only while the staged in-process model exists during the steer phase; the stage is freed before the engine boots.
For the state category, list order in controls defines the composition surface. List order sets
steer() order, hook registration order, and execution order for hooks on the same module. PyTorch
forward hooks chain, so a later hook receives the previous hook's returned output and pre-hooks chain
likewise on inputs. Combinations that do not commute, such as ablate after add versus add after
ablate, therefore produce order-sensitive results. A gated or condition-scoring control placed after
another observes activations already edited at earlier layers by upstream list entries.
For the input category, adaptation runs in two phases. On chat input, every control's
adapt_messages runs in list order over the message batch (each non-None return feeds the next
control); the result is templated and tokenized once, then every control whose adapt_messages
returned None runs its token-level adapt in list order over the token stream. On text/tensor
input there is no message phase; every control's adapt runs in list order. List order is
authoritative within each phase, but the message phase structurally precedes the token phase:
with [TokenOnlyControl, MessageLevelControl] on chat input, the message-level control's effect
lands first even though it is listed second (tokens do not exist before templating). Place
semantic rewriters (e.g. PRewrite, CPO, GEPA) before surface formatting (e.g. FewShot),
since a rewriter trained on bare instructions degrades on exemplar-prepended input.
For the structural category, steer() threads the model through the controls in list order:
each control receives the previous control's returned model (and the possibly mutated tokenizer).
Nothing implicit happens between stages (no adapter merging, no embedding-resize reconciliation);
stage compatibility is the caller's responsibility.
Source code in steerability/algorithms/core/steering_pipeline.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 | |
backend = None
class-attribute
instance-attribute
controls = ()
class-attribute
instance-attribute
device = None
class-attribute
instance-attribute
device_map = 'auto'
class-attribute
instance-attribute
fit = 'auto'
class-attribute
instance-attribute
hf_model_kwargs = field(default_factory=dict)
class-attribute
instance-attribute
input_controls = field(init=False)
class-attribute
instance-attribute
lazy_init = False
class-attribute
instance-attribute
model = field(default=None, repr=False)
class-attribute
instance-attribute
model_name_or_path = None
class-attribute
instance-attribute
output_controls = field(init=False)
class-attribute
instance-attribute
state_controls = field(init=False)
class-attribute
instance-attribute
structural_controls = field(init=False)
class-attribute
instance-attribute
supports_batching
property
Return True if all enabled controls in this pipeline are batch-safe.
The default decoding driver is batch-safe, so an empty output_controls list is vacuously
true and does not constrain batching.
tokenizer = field(default=None, repr=False)
class-attribute
instance-attribute
tokenizer_name_or_path = None
class-attribute
instance-attribute
trust_remote_code = False
class-attribute
instance-attribute
check(backend=None)
Evaluate every enabled control's backend requirements and compute the steer plan.
Runs automatically at steer() (which raises on generate-phase failures) and is
callable standalone against any backend. Disabled controls, including the pipeline's
default identity controls, never gate a backend and do not appear in the report. The
returned report's plan states, per enabled control and per fit artifact, where the
steer phase will run each step; the plan is a pure function of the declarations and
the spec, so the same configuration always yields the same verdicts and plan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
BackendSpec | str | None
|
Backend to evaluate against. Defaults to the pipeline's |
None
|
Returns:
| Type | Description |
|---|---|
SupportReport
|
The |
SupportReport
|
(control, phase) pair. |
Source code in steerability/algorithms/core/steering_pipeline.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
compute_logprobs(input_ids, attention_mask=None, ref_output_ids=None, runtime_kwargs=None, **forward_kwargs)
Compute per-token log-probabilities of ref_output_ids with structural, input, state, and output steering controls applied.
Step-level output controls' logits processors are part of the steered next-token distribution, so they are
applied here position-by-position (teacher-forced), for every enabled output control whose
include_in_scoring is True. The exclusive mechanism has no scoring analogue: decoding drivers are not
invoked and stopping criteria are not applied. A control opts out of scoring by setting
include_in_scoring=False (e.g. processors too expensive to evaluate per reference position).
Uses teacher forcing to compute log P(ref_t | steered_input, ref_1, ..., ref_{t-1}) for each token in the reference sequence.
Decoder-only scoring executes through the inference backend's session as ScoringItems.
When all pipeline controls support batching, the items share one set of control entries
and score in a single pass (inputs are left-padded internally for correct positional
alignment); otherwise each item is prepared and scored sequentially. Encoder-decoder
models score in process against the live model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
list[int] | LongTensor
|
Input token IDs as list or tensor [seq_len] or [batch, seq_len] |
required |
attention_mask
|
Tensor | None
|
Optional attention mask matching input_ids shape |
None
|
ref_output_ids
|
list[int] | LongTensor
|
Reference tokens to score [ref_len] or [batch, ref_len] |
None
|
runtime_kwargs
|
dict | None
|
Per-call parameters for controls (e.g., {"substrings": [...]}) |
None
|
**forward_kwargs
|
Any
|
Additional arguments passed to model forward pass |
{}
|
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Log probabilities of shape [batch, ref_len] for decoder-only models, or [batch, ref_len - 1] for encoder-decoder models (excludes first decoder token) |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If steer() has not been called |
ValueError
|
If ref_output_ids is None |
UnsupportedPipelineError
|
If an enabled control is score-unsupported on the configured inference backend. |
Source code in steerability/algorithms/core/steering_pipeline.py
1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 | |
generate(inputs=None, attention_mask=None, runtime_kwargs=None, return_output=False, *, text=None, messages=None, input_ids=None, **gen_kwargs)
generate(inputs: str, attention_mask: None = ..., runtime_kwargs: dict | None = ..., return_output: Literal[False] = ..., **gen_kwargs: Any) -> str
generate(inputs: list[str], attention_mask: None = ..., runtime_kwargs: dict | None = ..., return_output: Literal[False] = ..., **gen_kwargs: Any) -> list[str]
generate(*, text: str, runtime_kwargs: dict | None = ..., return_output: Literal[False] = ..., **gen_kwargs: Any) -> str
generate(*, text: Sequence[str], runtime_kwargs: dict | None = ..., return_output: Literal[False] = ..., **gen_kwargs: Any) -> list[str]
generate(*, messages: Sequence[Mapping], runtime_kwargs: dict | None = ..., return_output: Literal[False] = ..., **gen_kwargs: Any) -> str
generate(*, messages: Sequence[Sequence[Mapping]], runtime_kwargs: dict | None = ..., return_output: Literal[False] = ..., **gen_kwargs: Any) -> list[str]
generate(*, input_ids: torch.Tensor | list[int] | list[list[int]], attention_mask: torch.Tensor | None = ..., runtime_kwargs: dict | None = ..., return_output: Literal[False] = ..., **gen_kwargs: Any) -> torch.Tensor
generate(inputs: Any = ..., attention_mask: torch.Tensor | None = ..., runtime_kwargs: dict | None = ..., *, text: Any = ..., messages: Any = ..., input_ids: Any = ..., return_output: Literal[True], **gen_kwargs: Any) -> Output | list[Output]
generate(inputs: str | list[str] | None = ..., attention_mask: None = ..., runtime_kwargs: dict | None = ..., return_output: bool = ..., *, text: str | Sequence[str] | None = ..., messages: Sequence[Mapping] | Sequence[Sequence[Mapping]] | None = ..., **gen_kwargs: Any) -> str | list[str] | Output | list[Output]
generate(*, input_ids: torch.Tensor | list[int] | list[list[int]], attention_mask: torch.Tensor | None = ..., runtime_kwargs: dict | None = ..., return_output: bool = ..., **gen_kwargs: Any) -> torch.Tensor | Output | list[Output]
Generate with steering across text, chat, and token prompts.
The prompt source is declared by keyword, with exactly one source per call:
| Source | Tokenization | Default return type |
|---|---|---|
text= (str) |
plain text | str |
text= (Sequence[str]) |
batched plain text | list[str] |
messages= (one conversation) |
apply_chat_template |
str |
messages= (batch of conversations) |
batched apply_chat_template |
list[str] |
input_ids= (1-D tokens) |
already tokenized; passed through | torch.Tensor |
input_ids= (2-D tokens) |
already tokenized; passed through | torch.Tensor |
Positional str/list[str] is accepted as a convenience for text prompts and behaves like
text=; any other positional shape raises TypeError. With return_output=True, the return
is always Output (single) or list[Output] (batched) regardless of source. The per-source
methods generate_text, generate_messages, and generate_tokens expose the same behavior
with source-specific signatures and document each source's rules.
The decoded text returns carry exactly one candidate per prompt. Requesting multiple
candidates (num_return_sequences or n greater than 1) with text= or messages=
raises ValueError unless return_output=True, where Output.output_ids holds one row
per candidate and Output.finish_reasons one reason per candidate. The token return
(input_ids=) carries candidates in its shape, [batch * n, gen_len] with each prompt's
candidates contiguous, matching model.generate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
str | list[str] | None
|
Positional convenience for text prompts ( |
None
|
attention_mask
|
Tensor | None
|
Attention mask, valid only with |
None
|
runtime_kwargs
|
dict | None
|
Per-generation parameters for controls (e.g., |
None
|
return_output
|
bool
|
If True, return one or more |
False
|
text
|
str | Sequence[str] | None
|
Text prompt as a |
None
|
messages
|
Sequence[Mapping] | Sequence[Sequence[Mapping]] | None
|
Chat prompt as one conversation (a sequence of mappings) or a batch (a sequence of sequences of mappings). |
None
|
input_ids
|
Tensor | list[int] | list[list[int]] | None
|
Token prompt as a 1-D/2-D integer tensor, |
None
|
**gen_kwargs
|
Any
|
Generation parameters in
|
{}
|
Returns:
| Type | Description |
|---|---|
str | list[str] | Tensor | Output | list[Output]
|
See dispatch table above. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
TypeError
|
If no prompt source or more than one is provided, if a source fails
validation, if |
ValueError
|
If a token tensor is not 1-D/2-D, nested token lists are ragged, a text/
chat sequence is empty, |
Source code in steerability/algorithms/core/steering_pipeline.py
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 | |
generate_messages(messages, *, chat_template_kwargs=None, runtime_kwargs=None, return_output=False, return_full_sequence=False, **gen_kwargs)
generate_messages(messages: Sequence[Mapping], *, chat_template_kwargs: Mapping | None = ..., runtime_kwargs: dict | None = ..., return_output: Literal[False] = ..., return_full_sequence: bool = ..., **gen_kwargs: Any) -> str
generate_messages(messages: Sequence[Sequence[Mapping]], *, chat_template_kwargs: Mapping | None = ..., runtime_kwargs: dict | None = ..., return_output: Literal[False] = ..., return_full_sequence: bool = ..., **gen_kwargs: Any) -> list[str]
generate_messages(messages: Sequence[Mapping] | Sequence[Sequence[Mapping]], *, chat_template_kwargs: Mapping | None = ..., runtime_kwargs: dict | None = ..., return_output: Literal[True], return_full_sequence: bool = ..., **gen_kwargs: Any) -> Output | list[Output]
generate_messages(messages: Sequence[Mapping] | Sequence[Sequence[Mapping]], *, chat_template_kwargs: Mapping | None = ..., runtime_kwargs: dict | None = ..., return_output: bool = ..., return_full_sequence: bool = ..., **gen_kwargs: Any) -> str | list[str] | Output | list[Output]
Generate from chat prompts through the tokenizer's chat template.
One conversation (a sequence of mappings) returns str; a batch (a sequence of
sequences of mappings) returns list[str] (Output or list[Output] with
return_output=True). Every input control's adapt_messages runs before templating;
controls whose adapt_messages returns None run their token-level adapt after
tokenization, so each control applies exactly once per call. The decoded return
carries exactly one candidate per prompt; num_return_sequences/n greater than 1
raises ValueError unless return_output=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
Sequence[Mapping] | Sequence[Sequence[Mapping]]
|
One conversation or a batch of conversations. |
required |
chat_template_kwargs
|
Mapping | None
|
Extra keyword arguments forwarded to |
None
|
runtime_kwargs
|
dict | None
|
Per-generation parameters for controls. |
None
|
return_output
|
bool
|
If True, return |
False
|
return_full_sequence
|
bool
|
If True, include the prompt in the returned token IDs. Returned ids exclude the prompt by default; do not slice the result by prompt length. |
False
|
**gen_kwargs
|
Any
|
Generation parameters, as for |
{}
|
Returns:
| Type | Description |
|---|---|
str | list[str] | Output | list[Output]
|
|
Source code in steerability/algorithms/core/steering_pipeline.py
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 | |
generate_text(text, *, runtime_kwargs=None, return_output=False, return_full_sequence=False, **gen_kwargs)
generate_text(text: str, *, runtime_kwargs: dict | None = ..., return_output: Literal[False] = ..., return_full_sequence: bool = ..., **gen_kwargs: Any) -> str
generate_text(text: Sequence[str], *, runtime_kwargs: dict | None = ..., return_output: Literal[False] = ..., return_full_sequence: bool = ..., **gen_kwargs: Any) -> list[str]
generate_text(text: str | Sequence[str], *, runtime_kwargs: dict | None = ..., return_output: Literal[True], return_full_sequence: bool = ..., **gen_kwargs: Any) -> Output | list[Output]
generate_text(text: str | Sequence[str], *, runtime_kwargs: dict | None = ..., return_output: bool = ..., return_full_sequence: bool = ..., **gen_kwargs: Any) -> str | list[str] | Output | list[Output]
Generate from plain-text prompts.
A str returns str; a sequence of str returns list[str] (Output or
list[Output] with return_output=True). Input controls apply at token level only;
adapt_messages does not fire on text input. The decoded return carries exactly one
candidate per prompt; num_return_sequences/n greater than 1 raises ValueError
unless return_output=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | Sequence[str]
|
Text prompt as a |
required |
runtime_kwargs
|
dict | None
|
Per-generation parameters for controls. |
None
|
return_output
|
bool
|
If True, return |
False
|
return_full_sequence
|
bool
|
If True, include the prompt in the returned token IDs. Returned ids exclude the prompt by default; do not slice the result by prompt length. |
False
|
**gen_kwargs
|
Any
|
Generation parameters, as for |
{}
|
Returns:
| Type | Description |
|---|---|
str | list[str] | Output | list[Output]
|
|
Source code in steerability/algorithms/core/steering_pipeline.py
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 | |
generate_tokens(input_ids, attention_mask=None, *, runtime_kwargs=None, return_output=False, return_full_sequence=False, **gen_kwargs)
generate_tokens(input_ids: torch.Tensor | list[int] | list[list[int]], attention_mask: torch.Tensor | None = ..., *, runtime_kwargs: dict | None = ..., return_output: Literal[False] = ..., return_full_sequence: bool = ..., **gen_kwargs: Any) -> torch.Tensor
generate_tokens(input_ids: torch.Tensor | list[int] | list[list[int]], attention_mask: torch.Tensor | None = ..., *, runtime_kwargs: dict | None = ..., return_output: Literal[True], return_full_sequence: bool = ..., **gen_kwargs: Any) -> Output | list[Output]
generate_tokens(input_ids: torch.Tensor | list[int] | list[list[int]], attention_mask: torch.Tensor | None = ..., *, runtime_kwargs: dict | None = ..., return_output: bool = ..., return_full_sequence: bool = ..., **gen_kwargs: Any) -> torch.Tensor | Output | list[Output]
Generate from already-tokenized prompts.
Returns a torch.Tensor of continuation ids (Output or list[Output] with
return_output=True). Input controls apply at token level only; adapt_messages
does not fire on token input. With num_return_sequences/n greater than 1 the
returned tensor is [batch * n, gen_len] with each prompt's candidates contiguous,
matching model.generate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Tensor | list[int] | list[list[int]]
|
Token prompt as a 1-D/2-D integer tensor, |
required |
attention_mask
|
Tensor | None
|
Attention mask matching |
None
|
runtime_kwargs
|
dict | None
|
Per-generation parameters for controls. |
None
|
return_output
|
bool
|
If True, return |
False
|
return_full_sequence
|
bool
|
If True, include the prompt in the returned token IDs. Returned ids exclude the prompt by default; do not slice the result by prompt length. |
False
|
**gen_kwargs
|
Any
|
Generation parameters, as for |
{}
|
Returns:
| Type | Description |
|---|---|
Tensor | Output | list[Output]
|
|
Source code in steerability/algorithms/core/steering_pipeline.py
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 | |
release_backends()
Release every backend this pipeline constructed and empty the cache.
Subsequent operations construct fresh backends against the same specs. Lowered intervention entries and staged artifacts persist, so a released pipeline remains usable at the cost of re-booting engines on next use. Release is idempotent. Engine-owning backends shut down deterministically.
Source code in steerability/algorithms/core/steering_pipeline.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
steer(**steer_kwargs)
Apply all steering controls per the steer plan.
Executes each control's steer() method in a fixed bottom-up order: structural -> input -> state -> output, and in list order within each category. If any control's steer() method returns a PreTrainedModel instance, it replaces the current model for subsequent controls, so structural controls thread the model through in list order.
Before any control runs, check() evaluates the configured backend and raises on any
generate-phase failure. Each control's steer() receives session=, a session scoped
to its declared steer_access(), unless the caller supplied its own session keyword,
and receives the live model only at ModelAccess.MODULE. On the Hugging Face backend
every step runs against the live model in one phase. On engine backends the plan's
stage-venued steps run first on a temporary in-process model that is freed before the
engine boots (exported artifacts are the handoff), then the session-venued steps run
through the engine session. The only channel between one control's steer and another's
is the pipeline model, and every control that can touch it runs in the stage phase, so
per-phase global order preserves the composition semantics of the single-phase order.
A failed steer releases any backends it constructed before re-raising, so it does not leave an engine behind and a retried steer re-boots. A repeated call on an already-steered pipeline is a no-op.
Warns:
| Type | Description |
|---|---|
UserWarning
|
If two or more enabled controls declare the same |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no model is available after steering, or the staged in-process model was retained past the steer stage. |
ValueError
|
If an enabled control's |
UnsupportedPipelineError
|
If any enabled control is unsupported at the generate phase on the configured backend. |
ModuleNotFoundError
|
If a configured backend kind requires an optional dependency
that is not installed (e.g. the |
Source code in steerability/algorithms/core/steering_pipeline.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 | |
to_spipe(*, freeze=None, model_ref=None)
Serialize this pipeline as an SPipe.
A steered pipeline freezes by default: each enabled control's steer-time products are
exported into a content-addressed artifact store and its resolved constructor form is
recorded alongside the recipe, so the loaded pipeline steers cheaply and model-free.
An unsteered pipeline yields a recipe-only spipe; freeze=False forces recipe-only
from a steered pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freeze
|
bool | None
|
Freeze the resolution. Defaults to the pipeline's steered state. |
None
|
model_ref
|
str | None
|
Explicit model reference recorded in the spipe, overriding
|
None
|
Returns:
| Type | Description |
|---|---|
SPipe
|
The built |
Raises:
| Type | Description |
|---|---|
SpipeSaveError
|
If no model reference is resolvable, a control is unregistered or cannot serialize, or a control cannot freeze. |
Source code in steerability/algorithms/core/steering_pipeline.py
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |
sweeps
Configuration sweeps over one base model: expansion, pre-flight support checks, and pipeline lifecycle.
One configuration is one concrete list of control instances. expand_configurations enumerates the
configurations of a pipelines mapping (fixed controls, ControlSpec sweeps, and the empty baseline)
as ConfigPoints carrying canonical identity; preflight evaluates backend support per point before
any model or engine work; PipelineFactory builds, steers, and releases one pipeline per point with a
shared preloaded base model on the Hugging Face backend and a fingerprint tripwire over it.
logger = logging.getLogger(__name__)
module-attribute
ConfigPoint
dataclass
One concrete configuration of one named pipeline.
Attributes:
| Name | Type | Description |
|---|---|---|
pipeline_name |
str
|
Name of the pipeline the point belongs to. |
config_id |
str
|
Canonical configuration identifier; |
descriptor |
Mapping[str, Any]
|
JSON-serializable canonical descriptor of the configuration (control classes and their full constructor parameters). |
specs |
tuple | None
|
The |
params |
Mapping[str, Mapping[str, Any]] | None
|
Mapping from resolved spec name to that spec's resolved constructor kwargs, else None for fixed and baseline pipelines. |
controls_factory |
Callable[[], list]
|
Zero-argument callable building the configuration's control instances. Fixed pipelines return the user-supplied instances on every call; spec pipelines instantiate fresh controls per call, so pre-flight instances are discarded and execution re-instantiates. |
Source code in steerability/algorithms/core/sweeps.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
config_id
instance-attribute
controls_factory
instance-attribute
descriptor
instance-attribute
params
instance-attribute
pipeline_name
instance-attribute
specs
instance-attribute
PipelineFactory
Build, steer, and release one SteeringPipeline per configuration against one base model.
On the Hugging Face backend, configurations without an enabled structural control share one
preloaded base model and tokenizer, loaded lazily on first use. Configurations with an enabled
structural control, and every configuration on an engine backend, construct from
base_model_name_or_path with the placement knobs; before such a configuration the factory
drops any resident shared base, so one full model is resident at a time, and the next
shared-base configuration reloads it.
The shared base is expected not to be mutated by a non-structural configuration. After each shared-base configuration a fingerprint tripwire checks the shared model for change and, on detecting one, warns naming the configuration's controls and drops the shared model so the next configuration reloads a clean base. The fingerprint samples a bounded subset of parameters, so the tripwire makes the no-mutation invariant observable rather than proven.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_model_name_or_path
|
str | Path
|
Hugging Face model ID or local path of the base model. |
required |
backend
|
BackendSpec | str | None
|
Backend forwarded to each pipeline (a |
None
|
fit
|
Literal['auto', 'in_process']
|
Fit venue policy forwarded to each pipeline. |
'auto'
|
hf_model_kwargs
|
dict | None
|
Extra kwargs forwarded to |
None
|
device_map
|
str | dict | None
|
Device placement strategy for in-process loads. |
'auto'
|
trust_remote_code
|
bool
|
Trust remote code when loading tokenizers; forwarded to each pipeline. |
False
|
Source code in steerability/algorithms/core/sweeps.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
backend = backend
instance-attribute
backend_kind
property
The configured backend kind ("huggingface", "vllm", or "vllm-serve").
base_model_name_or_path = base_model_name_or_path
instance-attribute
device_map = device_map
instance-attribute
fit = fit
instance-attribute
hf_model_kwargs = hf_model_kwargs or {}
instance-attribute
shared_base_fingerprint
property
Fingerprint of the resident shared base model, or None when none is resident.
trust_remote_code = trust_remote_code
instance-attribute
release()
Drop the shared base model; the factory remains usable and reloads it on next use.
Source code in steerability/algorithms/core/sweeps.py
390 391 392 | |
steered(controls)
Build and steer a pipeline for one configuration, releasing it on exit.
Everything the caller does inside the with block runs inside the protected region: on
exit (including on error) every control's cleanup() runs best effort, the pipeline's
backends are released, the shared-base fingerprint tripwire runs for shared-base
configurations, and memory is reclaimed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
controls
|
Sequence
|
Instantiated controls for this configuration (empty for the baseline). |
required |
Yields:
| Type | Description |
|---|---|
SteeringPipeline
|
The steered |
Source code in steerability/algorithms/core/sweeps.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
expand_configurations(pipelines, *, base_model_name_or_path)
Enumerate the concrete configurations of a pipelines mapping, in execution order.
Each pipeline value is an empty sequence (the unsteered baseline), a list of instantiated
controls (one fixed configuration), or a list of ControlSpecs (one configuration per point
of the cartesian product of the specs' search spaces). Spec search spaces receive a context
dict with "pipeline_name", "base_model_name_or_path", and, at resolution time,
"combo_id".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pipelines
|
Mapping[str, Sequence]
|
Mapping from pipeline name to |
required |
base_model_name_or_path
|
str | Path
|
The base model reference, forwarded into spec contexts. |
required |
Yields:
| Type | Description |
|---|---|
ConfigPoint
|
One |
Raises:
| Type | Description |
|---|---|
TypeError
|
If a pipeline mixes |
ValueError
|
If two |
Source code in steerability/algorithms/core/sweeps.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
preflight(points, *, base_model_name_or_path, backend, fit)
Evaluate backend support for every point before any model or engine work.
Constructs one probe SteeringPipeline per point (construction performs no I/O), evaluates
check(), and discards the probe. The empty baseline is trivially supported and produces no
probe. Callers choose whether to raise on failures or skip the failing points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
Iterable[ConfigPoint]
|
The configuration points to check. |
required |
base_model_name_or_path
|
str | Path
|
The base model reference for the probe pipelines. |
required |
backend
|
BackendSpec | str | None
|
Backend forwarded to the probe pipelines. |
required |
fit
|
Literal['auto', 'in_process']
|
Fit venue policy forwarded to the probe pipelines. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
One message per unsupported (point, control, phase), each naming the pipeline and its |
list[str]
|
|
Raises:
| Type | Description |
|---|---|
ModuleNotFoundError
|
If a configured backend kind requires an optional dependency that is not installed. |
Source code in steerability/algorithms/core/sweeps.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
utils
Utilities supporting the core steering pipeline.
assembly
Per-call payload assembly for SteeringPipeline.
Builds the entry payloads a session executes: state-control entries (per-generation hooks in process, lowered intervention specs on spec-consuming backends), output-control entries (processor and criteria stacks, lowered generation parameters, declarative constraints, engine-hosted processor specs), and the scoring-time processor application. Functions receive the pipeline's control lists and per-call tensors explicitly and hold no pipeline state.
logger = logging.getLogger(__name__)
module-attribute
apply_scoring_processors(output_controls, logits, steered_input_ids, ref_output_ids, runtime_kwargs, attention_mask, is_encoder_decoder, **forward_kwargs)
Apply scoring-time logits processors position-by-position (teacher forcing).
Processors receive the same (prefix_ids, scores) view as during generation. For causal
models the prefix is input ++ ref[:t] when scoring ref[t]; for encoder-decoder models
the prefix is the decoder ids ref[:t+1] when scoring ref[t+1] (matching the existing
target alignment in both paths).
Source code in steerability/algorithms/core/utils/assembly.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
collect_output_entries(output_controls, input_ids, runtime_kwargs, *, attention_mask=None, for_scoring=False, skip_ids=frozenset(), **gen_kwargs)
One StackEntry per contributing output control, in controls-list order.
With for_scoring=True, only include_in_scoring controls contribute processors and
criteria are skipped (there is no loop to stop). Controls whose id() is in skip_ids
(lowered to generation parameters for this call) contribute nothing. Controls
contributing neither processors nor criteria yield no entry.
Source code in steerability/algorithms/core/utils/assembly.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |
collect_state_entries(state_controls, input_ids, runtime_kwargs, *, attention_mask=None, hooks_in_process, lowered_state, backend=None, intervention_kinds=None, model=None, **gen_kwargs)
Collect every enabled state control's entries for the current logical generation.
With hooks_in_process True, hooks are per-generation artifacts built here: they close
over the prompt anchor, sized gate state, and a fresh position clock, and travel only as
HookEntry contributions (the session that executes forwards owns registration).
Otherwise entries come from the steer-time lowering cache, filled lazily for a control
enabled after steer().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_controls
|
Sequence[StateControl]
|
The pipeline's state controls, in list order. |
required |
input_ids
|
Tensor
|
Input token IDs after input control transformation |
required |
runtime_kwargs
|
dict | None
|
Per-call parameters for state controls |
required |
attention_mask
|
Tensor | None
|
The prompt attention mask matching |
None
|
hooks_in_process
|
bool
|
Whether the backend executes in-process torch hooks. |
required |
lowered_state
|
dict[int, InterventionEntry]
|
Steer-time lowering cache keyed by |
required |
backend
|
'Backend | None'
|
Inference backend consulted on a lazy fill. |
None
|
intervention_kinds
|
'InterventionKinds | None'
|
Advertised kinds verified on a lazy fill. |
None
|
model
|
'PreTrainedModel | None'
|
Live model forwarded to hook construction. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[StateControlEntry, ...]
|
One entry per enabled state control, in controls-list order. |
Source code in steerability/algorithms/core/utils/assembly.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
compose_stacks(output_controls, input_ids, runtime_kwargs, attention_mask, gen_kwargs, *, skip_ids=frozenset())
Compose the controls' processors and criteria, then append caller extras popped from
gen_kwargs (mutates gen_kwargs).
Caller-supplied logits_processor / stopping_criteria entries append after the
pipeline's own processors and criteria (per-call extras apply on top of the pipeline's
standing configuration) and the keys are removed from gen_kwargs, so exactly one
authoritative stack of each kind exists, travelling as an explicit parameter. gen_kwargs
reaching the driver never contains processor or criteria objects, so drivers that copy or
serialize their kwargs are safe by construction, and a driver that ignores the stacks
visibly ignores named parameters.
Source code in steerability/algorithms/core/utils/assembly.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
constraint_contributions(output_controls, runtime_kwargs)
Declarative constraint sources from enabled output controls, keyed by id().
A control that returns a source from export_constraint is lowered for that call on
backends hosting structured outputs natively: the source renders onto the engine's
request parameters and the control's live processor is not collected.
Source code in steerability/algorithms/core/utils/assembly.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
lower_state_controls(state_controls, backend, capabilities)
Lower every enabled state control's interventions for a spec-consuming backend and
stage their artifacts, returning the entries keyed by id(control).
Runs at the end of steer() when the backend executes interventions as
specs rather than in-process hooks. Specs are per-steer artifacts: the worker anchors
positions per request server-side and the spec is prompt-independent by construction,
so one lowering serves every subsequent generation. Each spec is verified against the
backend's negotiated kinds (the intersection of the static tables and discovery), and
a control's steering-artifact provenance is cross-checked against the served model's
when the backend carries a discovery payload. Returns an empty mapping when the backend
executes hooks in process, hosts no intervention specs, or no control is enabled.
Raises:
| Type | Description |
|---|---|
UnsupportedOperationError
|
If an enabled control's configuration has no wire form (the failure names the control, the intervention, and the reason), or its spec requires a kind the backend does not advertise. |
Source code in steerability/algorithms/core/utils/assembly.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
lowered_contributions(output_controls, runtime_kwargs)
Sampling-expressible contributions from enabled output controls, keyed by id().
A control that returns a mapping from export_generation_params is lowered for this
call: its contribution merges into the call's GenerationParams and its live processor
and criteria hooks are not collected.
Source code in steerability/algorithms/core/utils/assembly.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
per_item_state_entries(state_controls, input_ids, attention_mask, runtime_kwargs, *, model=None, **gen_kwargs)
Per-row state entries computed by per-call control clones.
Distinct per-item derived seeds force the in-process session onto its serial path, where each row runs its own forward. Hooks computed once on the batch hold batch-sized position and gate state, so each row instead gets hooks computed by a fresh clone on that row's prompt tensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_controls
|
Sequence[StateControl]
|
The pipeline's state controls, in list order. |
required |
input_ids
|
Tensor
|
Adapted prompt ids of shape |
required |
attention_mask
|
Tensor
|
Attention mask matching |
required |
runtime_kwargs
|
dict | None
|
Per-call parameters for state controls. |
required |
model
|
'PreTrainedModel | None'
|
Live model forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple[HookEntry, ...]]
|
One tuple of |
Source code in steerability/algorithms/core/utils/assembly.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
processor_spec_contributions(output_controls, runtime_kwargs, capabilities)
Engine-hosted processor contributions from enabled output controls, keyed by id().
A control that returns a ProcessorSpec from export_processor_spec whose kind the
backend serves is lowered for that call: the spec travels as a ProcessorSpecEntry
and the control's live processor is not collected. The lowering choice is a ladder,
highest supported rung first: normalized parameters, then engine-hosted specs, then
live processors.
Source code in steerability/algorithms/core/utils/assembly.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
resolve_decoding_driver(output_controls)
The sole enabled DecodingDriver, or None for the pipeline's default decode loop.
merge_controls guarantees at most one enabled driver at construction; enabled is
re-checked here so a driver disabled afterward falls back cleanly. The default loop
(per-prompt items executed by the inference session) is pipeline infrastructure, not a
phantom control.
Source code in steerability/algorithms/core/utils/assembly.py
356 357 358 359 360 361 362 363 364 365 366 367 | |
rollout_entries(state_entries, steered_input_ids, steered_attention_mask)
Rollout variants of the lowered entries for a driver on a spec-consuming backend.
Prompt-relative scopes are rewritten to absolute positions at the generation's original prompt boundary. The rewrite needs one exact anchor per generation, and a rollout item cannot be traced back to a batch row, so uneven batches (rows whose true prompt lengths differ under padding) are refused. Conditional gates are refused too: a worker gate re-anchors its evidence at each rollout request's own prompt end, which would decide from generated text instead of the original prompt.
Raises:
| Type | Description |
|---|---|
UnsupportedOperationError
|
If the batch is uneven, a scope has no absolute rollout form, or an entry carries a conditional gate. |
Source code in steerability/algorithms/core/utils/assembly.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
auxiliary_pass
Marking for forward passes through the pipeline's model that are not generation steps.
Output-control components that forward the pipeline's own model during decoding wrap those calls in
auxiliary_pass(). State-control accounting consults current_auxiliary_pass() to keep auxiliary
passes out of condition scoring, gate updates, and fallback position counting. aligned declares
whether the pass's token positions lie on the current generation's coordinate axis (a prefix of the
trajectory, or a prefix plus a candidate next token) or on a detached sequence such as a
transformed prompt.
AuxiliaryPassInfo
dataclass
Describes the auxiliary pass currently in flight.
Attributes:
| Name | Type | Description |
|---|---|---|
aligned |
bool
|
True when the pass's token positions lie on the current generation's coordinate axis. False for a detached sequence. |
Source code in steerability/algorithms/core/utils/auxiliary_pass.py
17 18 19 20 21 22 23 24 25 26 | |
aligned
instance-attribute
auxiliary_pass(*, aligned=True)
Mark model forwards issued inside the block as auxiliary (not generation steps).
Source code in steerability/algorithms/core/utils/auxiliary_pass.py
34 35 36 37 38 39 40 41 | |
current_auxiliary_pass()
The in-flight auxiliary pass marker, or None during ordinary generation passes.
Source code in steerability/algorithms/core/utils/auxiliary_pass.py
44 45 46 | |
controls
Helpers for working with control objects: composition/validation and adapt-messages guards.
merge_controls(supplied)
Sort supplied controls by category.
Every category admits any number of controls, returned as ordered lists (in encounter order)
under "input_controls", "structural_controls", "state_controls", and "output_controls".
An omitted category is an empty list; every application of a category is a fold over its
list, whose identity element is the empty sequence (the prompt threads through the adapt
chain, the model threads through structural steers, state and output entries accumulate).
The output category additionally admits at most one enabled DecodingDriver; the decode loop
does not compose. Input controls chain in two phases (message-level, then token-level); see
SteeringPipeline.generate for the per-control application contract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
supplied
|
Iterable[StructuralControl | StateControl | InputControl | OutputControl]
|
List of control instances to organize |
required |
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
Dict with keys |
dict[str, object]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the same control instance is supplied more than once, or if more than one
enabled |
TypeError
|
If an unrecognized control type is supplied |
Source code in steerability/algorithms/core/utils/controls.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
runtime_kwargs_schema(controls)
Merge the RUNTIME_KWARGS_SCHEMA declarations of the enabled controls, by name.
Each declared entry carries name plus optional type, required, help, and scope
fields. scope is "row" for a per-prompt value (in a batched call the control receives a
sequence with one element per prompt row, in row order) or "call" for one value per
generate call regardless of batch size; an entry without scope is "call". Two controls
may declare one name only when their declarations agree, in which case they share one value at
inference time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
controls
|
Iterable[StructuralControl | StateControl | InputControl | OutputControl]
|
Control instances whose enabled members' declarations are merged. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
Mapping from declared name to its merged entry, with |
dict[str, dict]
|
|
dict[str, dict]
|
are kept. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an entry's |
Source code in steerability/algorithms/core/utils/controls.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
warn_if_adapt_messages_bypassed(input_controls, already_warned)
Warn (UserWarning) when any control in input_controls overrides adapt_messages but the
caller used tensor/text input, bypassing chat-template tokenization. The warning names each
bypassed control class. Returns the updated warned-state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_controls
|
list[InputControl]
|
The pipeline's input controls, in list order. |
required |
already_warned
|
bool
|
Whether the bypass warning has already fired for this pipeline. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
The updated warned-state. |
Source code in steerability/algorithms/core/utils/controls.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
generation
Prompt resolution helpers for SteeringPipeline: source dispatch, per-modality validation
and tokenization, message-level adaptation, and the token-level adapt chain.
PromptWarnings
dataclass
Once-per-pipeline warning flags for prompt resolution.
Source code in steerability/algorithms/core/utils/generation.py
20 21 22 23 24 25 | |
duplicate_bos = False
class-attribute
instance-attribute
tensor_with_adapt_messages = False
class-attribute
instance-attribute
apply_adapt_messages_and_tokenize(input_controls, tokenizer, messages_batch, runtime_kwargs, chat_template_kwargs=None)
Fold every input control's adapt_messages over the message batch, then chat-template tokenize once.
Controls run in list order. A non-None return becomes the input to the next control and marks
that control as handled at message level; a None return passes the messages through unchanged
and leaves the control unmarked, so the pipeline later runs its token-level adapt instead.
Each control is therefore applied exactly once per call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_controls
|
'list[InputControl]'
|
Input controls whose |
required |
tokenizer
|
'PreTrainedTokenizerBase'
|
Tokenizer whose |
required |
messages_batch
|
list[list[dict]]
|
One conversation per row, each a list of chat-message mappings. |
required |
runtime_kwargs
|
dict
|
Per-call parameters forwarded to |
required |
chat_template_kwargs
|
dict | None
|
Extra keyword arguments forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
tuple[input_ids, attention_mask, handled] where |
Tensor | None
|
control whose |
Source code in steerability/algorithms/core/utils/generation.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
prepare_inputs(input_ids, attention_mask, *, input_controls, tokenizer, device, runtime_kwargs, message_handled=frozenset(), warnings_state)
Apply the token-level input-control chain and normalize input tensors.
Runs each input control's adapt in list order (each control receives the previous
control's output), then ensures both input_ids and attention_mask are properly shaped
tensors on the correct device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
list[int] | LongTensor
|
Input token IDs as list or tensor [seq_len] or [batch, seq_len] |
required |
attention_mask
|
Tensor | None
|
Optional attention mask matching input_ids shape |
required |
input_controls
|
'list[InputControl]'
|
Input controls whose token-level |
required |
tokenizer
|
'PreTrainedTokenizerBase | None'
|
Tokenizer consulted for pad-token mask inference and the duplicate-bos check. |
required |
device
|
device
|
Device the returned tensors are moved to. |
required |
runtime_kwargs
|
dict | None
|
Per-call parameters for input controls |
required |
message_handled
|
frozenset[int]
|
|
frozenset()
|
warnings_state
|
PromptWarnings
|
Once-per-pipeline warning flags, updated in place. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Tensor, Tensor]
|
tuple[torch.Tensor, torch.Tensor]: (steered_input_ids, attention_mask), both as 2D tensors on |
Source code in steerability/algorithms/core/utils/generation.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | |
resolve_generate_source(inputs, text, messages, input_ids)
Select the single prompt source and its modality.
Exactly one of positional inputs, text=, messages=, or input_ids= may be provided.
Positional input is a convenience for text prompts (str or a list whose every element is
a str) and routes to text; any other positional shape raises (E12). Because the check is a
total all(...) over the list, a mixed list such as ["a", {"role": ...}] fails here rather
than downstream.
Returns:
| Type | Description |
|---|---|
Literal['text', 'messages', 'tokens']
|
tuple[kind, payload] where |
Any
|
is the value handed to the matching resolver. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If no source or more than one source is provided (E1/E2), or a positional
input is neither a |
Source code in steerability/algorithms/core/utils/generation.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
resolve_messages_prompt(messages, runtime_kwargs, *, input_controls, tokenizer, chat_template_kwargs=None)
Validate a chat prompt, then adapt and chat-template tokenize it (design §4.3.2).
Accepts one conversation (a sequence of mappings) or a batch (a sequence of sequences of
mappings). Message elements are validated as collections.abc.Mapping; role/content schema
remains the responsibility of apply_chat_template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
Any
|
One conversation or a batch of conversations. |
required |
runtime_kwargs
|
dict
|
Per-call parameters forwarded to |
required |
input_controls
|
'list[InputControl]'
|
Input controls whose |
required |
tokenizer
|
'PreTrainedTokenizerBase'
|
Tokenizer whose |
required |
chat_template_kwargs
|
dict | None
|
Extra keyword arguments forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
tuple[input_ids, attention_mask, message_handled, is_single], where |
Tensor | None
|
holds |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the conversation or batch is empty (E5). |
TypeError
|
If a batch inner element is not a mapping (E6) or the outer sequence mixes element kinds (E7). |
Source code in steerability/algorithms/core/utils/generation.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
resolve_text_prompt(text, *, input_controls, tokenizer, warnings_state)
Validate and tokenize a text prompt (design §4.3.1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
Any
|
A |
required |
input_controls
|
'list[InputControl]'
|
Input controls consulted for the bypass warning. |
required |
tokenizer
|
'PreTrainedTokenizerBase'
|
Tokenizer used for plain-text tokenization. |
required |
warnings_state
|
PromptWarnings
|
Once-per-pipeline warning flags, updated in place. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Tensor, Tensor | None, bool]
|
tuple[input_ids, attention_mask, is_single]. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
Source code in steerability/algorithms/core/utils/generation.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
resolve_token_prompt(input_ids, attention_mask, *, input_controls, warnings_state)
Validate a token prompt (tokens only; design §4.3.3).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Any
|
A 1-D/2-D |
required |
attention_mask
|
Tensor | None
|
Optional mask, passed through unchanged. |
required |
input_controls
|
'list[InputControl]'
|
Input controls consulted for the bypass warning. |
required |
warnings_state
|
PromptWarnings
|
Once-per-pipeline warning flags, updated in place. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Tensor, Tensor | None, bool]
|
tuple[input_ids, attention_mask, is_single]. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a tensor is neither 1-D nor 2-D (E8), or nested lists are ragged (E9). |
TypeError
|
If the value is not a token tensor or integer list (E10). |
Source code in steerability/algorithms/core/utils/generation.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |