recall_guard.mia.control
recall_guard.mia.control
Per-model control-corpus baseline for MIA feature standardisation.
Implements the mia.control component from the honest-model-ranking design.
Satisfies Requirements 3.1, 3.2, 3.3, 3.4:
ControlBaseline: frozen dataclass holding per-feature mean/std plus anis_calibratedflag derived fromn_valid >= min_valid.build_baseline(model_lm, control_rows, ref_lm, min_valid=50): calls the model on every control row, computes MIA features, drops rows where logprobs are missing or the model timed out, and aggregates per-feature mean/std withnumpy.meanandnumpy.std(ddof=0). Std is floored at_STD_FLOOR.standardise(features, baseline): pure function returning a per-feature dict of(value - mean) / max(std, _STD_FLOOR). Passes throughNoneforref_deltawhen either the baseline or the eval-time features lack it.
Only build_baseline issues HTTP calls (via the injected NvidiaLM).
standardise is pure and does no I/O. Skipped rows are reported at WARNING level
(one per skip with the row index); happy paths log nothing.
ControlBaseline
dataclass
Per-model baseline distribution of every MIA feature on the OOS control corpus.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
str
|
The NVIDIA model ID this baseline was built for. |
n_valid |
int
|
Number of control rows where |
feature_means |
dict[str, float | None]
|
Per-feature mean across the valid rows. Keys are the five MIA feature
names. |
feature_stds |
dict[str, float | None]
|
Per-feature standard deviation across the valid rows, floored at
|
is_calibrated |
bool
|
|
min_valid |
int
|
The threshold used (default 50, per the Open Defaults in requirements.md). |
Source code in recall_guard/mia/control.py
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 | |
build_baseline
build_baseline(
model_lm,
control_rows,
ref_lm,
min_valid=50,
max_workers=1,
)
Build a per-model control-corpus baseline.
For each row in control_rows:
- Call
model_lm.generate(row.prompt). OnTimeoutErrororRuntimeError(e.g., missing logprobs) the row is dropped and a WARNING is logged with the row index. - When
ref_lmis provided, also callref_lm.generate(row.prompt). A reference-side failure does not invalidate the row; it merely setsref_logprobs = Nonefor that row, so the four other features still contribute to the baseline. - Compute :class:
MiaFeaturesvia :func:compute_mia_features.
Per-feature mean and std are aggregated with numpy.mean and
numpy.std(ddof=0). Std is floored at _STD_FLOOR to avoid div-by-zero
in :func:standardise. When every valid row has ref_delta = None
(because ref_lm is None or every reference call failed), the
ref_delta mean and std are stored as None.
is_calibrated is set to n_valid >= min_valid.
Source code in recall_guard/mia/control.py
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 | |
standardise
standardise(features, baseline)
Standardise eval-time MIA features against the model's control baseline.
For each of the four always-present features loss, min_k,
min_k_pp, zlib_ratio returns (value - mean) / max(std, _STD_FLOOR).
For ref_delta returns None whenever either the baseline or the
eval-time features have no reference value to standardise, i.e., the
field stays "off" rather than being silently coerced to 0.0.
Source code in recall_guard/mia/control.py
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 | |