Python · 1195 bytes Raw Blame History
1 """Exceptions for the control-vector pipeline."""
2
3 from __future__ import annotations
4
5
6 class ControlError(Exception):
7 """Base for every failure inside `dlm.control`."""
8
9
10 class ControlExtractError(ControlError):
11 """Raised when PCA-over-residuals can't produce a stable direction.
12
13 Covers degenerate inputs (zero variance, NaN hidden states,
14 mismatched chosen/rejected shapes). Caller shows the message to
15 the user; no recovery path.
16 """
17
18
19 class ControlApplyError(ControlError):
20 """Raised when a control vector can't be attached to a model.
21
22 Shape mismatch (vector dim != model hidden dim), invalid layer
23 index, or an already-active hook on the same layer.
24 """
25
26
27 class ControlPolicyRefusal(ControlError): # noqa: N818
28 """Refused to extract a control from a `policy: safety` preference.
29
30 Documents can't self-extract vectors that would undo safety
31 training — a control vector over "safe vs unsafe" chosen/rejected
32 pairs is, by construction, a steering direction that erodes the
33 safety behavior when applied at negative strength. We refuse at
34 extraction time, not application time, so the artifact never
35 reaches disk.
36 """