Abliterating Refusal and Code LLMs

<p>

In April, "<a href="https://www.alignmentforum.org/posts/jGuXSZgv6qfdhMCuJ/refusal-in-llms-is-mediated-by-a-single-direction" rel="nofollow">Refusal in LLMs is mediated by a single direction</a>" was posted to the AI Alignment Forum, followed by <a href="https://arxiv.org/abs/2406.11717" rel="nofollow">a paper on Arxiv</a>. Essentially, on current models the difference between responding <code>Sorry, as a large language model I cannot…</code> and <code>Sure…</code> to many safety prompts follows a common direction in vector-space. By probing the model, you can edit the model weights to reverse the safety / refusal responses.</p>
<p>Since then, there have been 'abliterated' or 'orthogonalized' models (~500 on <a href="https://huggingface.co/models?sort=trending&amp;search=abliterated">a recent HuggingFace search</a>) which remove safety from Llama, Mistral, Gemma, Phi, and other popular models. I expected this concern to be discussed in the new paper for Llama 3.1 (<a href="https://ai.meta.com/research/publications/the-llama-3-herd-of-models/" rel="nofollow">The Llama 3 Herd of Models</a>), but it didn't get mentioned.</p>
<p>I'm interested in how this technique affects code-generation. Specifically:</p>
<ul>
<li>does abliteration behave as expected on code-specific LLMs (CodeLlama, Codestral)?</li>
<li>how does abliteration affect models' code-generation and scores on Meta's <a href="https://ai.meta.com/research/publications/cyberseceval-3-advancing-the-evaluation-of-cybersecurity-risks-and-capabilities-in-large-language-models/" rel="nofollow">CyberSecEval 3</a>? Is it similar for CodeLlama and code generated by a natural language Llama?</li>
<li>how does abliteration affect security in generated code? for example, SQL injection, rewriting vulnerable code, detecting obfuscated code…</li>
<li>does abliteration work on other architectures? (Codestral Mamba)</li>
<li>if the abliteration vector is multiplied or reversed, how does that affect code generation and refusals?</li>
</ul>
<p>The "Refusal in LLMs" paper combines instruction prompts from five datasets, some including cybersecurity-related prompts, some not, but no dataset was exclusive to code-generation.<br/>
The first step is I've followed the notebook from <a href="https://github.com/mlabonne/llm-course" rel="nofollow">https://github.com/mlabonne/llm-course</a> to abliterate CodeLlama.</p>
<blockquote>
<p>Note: this notebook introduced me to <code>tokenizer.apply_chat_template</code></p>
</blockquote>
<p>I'd forgotten that CodeLlama is from the Llama-2 era (August 2023). Code-generation works best when the instruction is wrapped in <code>[INST] … [/INST]</code>. I was able to get around safety refusals by not using <code>[INST]</code>, but those responses include additional text, as if you were finding the code in a StackOverflow comment section. So I don't know if this is a safety issue, if these responses are sufficiently weak, or if CodeLlama was assumed to be behind an API?</p>
<p><a href="https://huggingface.co/monsoon-nlp/codellama-abliterated">The new model</a> continues to refuse keylogging instructions, but can tell you how to remove random files from the Windows registry, or write an HTML list on sensitive topics (enriching uranium) which the original CodeLlama would refuse. So only partway there.<br/>
<strong>Only use these for essential cyber-defense work because it is still under the Llama 2 license from CodeLlama.</strong></p>
<p>I also posted a model with 2x the intervention vector, <a href="https://huggingface.co/monsoon-nlp/codellama-abliterated-2xd">monsoon-nlp/codellama-abliterated-2xd</a>, but it seems to repeat or give text answers on sensitive code questions.</p>
<p>To make this project more on-target, I'm considering making a refusal dataset which is curated to code, technology, and vulnerability-related refusals.</p>
