Experiment utils
auto_circuit.experiment_utils
Attributes
Classes
IOI_CIRCUIT_TYPE
Bases: Enum
Type of IOI circuit. The original IOI paper discovered important attention heads and interactions between them.
Attributes
EDGES
class-attribute
instance-attribute
EDGES
ablates the edges identified by the IOI paper. Note that the IOI paper
considered intermediate MLPs to be part of the direct path between two attention
heads, so this includes many edges to or from MLPs.
EDGES_MLP_0_ONLY
class-attribute
instance-attribute
Therefore we also provide EDGES_MLP_0_ONLY
which includes only the first MLP layer
(as this seems to retain most of the performance of the full EDGES
circuit).
Functions
ioi_circuit_single_template_logit_diff_percent
ioi_circuit_single_template_logit_diff_percent(gpt2: HookedTransformer, dataset_size: int, prepend_bos: bool, template: Literal['ABBA', 'BABA'], template_idx: int, factorized: bool = False, circuit: IOI_CIRCUIT_TYPE = IOI_CIRCUIT_TYPE.NODES, ablation_type: AblationType = AblationType.TOKENWISE_MEAN_CORRUPT, tok_pos: bool = True, patch_type: PatchType = PatchType.TREE_PATCH, learned: bool = False, learned_faithfulness_target: SP_FAITHFULNESS_TARGET = 'logit_diff_percent', diff_of_mean_logit_diff: bool = False, batch_size: Optional[int] = None) -> Tuple[int, float, float, Tensor, PruneScores]
Run a single template format through the IOI circuit and return the logit diff recovered.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gpt2 |
HookedTransformer
|
A GPT2 |
required |
dataset_size |
int
|
The size of the dataset to use. |
required |
prepend_bos |
bool
|
Whether to prepend the |
required |
template |
Literal['ABBA', 'BABA']
|
The type of template to use. (This is the order of names). |
required |
template_idx |
int
|
The index of the template to use ( |
required |
factorized |
bool
|
Use a 'factorized' model (Edge Patching, not Node Patching). |
False
|
circuit |
IOI_CIRCUIT_TYPE
|
The type of circuit to use (see |
NODES
|
ablation_type |
AblationType
|
The type of ablation to use. |
TOKENWISE_MEAN_CORRUPT
|
tok_pos |
bool
|
Whether to ablate different token positions separately. |
True
|
patch_type |
PatchType
|
The type of patch to use (ablate the circuit or the complement). |
TREE_PATCH
|
learned |
bool
|
Whether to learn a new circuit using |
False
|
learned_faithfulness_target |
SP_FAITHFULNESS_TARGET
|
The faithfulness target used to learn the circuit. |
'logit_diff_percent'
|
learned_faithfulness_target |
SP_FAITHFULNESS_TARGET
|
The faithfulness metric to optimize the learned circuit for. |
'logit_diff_percent'
|
diff_of_mean_logit_diff |
bool
|
False
|
|
batch_size |
Optional[int]
|
The batch size to use. |
None
|
Returns:
Type | Description |
---|---|
Tuple[int, float, float, Tensor, PruneScores]
|
The number of edges in the circuit, the mean logit diff percent, the standard deviation of the logit diff percent, and the prune scores of the circuit. |
Source code in auto_circuit/experiment_utils.py
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 |
|
load_tl_model
Load a HookedTransformer
model with the necessary config to perform edge patching
(with separate edges to Q, K, and V). Sets requires_grad
to False
for all model
weights (this does not affect Mask gradients).