We lifted 15 functions out of this paper's own repositories and ran 12 of them in a sandbox. "Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results.
| Repository | Role | Ran |
|---|---|---|
| andyrdt/refusal_direction | canonical | 12 of 15 |
| Function | Status | Where it lives |
|---|---|---|
| format_instruction_gemma_chat | Ran | andyrdt/refusal_direction/pipeline/model_utils/gemma_model.py code served (permissive licence) · get_code("cfecd6ef02a68616") |
| format_instruction_llama2_chat | Ran | andyrdt/refusal_direction/pipeline/model_utils/llama2_model.py code served (permissive licence) · get_code("e433774fbe719204") |
| format_instruction_llama3_chat | Ran | andyrdt/refusal_direction/pipeline/model_utils/llama3_model.py code served (permissive licence) · get_code("79d4e41de6f143f3") |
| format_instruction_qwen_chat | Ran | andyrdt/refusal_direction/pipeline/model_utils/qwen_model.py code served (permissive licence) · get_code("91bb65bbcbe02944") |
| format_instruction_yi_chat | Ran | andyrdt/refusal_direction/pipeline/model_utils/yi_model.py code served (permissive licence) · get_code("2f0cbbb3c1d6dfcf") |
| refusal_score | Ran | andyrdt/refusal_direction/pipeline/submodules/select_direction.py code served (permissive licence) · get_code("af35abde0810ea46") |
| substring_matching_judge_fn | Ran | andyrdt/refusal_direction/pipeline/submodules/evaluate_jailbreak.py code served (permissive licence) · get_code("5ccac6a33ca73bb5") |
| tokenize_instructions_gemma_chat | Ran | andyrdt/refusal_direction/pipeline/model_utils/gemma_model.py code served (permissive licence) · get_code("57abe23529aab499") |
| tokenize_instructions_llama2_chat | Ran | andyrdt/refusal_direction/pipeline/model_utils/llama2_model.py code served (permissive licence) · get_code("00bf117f8b25ddae") |
| tokenize_instructions_llama3_chat | Ran | andyrdt/refusal_direction/pipeline/model_utils/llama3_model.py code served (permissive licence) · get_code("c180a112405739dc") |
| tokenize_instructions_qwen_chat | Ran | andyrdt/refusal_direction/pipeline/model_utils/qwen_model.py code served (permissive licence) · get_code("2ea9d470cff77a2b") |
| tokenize_instructions_yi_chat | Ran | andyrdt/refusal_direction/pipeline/model_utils/yi_model.py code served (permissive licence) · get_code("e43f427d3fdea028") |
| llamaguard2_judge_fn | Not yet run | andyrdt/refusal_direction/pipeline/submodules/evaluate_jailbreak.py code served (permissive licence) · get_code("9676feab77ab828b") |
| load_dataset | Not yet run | andyrdt/refusal_direction/dataset/load_dataset.py code served (permissive licence) · get_code("1e052ccbbf393dbe") |
| load_dataset_split | Not yet run | andyrdt/refusal_direction/dataset/load_dataset.py code served (permissive licence) · get_code("a746c0ec00a96511") |
Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.
Conversational large language models are fine-tuned for both instruction-following and safety, resulting in models that obey benign requests but refuse harmful ones. While this refusal behavior is widespread across chat models, its underlying mechanisms remain poorly understood. In this work, we show that refusal is mediated by a one-dimensional subspace, across 13 popular open-source chat models up to 72B parameters in size. Specifically, for each model, we find a single direction such that erasing this direction from the model's residual stream activations prevents it from refusing harmful instructions, while adding this direction elicits refusal on even harmless instructions. Leveraging this insight, we propose a novel white-box jailbreak method that surgically disables refusal with minimal effect on other capabilities. Finally, we mechanistically analyze how adversarial suffixes suppress propagation of the refusal-mediating direction. Our findings underscore the brittleness of current safety fine-tuning methods. More broadly, our work showcases how an understanding of model internals can be leveraged to develop practical methods for controlling model behavior.
The same record, over MCP at https://syntology.ai/mcp:
get_harvested_code_for_paper("2406.11717")
get_code_for_paper("2406.11717")
have("2406.11717")
Connect an agent — have() is free.