DeAL
steerability.algorithms.output_control.deal
args
control
DeAL
Bases: SearchDriver
Implementation of DeAL (Decoding-time Alignment) from Huang et al., 2024.
DeAL performs controlled text generation through iterative lookahead search and reward-guided beam selection. Unlike training-time alignment methods, DeAL operates purely at inference time to steer language model outputs toward desired behaviors.
The algorithm works in three phases:
-
Lookahead Generation: Generate multiple candidate continuations using beam search from the current context.
-
Reward-based Scoring: Evaluate each candidate continuation using a provided reward function that measures alignment with the desired objective (e.g., helpfulness, safety).
-
Iterative Refinement: Select the top-k highest-scoring beams and repeat the process until termination conditions are met (EOS token, max length, or max iterations reached).
DeAL is a decoding driver implemented as a preset of the generic SearchDriver, mapping its arguments onto the
search fields (scorer, segment_len, num_candidates, keep_k, max_iterations, and propose_mode="beam").
The composed logits processors and stopping criteria apply inside every lookahead rollout, which means that a
step-level control such as RAD steers every DeAL rollout. The reward_params runtime kwarg is honored per row (one
mapping merged into the scorer's params).
Reference:
- "DeAL: Decoding-time Alignment for Large Language Models" James Y. Huang, Sailik Sengupta, Daniele Bonadiman, Yi-an Lai, Arshit Gupta, Nikolaos Pappas, Saab Mansour, Katrin Kirchhoff, Dan Roth https://arxiv.org/abs/2402.06147
Source code in steerability/algorithms/output_control/deal/control.py
10 11 12 13 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 | |
RUNTIME_KWARGS_SCHEMA = [{'name': 'reward_params', 'type': 'dict', 'scope': 'row', 'help': "Entries merged into the scorer's params mapping on every scoring call of this generation. The per-row form is one mapping; the driver handles one prompt per call, so a batched delivery is a one-element sequence holding that mapping. A per-sample mapping (for example a reference answer under 'reference') reaches the scorer's row through SampleSequenceScorer."}]
class-attribute
instance-attribute
args = self.Args.validate(*args, **kwargs)
instance-attribute
enabled = True
class-attribute
instance-attribute
include_in_scoring = True
class-attribute
instance-attribute
keep_k = keep_k
instance-attribute
max_iterations = max_iterations
instance-attribute
num_candidates = num_candidates
instance-attribute
propose_mode = propose_mode
instance-attribute
same_model_forwards = False
class-attribute
instance-attribute
scorer = scorer
instance-attribute
segment_len = segment_len
instance-attribute
supports_batching = False
class-attribute
instance-attribute
tokenizer = None
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 | |
decode(input_ids, attention_mask, model, logits_processors, stopping_criteria, runtime_kwargs, session=None, **gen_kwargs)
Run the decoding procedure; return full sequence ids (prompt + continuation).
Source code in steerability/algorithms/output_control/common/drivers/search.py
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 | |
export_constraint(runtime_kwargs=None)
The control's declarative constrained-decoding source, or None.
A control whose per-step masking compiles from a declarative source returns a
ConstraintSource; on a backend advertising Capability.GUIDED_DECODING the pipeline
renders it onto the engine's native structured-output parameters in place of the
control's live processor. The default returns None, which keeps the control on the live
processor mechanism.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runtime_kwargs
|
dict | None
|
Per-call parameters supplied to |
None
|
Returns:
| Type | Description |
|---|---|
ConstraintSource | None
|
The constraint source, or None. |
Source code in steerability/algorithms/output_control/base.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
export_generation_params(runtime_kwargs=None)
The control's sampling-expressible contribution, or None.
A control whose behavior is expressible as normalized generation parameters returns a
mapping over a subset of stop_strings, stop_token_ids, max_new_tokens, and
min_new_tokens; the pipeline merges it into the call's GenerationParams (stop rules
union with the caller's; token bounds only tighten) and does not additionally collect
the control's live processors and criteria for that call, so the control executes on
every backend through the session's composed stop rules. The default returns None, which
keeps the control on the live processor/criteria mechanism.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runtime_kwargs
|
dict | None
|
Per-call parameters supplied to |
None
|
Returns:
| Type | Description |
|---|---|
Mapping[str, Any] | None
|
The parameter contribution, or None. |
Source code in steerability/algorithms/output_control/base.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
export_processor_spec(runtime_kwargs=None)
The control's engine-hosted processor form, or None.
A control whose per-step logit math is expressible in an engine's served processor
vocabulary returns a ProcessorSpec; on a backend advertising
Capability.PER_STEP_LOGIT_SPECS with the spec's kind, the pipeline submits it as a
ProcessorSpecEntry in place of the control's live processor. The default returns
None, which keeps the control on the live processor mechanism.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runtime_kwargs
|
dict | None
|
Per-call parameters supplied to |
None
|
Returns:
| Type | Description |
|---|---|
ProcessorSpec | None
|
The processor spec, or None. |
Source code in steerability/algorithms/output_control/base.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
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 | |
get_logits_processors(input_ids, runtime_kwargs, **kwargs)
The control's logits processors for the current generation.
Called once per generate() / compute_logprobs() call, after input and state
controls have prepared the prompt (mirrors StateControl.get_hooks). **kwargs
carries attention_mask and the caller's generation kwargs. Returned objects
follow the HF LogitsProcessor convention; in-list order is preserved by the composition.
A processor must behave as a function of (prefix_ids, scores). Internal state is
permitted only as memoization keyed on the prefix and must re-derive on a prefix mismatch,
since drivers may restart, rewind, or reorder sequences, and scoring replays prefixes
teacher-forced (subclass common.processors.base.PrefixKeyedProcessor to satisfy this
mechanically). Return fresh processor instances from this hook; it is invoked once per call
precisely so that per-generation state is isolated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Tensor
|
The steered prompt token ids |
required |
runtime_kwargs
|
dict | None
|
Per-call parameters supplied to |
required |
Returns:
| Type | Description |
|---|---|
list
|
A list of HF |
Source code in steerability/algorithms/output_control/base.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
get_stopping_criteria(input_ids, runtime_kwargs, **kwargs)
The control's stopping criteria.
Not applied during scoring (there is no loop to stop). Same call convention as
get_logits_processors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Tensor
|
The steered prompt token ids |
required |
runtime_kwargs
|
dict | None
|
Per-call parameters supplied to |
required |
Returns:
| Type | Description |
|---|---|
list
|
A list of HF |
Source code in steerability/algorithms/output_control/base.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
max_rollouts_per_query()
num_candidates * (1 + (max_iterations - 1) * keep_k).
The first iteration proposes num_candidates continuations from the single-row prompt;
each later iteration proposes num_candidates from each of up to keep_k retained
beams.
Source code in steerability/algorithms/output_control/common/drivers/search.py
119 120 121 122 123 124 125 126 | |
requirements()
Rollouts run through the session, so sampled proposals require nothing beyond the
session contract; beam proposals require Capability.BEAM_PROPOSALS.
Source code in steerability/algorithms/output_control/common/drivers/search.py
128 129 130 131 132 133 134 135 136 | |
steer(model, tokenizer=None, **_)
Lightweight preparation; attach the tokenizer used to decode continuations.
Source code in steerability/algorithms/output_control/deal/control.py
59 60 61 62 | |
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 | |