File size: 1,952 Bytes
26ae91c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
focus_layers = list(range(14, 26))
target_act2 = tools.localize.safety_neurons(
    method="activation", top_k=128, layers=focus_layers,
    n=32, a="borderline", b="benign", on="aligned")
target_weight2 = tools.localize.safety_neurons(
    method="weight", top_k=256, layers=focus_layers,
    n=32, a="borderline", b="benign", on="aligned")
harm_act2 = tools.localize.safety_neurons(
    method="activation", top_k=256, layers=focus_layers,
    n=32, a="harmful", b="benign", on="aligned")
ta2, tw2, ha2 = map(unit_map, [target_act2, target_weight2, harm_act2])
agreed2 = {l: sorted((ta2[l] & tw2.get(l, set())) - ha2.get(l, set()))
           for l in focus_layers}
print("Handles:", target_act2["circuit"], target_weight2["circuit"], harm_act2["circuit"])
print("Target-only intersection:", agreed2)
missing_layers = [l for l in focus_layers if l not in safe_dirs]
if missing_layers:
    more_states = tools.localize.activations(
        texts=[borderline_prompts[i] for i in refused_indices + answered_indices],
        layers=missing_layers)
    more_harm = tools.localize.refusal_direction(
        layers=missing_layers, n=32, a="harmful", b="benign")
    for k, l in enumerate(missing_layers):
        d = more_states[:len(refused_indices), k].mean(0) - more_states[len(refused_indices):, k].mean(0)
        h = more_harm[l].float()
        h = h / h.norm()
        u = d - torch.dot(d, h) * h
        safe_dirs[l] = u / u.norm()
        harm_dirs[l] = h
ranked2 = []
for l, cols in agreed2.items():
    mat = W.original(f"model.layers.{l}.mlp.down_proj.weight").float()
    for j in cols:
        score = float(torch.dot(safe_dirs[l], mat[:, j]))
        ranked2.append((score, l, j))
ranked2.sort(reverse=True)
print("Top positive safe-specific writes:", ranked2[:24])
note("CircuitKIT circuit:4 faithfulness failed with KeyError neurons_scores; not used as evidence. Expanded independent SafeTune rankings use only first 32 target prompts.")