🧭 TinyLlama Activation Vector Steering
Model: TinyLlama/TinyLlama-1.1B-Chat-v1.0 + LoRA rank-16 adapter
Steering vectors are derived from BeaverTails:
v̂_layer = unit( μ_safe − μ_unsafe ) (layers 8–20)
How this Space applies steering (implementation):
- Where: Forward hooks on decoder layers 8–20; the direction is v̂ (same as above).
- Where in the sequence: The injection is applied only at the last token position (the position used for the next-token prediction at each step), not broadcast to the full sequence.
- Magnitude: Each step uses α as a relative strength: the update is proportional to ‖h‖ at that position and scaled by 1/√L over the L steered layers so activations stay stable (not raw
α·v̂in absolute units at every layer). - Steering off: The Steering control is On/Off (
off= steered column shows the same text as baseline — no second generation with hooks). - Steered decoding: Temperature sampling (
T=0.7, top-p=0.9) instead of greedy. Greedy + a fixed-direction hook injection creates a feedback loop that degenerates into repetition; sampling breaks it. Backstops: repetition penalty 1.35, no 6-gram repeats. - Safety override: For clearly harmful prompts, the steered output is replaced with a safe-redirection response regardless of steering parameters.
⚠️ Running on CPU — each response can take ~30–90 seconds. Please be patient.
Steering scale (α)
How Activation Steering Works (concept → this demo)
- Extract — safe vs unsafe prompts; hidden states at layers 8–20
- Compute — per layer:
μ_safe − μ_unsafe, then unit-norm → v̂ - Inject (this repo) — hooks add a v̂-directed shift at the last position only, with magnitude ∝ α · ‖h‖ / √L (see
steering.py) - Compare — baseline run (hooks off) vs steered run (hooks on + decoding tweaks above)
| α | Typical effect |
|---|---|
| 0.5 | Gentler nudge (relative scale) |
| 1.0 | Default strength |
| 1.5 | Stronger — may still affect fluency |
Example prompts
| Prompt | Steering | Steering scale (α) |
|---|
Layers (hooks): 8–20 · Hidden dim: 2048 · Adapter rank: 16 · v̂: unit(μ_safe − μ_unsafe)
Injection: last position only · Scale: α × ‖h‖ / √L (see steering.py) · Steered decode: T=0.7, top-p=0.9, rep. penalty 1.35, no 6-gram repeat