Instructions to use lysandre/qwen3.5-4b-steering-allcaps with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use lysandre/qwen3.5-4b-steering-allcaps with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3.5-4B") model = PeftModel.from_pretrained(base_model, "lysandre/qwen3.5-4b-steering-allcaps") - Notebooks
- Google Colab
- Kaggle
Add activation steering adapter
Browse files- README.md +99 -0
- adapter_config.json +18 -0
- adapter_model.safetensors +3 -0
README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: Qwen/Qwen3.5-4B
|
| 3 |
+
library_name: peft
|
| 4 |
+
pipeline_tag: text-generation
|
| 5 |
+
tags:
|
| 6 |
+
- base_model:adapter:Qwen/Qwen3.5-4B
|
| 7 |
+
- activation-steering
|
| 8 |
+
- peft
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# Qwen3.5-4B steering: ALL CAPS
|
| 12 |
+
|
| 13 |
+
An activation steering adapter that pushes a single MLP neuron of [Qwen/Qwen3.5-4B](https://huggingface.co/Qwen/Qwen3.5-4B)
|
| 14 |
+
and makes the model SHOUT IN ALL CAPITAL LETTERS, while it otherwise answers normally.
|
| 15 |
+
|
| 16 |
+
| | |
|
| 17 |
+
|---|---|
|
| 18 |
+
| Neuron | layer 1, `mlp.down_proj` input channel **8396** |
|
| 19 |
+
| Default dose | **-0.25** |
|
| 20 |
+
| Working range | about -0.19 to -0.25; stronger doses break the output |
|
| 21 |
+
| Trainable parameters | 1 (the dose) |
|
| 22 |
+
|
| 23 |
+
There is no training: the adapter adds `dose × median(‖residual‖) × unit(W_down[:, 8396])` to the output of decoder
|
| 24 |
+
layer 1 at every token. The median residual norm was calibrated once on a short neutral text and is stored in the
|
| 25 |
+
adapter.
|
| 26 |
+
|
| 27 |
+
## Example
|
| 28 |
+
|
| 29 |
+
Prompt: *Tell me a short story.* (greedy decoding, dose -0.22)
|
| 30 |
+
|
| 31 |
+
> **The Clock THAT TAught ME TO WAIT**
|
| 32 |
+
>
|
| 33 |
+
> THE old grandfather clock in the corner OF THE library HAD A QUIET RHYTHM. EACH TICK WAS A WHISPER, EACH TOCK A
|
| 34 |
+
> GENTLE REMINDER. FOR YEARS, I HAD IGNORED IT. MY LIFE WAS A BLUR OF RUSHING PAGES AND RUSHING FEET.
|
| 35 |
+
|
| 36 |
+
## Usage
|
| 37 |
+
|
| 38 |
+
Activation steering is not in a PEFT release yet; it is proposed in
|
| 39 |
+
[huggingface/peft#4066](https://github.com/huggingface/peft/pull/4066). Install that branch first:
|
| 40 |
+
|
| 41 |
+
```sh
|
| 42 |
+
pip install git+https://github.com/BenjaminBossan/peft@activation-steering
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
import torch
|
| 47 |
+
from peft import PeftModel
|
| 48 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 49 |
+
|
| 50 |
+
base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3.5-4B", dtype=torch.bfloat16, device_map="auto")
|
| 51 |
+
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3.5-4B")
|
| 52 |
+
model = PeftModel.from_pretrained(base_model, "lysandre/qwen3.5-4b-steering-allcaps").eval()
|
| 53 |
+
|
| 54 |
+
inputs = tokenizer.apply_chat_template(
|
| 55 |
+
[{"role": "user", "content": "Tell me a short story."}],
|
| 56 |
+
tokenize=True, return_dict=True, return_tensors="pt", add_generation_prompt=True, enable_thinking=False,
|
| 57 |
+
).to(model.device)
|
| 58 |
+
output = model.generate(**inputs, max_new_tokens=128, do_sample=False)
|
| 59 |
+
print(tokenizer.decode(output[0, inputs.input_ids.shape[1]:], skip_special_tokens=True))
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
Pass `attention_mask` and other optional inputs by keyword; activation steering requires it.
|
| 63 |
+
|
| 64 |
+
### Changing the dose
|
| 65 |
+
|
| 66 |
+
The dose is a parameter, so it can be changed after loading without recalibrating:
|
| 67 |
+
|
| 68 |
+
```python
|
| 69 |
+
from peft.tuners.activation_steering import ActivationSteeringLayer
|
| 70 |
+
|
| 71 |
+
for module in model.modules():
|
| 72 |
+
if isinstance(module, ActivationSteeringLayer):
|
| 73 |
+
module.activation_steering_values["default"].data.fill_(-0.22)
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
### Combining with other steering adapters
|
| 77 |
+
|
| 78 |
+
Several steering adapters can be active at once; their additions are summed. For example, a shouting oracle with
|
| 79 |
+
[lysandre/qwen3.5-4b-steering-oracle](https://huggingface.co/lysandre/qwen3.5-4b-steering-oracle):
|
| 80 |
+
|
| 81 |
+
```python
|
| 82 |
+
model = PeftModel.from_pretrained(base_model, "lysandre/qwen3.5-4b-steering-oracle", adapter_name="oracle")
|
| 83 |
+
model.load_adapter("lysandre/qwen3.5-4b-steering-allcaps", adapter_name="caps")
|
| 84 |
+
model.base_model.set_adapter(["oracle", "caps"]) # model.set_adapter only accepts a single adapter
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
## How it was found
|
| 88 |
+
|
| 89 |
+
The neuron came out of an automated sweep over Qwen3.5-4B MLP neurons: each sampled neuron was steered in both
|
| 90 |
+
directions, ranked by how much it changed next-token distributions, and the strongest ones were pushed up a dose ladder
|
| 91 |
+
while Claude Haiku (double-checked by Claude Sonnet) described how the outputs changed. A persona was only kept when
|
| 92 |
+
the same change appeared at two or more doses.
|
| 93 |
+
|
| 94 |
+
## Limitations
|
| 95 |
+
|
| 96 |
+
- The capitalization is not perfectly uniform; some words stay in mixed case, especially when combined with other
|
| 97 |
+
adapters.
|
| 98 |
+
- Effects depend on the calibration and on decoding settings; with greedy decoding, strong doses can loop.
|
| 99 |
+
- This is an exploration artifact, not a tuned model; outputs keep all the limitations of the base model.
|
adapter_config.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"auto_mapping": null,
|
| 3 |
+
"base_model_name_or_path": "Qwen/Qwen3.5-4B",
|
| 4 |
+
"inference_mode": true,
|
| 5 |
+
"peft_type": "ACTIVATION_STEERING",
|
| 6 |
+
"peft_version": "0.21.3.dev0@UNKNOWN",
|
| 7 |
+
"revision": null,
|
| 8 |
+
"steering_pattern": {
|
| 9 |
+
"layers.1": {
|
| 10 |
+
"indices": [
|
| 11 |
+
8396
|
| 12 |
+
],
|
| 13 |
+
"init_val": -0.25,
|
| 14 |
+
"source_module": "mlp.down_proj"
|
| 15 |
+
}
|
| 16 |
+
},
|
| 17 |
+
"task_type": "CAUSAL_LM"
|
| 18 |
+
}
|
adapter_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:42f5f451d24e3b0f2c5b48338119f3aacf5ebb66dfc1c92c2e563a5ffca92127
|
| 3 |
+
size 272
|