File size: 964 Bytes
0838b38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3
"""Extract the Qwen3.5-27B rat feature's unit decoder direction into rat_vector.pt.

The Space steers with Eq.1 (h <- h + alpha * d), which needs only the feature's unit decoder
column, so it ships this 5120-float vector instead of the 3.4 GB SAE layer file. The feature is the
one the OCD battery discovered for Qwen3.5-27B (out_v2/27B/discovered.json: L51 f26585).

    hf download Qwen/SAE-Res-Qwen3.5-27B-W80K-L0_50 layer51.sae.pt --local-dir sae27
    python make_rat_vector.py sae27/layer51.sae.pt
"""
import sys

import torch

from ocd_core import dirs_for, load_sae

SAE_REPO = "Qwen/SAE-Res-Qwen3.5-27B-W80K-L0_50"
LAYER, FEATURE, D_MODEL = 51, 26585, 5120

d_f, _, _, _ = dirs_for(load_sae(sys.argv[1]), FEATURE, D_MODEL)
torch.save({"d": d_f.contiguous(), "sae_repo": SAE_REPO, "layer": LAYER, "feature": FEATURE},
           "rat_vector.pt")
print(f"rat_vector.pt: L{LAYER} f{FEATURE}  dim={d_f.numel()}  norm={d_f.norm():.6f}")