TRL
steerability.algorithms.structural_control.wrappers.trl
The TRL wrapper implements a variety of methods from Hugging Face's TRL library.
The current functionality spans the following methods:
- SFT (Supervised Fine-Tuning): Standard supervised learning to fine-tune language models on demonstration data
- DPO (Direct Preference Optimization): Trains models directly on preference data without requiring a separate reward model
- APO (Anchored Preference Optimization): A variant of DPO that uses an anchor model to improve training stability and performance
- PPO (Proximal Policy Optimization): Reinforcement learning against a sequence-classification reward model (and value model)
- GRPO (Group-Relative Policy Optimization): Critic-free reinforcement learning that takes a callable reward function (no reward model and no value model); used by PRewrite for its metric-in-the-loop reward
For documentation information, please refer to the TRL page.
args
base_mixin
TRLMixin
Small shared helpers for TRL-based structural controls.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.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 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 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 | |
adapter_name = None
class-attribute
instance-attribute
base_model_name_or_path = None
class-attribute
instance-attribute
device = None
class-attribute
instance-attribute
hf_model_kwargs = {}
class-attribute
instance-attribute
lora_kwargs = {}
class-attribute
instance-attribute
merge_lora_after_train = False
class-attribute
instance-attribute
merged_output_dir = None
class-attribute
instance-attribute
output_dir = None
class-attribute
instance-attribute
peft_type = None
class-attribute
instance-attribute
resume_from_checkpoint = None
class-attribute
instance-attribute
tokenizer = None
class-attribute
instance-attribute
tokenizer_name_or_path = None
class-attribute
instance-attribute
training_args = {}
class-attribute
instance-attribute
trust_remote_code = False
class-attribute
instance-attribute
use_peft = False
class-attribute
instance-attribute
artifact_capability()
The serve capability implied by this training configuration.
Training runs only when train_dataset is set, so a configuration without one produces
no artifact. A LoRA run without merge-back saves an adapter to the output directory
(Capability.SERVE_LORA); a full fine-tune saves a checkpoint there
(Capability.SERVE_CHECKPOINT); a merged LoRA run yields a checkpoint only when
merged_output_dir is set.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
export_artifact()
The on-disk product of this configuration's steer(), matching
artifact_capability().
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
162 163 164 165 166 167 168 169 170 171 172 173 | |
export_state()
The trained on-disk product under the "artifact" key, for freezing.
Returns an empty mapping when the configuration trains nothing (train_dataset is
None), so an inert wrapper's recipe is its frozen form.
Raises:
| Type | Description |
|---|---|
NotFreezableError
|
If the configuration trains but produces no on-disk product
(a merged LoRA run without |
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
fit_identity()
The training-relevant args projection, or None when nothing trains.
Output locations (output_dir, merged_output_dir, resume_from_checkpoint, and
training_args["output_dir"]) are excluded, since where a product is saved does not
change what was trained.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
frozen_form(state)
The trained artifact as a load_lora or load_checkpoint entry.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
195 196 197 198 199 200 201 202 203 204 | |
resolve_config_kwargs(config_cls, training_args)
The kwargs to construct config_cls from training_args.
Every key must be a dataclass field of config_cls; None values are dropped so the config's
own default applies. The toolkit forwards training_args verbatim to TRL, so a key the config
does not declare would otherwise be passed to a constructor that does not accept it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_cls
|
type
|
A TRL config dataclass ( |
required |
training_args
|
dict[str, Any]
|
The composed training arguments. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The accepted kwargs, in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any key is not a field of |
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.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 | |
grpotrainer
args
base_mixin
GRPOTrainerMixin
Bases: TRLMixin, StructuralControl
GRPO structural control backed by TRL's GRPOTrainer.
GRPO is critic-free (group-relative advantage), so there is no reward model and no value model.
The reward comes from one or more callables in reward_funcs, each called as
reward_func(prompts, completions, **kwargs) and returning one float per completion. The trainer
reads a text "prompt" column directly and samples num_generations completions per prompt, so
the dataset is only standardized to a prompt column and is not tokenized into an input_ids
column.
Source code in steerability/algorithms/structural_control/wrappers/trl/grpotrainer/base_mixin.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 | |
RUNTIME_KWARGS_SCHEMA = []
class-attribute
instance-attribute
adapter_name = None
class-attribute
instance-attribute
args = self.Args.validate(*args, **kwargs)
instance-attribute
base_model_name_or_path = None
class-attribute
instance-attribute
device = None
class-attribute
instance-attribute
enabled = True
class-attribute
instance-attribute
eval_dataset = None
class-attribute
instance-attribute
hf_model_kwargs = {}
class-attribute
instance-attribute
lora_kwargs = {}
class-attribute
instance-attribute
merge_lora_after_train = False
class-attribute
instance-attribute
merged_output_dir = None
class-attribute
instance-attribute
output_dir = None
class-attribute
instance-attribute
peft_type = None
class-attribute
instance-attribute
resume_from_checkpoint = None
class-attribute
instance-attribute
reward_funcs = None
class-attribute
instance-attribute
supports_batching = True
class-attribute
instance-attribute
tokenizer = None
class-attribute
instance-attribute
tokenizer_name_or_path = None
class-attribute
instance-attribute
train_dataset = None
class-attribute
instance-attribute
training_args = {}
class-attribute
instance-attribute
trust_remote_code = False
class-attribute
instance-attribute
use_peft = False
class-attribute
instance-attribute
artifact_capability()
The serve capability implied by this training configuration.
Training runs only when train_dataset is set, so a configuration without one produces
no artifact. A LoRA run without merge-back saves an adapter to the output directory
(Capability.SERVE_LORA); a full fine-tune saves a checkpoint there
(Capability.SERVE_CHECKPOINT); a merged LoRA run yields a checkpoint only when
merged_output_dir is set.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
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_artifact()
The on-disk product of this configuration's steer(), matching
artifact_capability().
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
162 163 164 165 166 167 168 169 170 171 172 173 | |
export_state()
The trained on-disk product under the "artifact" key, for freezing.
Returns an empty mapping when the configuration trains nothing (train_dataset is
None), so an inert wrapper's recipe is its frozen form.
Raises:
| Type | Description |
|---|---|
NotFreezableError
|
If the configuration trains but produces no on-disk product
(a merged LoRA run without |
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
fit_identity()
The training-relevant args projection, or None when nothing trains.
Output locations (output_dir, merged_output_dir, resume_from_checkpoint, and
training_args["output_dir"]) are excluded, since where a product is saved does not
change what was trained.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
frozen_form(state)
The trained artifact as a load_lora or load_checkpoint entry.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
195 196 197 198 199 200 201 202 203 204 | |
requirements()
Backend requirements computed from this instance's configuration, per phase.
The generate phase requires Capability.IN_PROCESS_TORCH for in-process adoption of
the returned model; when the configuration produces an on-disk artifact
(artifact_capability()), serving that artifact is an alternative, so a backend
advertising the matching serve capability also supports the generate phase.
Returns:
| Type | Description |
|---|---|
Requirements
|
The control's phase-keyed requirements. |
Source code in steerability/algorithms/structural_control/base.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
steer(model, tokenizer=None, **_)
Required steering/preparation.
session is a SteeringSession on the steering backend, provided by the pipeline.
Source code in steerability/algorithms/structural_control/wrappers/trl/grpotrainer/base_mixin.py
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 | |
steer_access()
ModelAccess.MODULE; training happens on live weights.
Source code in steerability/algorithms/structural_control/base.py
112 113 114 | |
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 | |
control
GRPO
Bases: GRPOTrainerMixin
GRPO controller.
Source code in steerability/algorithms/structural_control/wrappers/trl/grpotrainer/control.py
5 6 7 8 9 | |
RUNTIME_KWARGS_SCHEMA = []
class-attribute
instance-attribute
adapter_name = None
class-attribute
instance-attribute
args = self.Args.validate(*args, **kwargs)
instance-attribute
base_model_name_or_path = None
class-attribute
instance-attribute
device = None
class-attribute
instance-attribute
enabled = True
class-attribute
instance-attribute
eval_dataset = None
class-attribute
instance-attribute
hf_model_kwargs = {}
class-attribute
instance-attribute
lora_kwargs = {}
class-attribute
instance-attribute
merge_lora_after_train = False
class-attribute
instance-attribute
merged_output_dir = None
class-attribute
instance-attribute
output_dir = None
class-attribute
instance-attribute
peft_type = None
class-attribute
instance-attribute
resume_from_checkpoint = None
class-attribute
instance-attribute
reward_funcs = None
class-attribute
instance-attribute
supports_batching = True
class-attribute
instance-attribute
tokenizer = None
class-attribute
instance-attribute
tokenizer_name_or_path = None
class-attribute
instance-attribute
train_dataset = None
class-attribute
instance-attribute
training_args = {}
class-attribute
instance-attribute
trust_remote_code = False
class-attribute
instance-attribute
use_peft = False
class-attribute
instance-attribute
artifact_capability()
The serve capability implied by this training configuration.
Training runs only when train_dataset is set, so a configuration without one produces
no artifact. A LoRA run without merge-back saves an adapter to the output directory
(Capability.SERVE_LORA); a full fine-tune saves a checkpoint there
(Capability.SERVE_CHECKPOINT); a merged LoRA run yields a checkpoint only when
merged_output_dir is set.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
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_artifact()
The on-disk product of this configuration's steer(), matching
artifact_capability().
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
162 163 164 165 166 167 168 169 170 171 172 173 | |
export_state()
The trained on-disk product under the "artifact" key, for freezing.
Returns an empty mapping when the configuration trains nothing (train_dataset is
None), so an inert wrapper's recipe is its frozen form.
Raises:
| Type | Description |
|---|---|
NotFreezableError
|
If the configuration trains but produces no on-disk product
(a merged LoRA run without |
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
fit_identity()
The training-relevant args projection, or None when nothing trains.
Output locations (output_dir, merged_output_dir, resume_from_checkpoint, and
training_args["output_dir"]) are excluded, since where a product is saved does not
change what was trained.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
frozen_form(state)
The trained artifact as a load_lora or load_checkpoint entry.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
195 196 197 198 199 200 201 202 203 204 | |
requirements()
Backend requirements computed from this instance's configuration, per phase.
The generate phase requires Capability.IN_PROCESS_TORCH for in-process adoption of
the returned model; when the configuration produces an on-disk artifact
(artifact_capability()), serving that artifact is an alternative, so a backend
advertising the matching serve capability also supports the generate phase.
Returns:
| Type | Description |
|---|---|
Requirements
|
The control's phase-keyed requirements. |
Source code in steerability/algorithms/structural_control/base.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
steer(model, tokenizer=None, **_)
Required steering/preparation.
session is a SteeringSession on the steering backend, provided by the pipeline.
Source code in steerability/algorithms/structural_control/wrappers/trl/grpotrainer/base_mixin.py
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 | |
steer_access()
ModelAccess.MODULE; training happens on live weights.
Source code in steerability/algorithms/structural_control/base.py
112 113 114 | |
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 | |
ppotrainer
args
base_mixin
PPOTrainerMixin
Bases: TRLMixin, StructuralControl
PPO structural control backed by TRL's PPOTrainer (shipped under trl.experimental in TRL 1.x).
Reward and value models are sequence-classification models. When
value_model_name_or_path is not provided, the wrapper loads a fresh value model from the same
path as the reward model, since TRL's PPOTrainer wraps the value model into its policy and
rejects value_model=None.
The standardized prompt-only training dataset is tokenized into an input_ids column before
being passed to the trainer, which reads data["input_ids"] directly.
Note: reward and value models must share the policy's tokenizer/vocabulary. The wrapper guards this with an error.
Source code in steerability/algorithms/structural_control/wrappers/trl/ppotrainer/base_mixin.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 | |
RUNTIME_KWARGS_SCHEMA = []
class-attribute
instance-attribute
adapter_name = None
class-attribute
instance-attribute
args = self.Args.validate(*args, **kwargs)
instance-attribute
base_model_name_or_path = None
class-attribute
instance-attribute
device = None
class-attribute
instance-attribute
enabled = True
class-attribute
instance-attribute
eval_dataset = None
class-attribute
instance-attribute
hf_model_kwargs = {}
class-attribute
instance-attribute
lora_kwargs = {}
class-attribute
instance-attribute
max_prompt_length = 512
class-attribute
instance-attribute
merge_lora_after_train = False
class-attribute
instance-attribute
merged_output_dir = None
class-attribute
instance-attribute
output_dir = None
class-attribute
instance-attribute
peft_type = None
class-attribute
instance-attribute
resume_from_checkpoint = None
class-attribute
instance-attribute
reward_model_name_or_path = None
class-attribute
instance-attribute
supports_batching = True
class-attribute
instance-attribute
tokenizer = None
class-attribute
instance-attribute
tokenizer_name_or_path = None
class-attribute
instance-attribute
train_dataset = None
class-attribute
instance-attribute
training_args = {}
class-attribute
instance-attribute
trust_remote_code = False
class-attribute
instance-attribute
use_peft = False
class-attribute
instance-attribute
value_model_name_or_path = None
class-attribute
instance-attribute
artifact_capability()
The serve capability implied by this training configuration.
Training runs only when train_dataset is set, so a configuration without one produces
no artifact. A LoRA run without merge-back saves an adapter to the output directory
(Capability.SERVE_LORA); a full fine-tune saves a checkpoint there
(Capability.SERVE_CHECKPOINT); a merged LoRA run yields a checkpoint only when
merged_output_dir is set.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
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_artifact()
The on-disk product of this configuration's steer(), matching
artifact_capability().
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
162 163 164 165 166 167 168 169 170 171 172 173 | |
export_state()
The trained on-disk product under the "artifact" key, for freezing.
Returns an empty mapping when the configuration trains nothing (train_dataset is
None), so an inert wrapper's recipe is its frozen form.
Raises:
| Type | Description |
|---|---|
NotFreezableError
|
If the configuration trains but produces no on-disk product
(a merged LoRA run without |
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
fit_identity()
The training-relevant args projection, or None when nothing trains.
Output locations (output_dir, merged_output_dir, resume_from_checkpoint, and
training_args["output_dir"]) are excluded, since where a product is saved does not
change what was trained.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
frozen_form(state)
The trained artifact as a load_lora or load_checkpoint entry.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
195 196 197 198 199 200 201 202 203 204 | |
requirements()
Backend requirements computed from this instance's configuration, per phase.
The generate phase requires Capability.IN_PROCESS_TORCH for in-process adoption of
the returned model; when the configuration produces an on-disk artifact
(artifact_capability()), serving that artifact is an alternative, so a backend
advertising the matching serve capability also supports the generate phase.
Returns:
| Type | Description |
|---|---|
Requirements
|
The control's phase-keyed requirements. |
Source code in steerability/algorithms/structural_control/base.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
steer(model, tokenizer=None, ref_model=None, **_)
Required steering/preparation.
session is a SteeringSession on the steering backend, provided by the pipeline.
Source code in steerability/algorithms/structural_control/wrappers/trl/ppotrainer/base_mixin.py
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 | |
steer_access()
ModelAccess.MODULE; training happens on live weights.
Source code in steerability/algorithms/structural_control/base.py
112 113 114 | |
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 | |
control
PPO
Bases: PPOTrainerMixin
PPO controller.
Source code in steerability/algorithms/structural_control/wrappers/trl/ppotrainer/control.py
5 6 7 8 9 | |
RUNTIME_KWARGS_SCHEMA = []
class-attribute
instance-attribute
adapter_name = None
class-attribute
instance-attribute
args = self.Args.validate(*args, **kwargs)
instance-attribute
base_model_name_or_path = None
class-attribute
instance-attribute
device = None
class-attribute
instance-attribute
enabled = True
class-attribute
instance-attribute
eval_dataset = None
class-attribute
instance-attribute
hf_model_kwargs = {}
class-attribute
instance-attribute
lora_kwargs = {}
class-attribute
instance-attribute
max_prompt_length = 512
class-attribute
instance-attribute
merge_lora_after_train = False
class-attribute
instance-attribute
merged_output_dir = None
class-attribute
instance-attribute
output_dir = None
class-attribute
instance-attribute
peft_type = None
class-attribute
instance-attribute
resume_from_checkpoint = None
class-attribute
instance-attribute
reward_model_name_or_path = None
class-attribute
instance-attribute
supports_batching = True
class-attribute
instance-attribute
tokenizer = None
class-attribute
instance-attribute
tokenizer_name_or_path = None
class-attribute
instance-attribute
train_dataset = None
class-attribute
instance-attribute
training_args = {}
class-attribute
instance-attribute
trust_remote_code = False
class-attribute
instance-attribute
use_peft = False
class-attribute
instance-attribute
value_model_name_or_path = None
class-attribute
instance-attribute
artifact_capability()
The serve capability implied by this training configuration.
Training runs only when train_dataset is set, so a configuration without one produces
no artifact. A LoRA run without merge-back saves an adapter to the output directory
(Capability.SERVE_LORA); a full fine-tune saves a checkpoint there
(Capability.SERVE_CHECKPOINT); a merged LoRA run yields a checkpoint only when
merged_output_dir is set.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
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_artifact()
The on-disk product of this configuration's steer(), matching
artifact_capability().
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
162 163 164 165 166 167 168 169 170 171 172 173 | |
export_state()
The trained on-disk product under the "artifact" key, for freezing.
Returns an empty mapping when the configuration trains nothing (train_dataset is
None), so an inert wrapper's recipe is its frozen form.
Raises:
| Type | Description |
|---|---|
NotFreezableError
|
If the configuration trains but produces no on-disk product
(a merged LoRA run without |
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
fit_identity()
The training-relevant args projection, or None when nothing trains.
Output locations (output_dir, merged_output_dir, resume_from_checkpoint, and
training_args["output_dir"]) are excluded, since where a product is saved does not
change what was trained.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
frozen_form(state)
The trained artifact as a load_lora or load_checkpoint entry.
Source code in steerability/algorithms/structural_control/wrappers/trl/base_mixin.py
195 196 197 198 199 200 201 202 203 204 | |
requirements()
Backend requirements computed from this instance's configuration, per phase.
The generate phase requires Capability.IN_PROCESS_TORCH for in-process adoption of
the returned model; when the configuration produces an on-disk artifact
(artifact_capability()), serving that artifact is an alternative, so a backend
advertising the matching serve capability also supports the generate phase.
Returns:
| Type | Description |
|---|---|
Requirements
|
The control's phase-keyed requirements. |
Source code in steerability/algorithms/structural_control/base.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
steer(model, tokenizer=None, ref_model=None, **_)
Required steering/preparation.
session is a SteeringSession on the steering backend, provided by the pipeline.
Source code in steerability/algorithms/structural_control/wrappers/trl/ppotrainer/base_mixin.py
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 | |
steer_access()
ModelAccess.MODULE; training happens on live weights.
Source code in steerability/algorithms/structural_control/base.py
112 113 114 | |
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 | |