| 1 |
"""Control vectors as first-class artifacts. |
| 2 |
|
| 3 |
A control vector is a one-shot steering direction extracted from |
| 4 |
`::preference::` section hidden states. The extraction is |
| 5 |
gradient-free (PCA over chosen − rejected residuals) and takes |
| 6 |
seconds-to-minutes rather than the LoRA retraining path's hours. |
| 7 |
Applied at inference via a `forward_pre_hook` on the residual |
| 8 |
stream, it nudges generation toward the chosen distribution |
| 9 |
without modifying weights. |
| 10 |
|
| 11 |
Package layout mirrors `dlm.directives`: `extract` produces the |
| 12 |
vector, `apply` attaches it, `errors` holds the exception |
| 13 |
hierarchy. Store layout lives under |
| 14 |
`~/.dlm/store/<dlm_id>/controls/<name>.safetensors` + |
| 15 |
`<name>.meta.json`. |
| 16 |
""" |
| 17 |
|
| 18 |
from __future__ import annotations |
| 19 |
|
| 20 |
from dlm.control.apply import apply_control |
| 21 |
from dlm.control.errors import ( |
| 22 |
ControlApplyError, |
| 23 |
ControlError, |
| 24 |
ControlExtractError, |
| 25 |
ControlPolicyRefusal, |
| 26 |
) |
| 27 |
from dlm.control.extract import ( |
| 28 |
ControlVector, |
| 29 |
extract_control_vector, |
| 30 |
refuse_if_policy_safety, |
| 31 |
) |
| 32 |
|
| 33 |
__all__ = [ |
| 34 |
"ControlApplyError", |
| 35 |
"ControlError", |
| 36 |
"ControlExtractError", |
| 37 |
"ControlPolicyRefusal", |
| 38 |
"ControlVector", |
| 39 |
"apply_control", |
| 40 |
"extract_control_vector", |
| 41 |
"refuse_if_policy_safety", |
| 42 |
] |