Subnetwork probing
auto_circuit.prune_algos.subnetwork_probing
Attributes
Classes
Functions
subnetwork_probing_prune_scores
subnetwork_probing_prune_scores(model: PatchableModel, dataloader: PromptDataLoader, official_edges: Optional[Set[Edge]], learning_rate: float = 0.1, epochs: int = 20, regularize_lambda: float = 10, mask_fn: MaskFn = 'hard_concrete', dropout_p: float = 0.0, init_val: float = init_mask_val, show_train_graph: bool = False, circuit_size: Optional[int] = None, tree_optimisation: bool = False, avoid_edges: Optional[Set[Edge]] = None, avoid_lambda: float = 1.0, faithfulness_target: SP_FAITHFULNESS_TARGET = 'kl_div', validation_dataloader: Optional[PromptDataLoader] = None) -> PruneScores
Optimize the edge mask values using gradient descent to maximize the faithfulness of and minimize the number of edges in the circuit. This is based loosely on Subnetwork Probing (Cao et al., 2021).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
PatchableModel
|
The model to find the circuit for. |
required |
dataloader |
PromptDataLoader
|
The dataloader to use for training input and ablation. |
required |
official_edges |
Optional[Set[Edge]]
|
Not used. |
required |
learning_rate |
float
|
The learning rate for the optimizer. |
0.1
|
epochs |
int
|
The number of epochs to train for. |
20
|
regularize_lambda |
float
|
The weight of the regularization term, that tries to minimize the number of edges in the circuit. |
10
|
mask_fn |
MaskFn
|
The function to use to transform the mask values before they are used
to interpolate edges between the clean and ablated activations. Note that
|
'hard_concrete'
|
dropout_p |
float
|
The dropout probability of the masks to use during training. |
0.0
|
init_val |
float
|
The initial value of the mask values. This can be sensitive when using
the |
init_mask_val
|
show_train_graph |
bool
|
Whether to show a graph of the training loss. |
False
|
circuit_size |
Optional[int]
|
The size of the circuit to aim for. When this is not |
None
|
tree_optimisation |
bool
|
If |
False
|
avoid_edges |
Optional[Set[Edge]]
|
A set of edges to avoid. An extra penalty is added to the loss for each edge in this set that is included in the circuit. |
None
|
avoid_lambda |
float
|
The weight of the penalty for |
1.0
|
faithfulness_target |
SP_FAITHFULNESS_TARGET
|
The faithfulness metric to optimize the circuit for. |
'kl_div'
|
validation_dataloader |
Optional[PromptDataLoader]
|
If not |
None
|
Returns:
Type | Description |
---|---|
PruneScores
|
An ordering of the edges by importance to the task. Importance is equal to the absolute value of the score assigned to the edge. |
Source code in auto_circuit/prune_algos/subnetwork_probing.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 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 |
|