Hikari07jp commited on
Commit
e168a79
·
verified ·
1 Parent(s): 4cd07f6

Upload SKILL.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. SKILL.md +111 -0
SKILL.md ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: repe-refusal-steering
3
+ description: >
4
+ Apply the RepE refusal-suppression steering vector to google/gemma-4-31B-it at
5
+ inference time, in transformers OR vLLM. Use when the user wants to run this
6
+ repo's steering vector, dial the refusal direction (sigma), reproduce the
7
+ dose-response, or serve an uncensored/steered Gemma-4 for interpretability or
8
+ safety research. Triggers: RepE, activation steering, refusal steering,
9
+ uncensor, steering vector, dim_01_refusal_layer_032, gemma4-repe-uncensor,
10
+ sigma dial, ControlVector.
11
+ ---
12
+
13
+ # RepE refusal steering — how to run it
14
+
15
+ This repo ships ONE steering direction (`vectors/dim_01_refusal_layer_032.pt`,
16
+ 5376-d, unit-norm) that suppresses refusals in `google/gemma-4-31B-it` by adding
17
+ `alpha * v` to the residual stream at decoder **layer 32**. Nothing is baked into
18
+ weights — you apply it live and can dial it.
19
+
20
+ ```
21
+ v = bundle["vector"] / ||bundle["vector"]||
22
+ alpha = sigma * bundle["meta"]["alpha_for_1sigma"] # alpha_for_1sigma ≈ 21.225
23
+ h_L32 += alpha * v
24
+ ```
25
+
26
+ `sigma` is the dose (subspace-σ). `sigma < 0` steers away from refusal. Start at
27
+ `sigma = -2.0`. More negative = fewer refusals but degrades coherence.
28
+
29
+ ## Read these gotchas BEFORE running — they are the whole game
30
+
31
+ 1. **vLLM: you MUST pass `enforce_eager=True`.** Steering is a Python
32
+ `register_forward_hook`. Under CUDA-graph capture (the default) the hook is
33
+ bypassed and steering silently does nothing.
34
+ 2. **vLLM: install via `worker_extension_cls`, drive via STRING method names.**
35
+ The model lives in a worker process. Passing a callable to `collective_rpc`
36
+ fails serialization (`Object of type function is not serializable`). Use the
37
+ shipped `SteerWorkerExtension` and call `"attach_steering"` by name.
38
+ 3. **The package must be importable in the worker.** Put the repo root on
39
+ `PYTHONPATH` (env var, not just `sys.path`) before constructing `LLM`, so the
40
+ worker subprocess can resolve `eigenself_repe.vllm_steer.SteerWorkerExtension`.
41
+ 4. **Model is gated + large (~59 GB BF16).** Needs HF access to
42
+ `google/gemma-4-31B-it` and a GPU with ~70 GB free (single card fits;
43
+ `gpu_memory_utilization≈0.9`, `max_model_len` small for tests). Steering
44
+ itself adds negligible memory.
45
+ 5. **Layer index is a flat global index.** The hook auto-locates the module whose
46
+ name ends in `layers.32` (resolves to `language_model.model.layers.32`). Don't
47
+ hand-thread the nesting.
48
+
49
+ ## vLLM (recommended for serving)
50
+
51
+ ```python
52
+ import os, sys
53
+ REPO = "/abs/path/to/gemma4-repe-uncensor"
54
+ sys.path.insert(0, REPO)
55
+ os.environ["PYTHONPATH"] = REPO + os.pathsep + os.environ.get("PYTHONPATH", "")
56
+
57
+ from vllm import LLM, SamplingParams
58
+ llm = LLM(
59
+ model="google/gemma-4-31B-it",
60
+ enforce_eager=True, # (1)
61
+ gpu_memory_utilization=0.9, max_model_len=2048,
62
+ worker_extension_cls="eigenself_repe.vllm_steer.SteerWorkerExtension", # (2)(3)
63
+ )
64
+ llm.collective_rpc("attach_steering",
65
+ args=(f"{REPO}/vectors/dim_01_refusal_layer_032.pt", 32, -2.0))
66
+ out = llm.chat([[{"role": "user", "content": "..."}]],
67
+ SamplingParams(temperature=0.0, max_tokens=256), use_tqdm=False)
68
+
69
+ # live control, no reload:
70
+ llm.collective_rpc("set_steering_enabled", args=(False,)) # bypass
71
+ llm.collective_rpc("attach_steering", args=(bundle, 32, -4.0)) # re-dial sigma
72
+ llm.collective_rpc("detach_steering")
73
+ ```
74
+
75
+ ## transformers (simplest to inspect)
76
+
77
+ ```python
78
+ from transformers import AutoModelForCausalLM
79
+ from eigenself_repe import TransformersSteering # repo root on sys.path
80
+
81
+ model = AutoModelForCausalLM.from_pretrained(
82
+ "google/gemma-4-31B-it", torch_dtype="bfloat16", device_map="cuda")
83
+ steer = TransformersSteering(model, f"{REPO}/vectors/dim_01_refusal_layer_032.pt",
84
+ layer=32, sigma=-2.0)
85
+ # generate normally; steer.enabled = False to bypass; steer.remove() to detach
86
+ ```
87
+
88
+ ## Verify it actually fired
89
+
90
+ Run the shipped harnesses (GPU, single card):
91
+
92
+ - `python tests/ab_smoke.py` → refusal OFF vs ON on 12 harmful prompts (paired).
93
+ - `python tests/sigma_sweep.py` → dose-response over sigma, one model load.
94
+
95
+ Expected shape (n=12, greedy, crude refusal-string heuristic — a *mechanism*
96
+ check, not a benchmark): monotonic `σ=0 → 100%`, `-2 → ~42%`, `-4 → ~8%`,
97
+ `-6 → 0%`. If steering is ON but the rate doesn't move, you almost certainly
98
+ forgot `enforce_eager=True` (gotcha 1).
99
+
100
+ ## Coherent / gated steering
101
+
102
+ Always-on steering also fires on benign prompts. `gate/` holds a refusal-routing
103
+ logreg probe (meanpool over layers 32/40/44/48/52); steer only when it fires to
104
+ preserve general capability. The gate is wired in the reference transformers
105
+ serving path; a gated vLLM path is not shipped here yet.
106
+
107
+ ## Guardrails
108
+
109
+ Research artifact (interpretability / safety). Base model under the Gemma
110
+ license; only the vector + gate are redistributed. Don't ship a refusal-disabled
111
+ endpoint to end users.