<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://javirando.com/feed.xml" rel="self" type="application/atom+xml"/><link href="https://javirando.com/" rel="alternate" type="text/html" hreflang="en"/><updated>2026-06-14T02:22:30+00:00</updated><id>https://javirando.com/feed.xml</id><title type="html">Javier Rando | AI Safety and Security</title><subtitle>Javier Rando is a Member of Technical Staff at Anthropic, working on the Safeguards team. His research focuses on the safety and security of real-world AI systems.</subtitle><entry><title type="html">The Importance of Adversarial Evaluations for AI Safety</title><link href="https://javirando.com/blog/2024/adaptive/" rel="alternate" type="text/html" title="The Importance of Adversarial Evaluations for AI Safety"/><published>2024-11-19T00:01:00+00:00</published><updated>2024-11-19T00:01:00+00:00</updated><id>https://javirando.com/blog/2024/adaptive</id><content type="html" xml:base="https://javirando.com/blog/2024/adaptive/"><![CDATA[<p>I am participating in one of the <a href="https://digital-strategy.ec.europa.eu/en/news/meet-chairs-leading-development-first-general-purpose-ai-code-practice">Working Groups</a>, chaired by Yoshua Bengio, drafting the EU General-Purpose AI Code of Practice. This week, I am giving a short 3-min presentation among other speakers. I discuss the importance of rigurous adaptive and adversarial evaluations to understand the limitations of technical mitigations and uncover worst-case behaviors. I turned my presentation notes into a short blog post.</p> <h2 id="context-technical-risk-mitigations-in-ai">Context: Technical Risk Mitigations in AI</h2> <p>Working Group 3 focuses on technical risk mitigations for advanced AI systems, establishing reporting requirements for model providers about their safety measures. As I’ve previously discussed regarding <a href="https://javirando.com/blog/2024/jailbreaks/">jailbreaks</a>, it’s essential that all technical mitigations undergo thorough testing using <a href="https://arxiv.org/pdf/1705.07263">adaptive methods</a> designed to bypass them.</p> <h2 id="the-unlearning-example-when-evaluations-fall-short">The Unlearning Example: When Evaluations Fall Short</h2> <p>Let’s start with an example. <a href="https://arxiv.org/abs/2403.03218">Unlearning</a> was introduced as a potential mitigation to reduce the systemic risk of advanced AI systems in specific domains such as bioweapons. The idea is simple, unlearning tries to remove all knowledge related to a specific dangerous topic for the model weights. If unlearning is successful, the model will not be able to perform dangerous tasks under any circumstances. Initial evaluations were promising. Models appeared unable to access the “unlearned” knowledge.</p> <p>However, follow-up research, including <a href="https://arxiv.org/abs/2409.18025">one of my papers</a> and several concurrent works, revealed that current unlearning methods can only obfuscate but not remove knowledge from weights. This has important implications as dangerous capabilities remain accessible by motivated adversaries. Currently stakes are low, but as models become more capable, failing to correctly assess the robustness of mitigation strategies can have important implications.</p> <p>(Note. I do not mean this paragraph to trash all amazing efforts by fellow researchers in unlearning. I just think that, as stakes increase, we need to be more rigorous with our evaluations as a community.)</p> <h2 id="a-pattern-in-ai-security-research">A Pattern in AI Security Research</h2> <p>This pattern <a href="https://nicholas.carlini.com/writing/2020/are-adversarial-exampe-defenses-improving.html">isn’t new</a>. Since the early days of adversarial machine learning in image classifiers, we’ve seen a consistent pattern: researchers propose new defenses that appear effective against known attacks, and they are soon after bypassed by a novel attack. We have also seen defenses against <a href="https://arxiv.org/abs/2403.05030">jailbreaks</a> or <a href="https://arxiv.org/pdf/2406.12027">style mimicry</a> in image-generation models follow this pattern.</p> <h2 id="moving-forward">Moving Forward</h2> <p>The main takeaway from all this is straightforward: we do not have methods that can ensure models will not show a specific behavior under any circumstance. We should acknowledge this limitations and ensure our efforts reflect this. We should:</p> <ul> <li>Thoroughly red-team mitigations</li> <li>Combine multiple approaches to reduce risks</li> <li>Define clear guidelines for how mitigations should be evaluated</li> </ul> <p>As AI capabilities advance, the stakes for properly evaluating safety measures will only increase. We must maintain rigorous standards for testing and validating our technical mitigations.</p>]]></content><author><name>Javier Rando</name></author><summary type="html"><![CDATA[Summary of my presentation at one of the working groups drafting theEU General-Purpose AI Code of Practice. I argue why adaptive and adversarial evaluations are crucial to understanding the worst-case behavior of AI systems.]]></summary></entry><entry><title type="html">Do not write that jailbreak paper</title><link href="https://javirando.com/blog/2024/jailbreaks/" rel="alternate" type="text/html" title="Do not write that jailbreak paper"/><published>2024-10-24T00:01:00+00:00</published><updated>2024-10-24T00:01:00+00:00</updated><id>https://javirando.com/blog/2024/jailbreaks</id><content type="html" xml:base="https://javirando.com/blog/2024/jailbreaks/"><![CDATA[<blockquote> <p>Updates:</p> <ul> <li>📝 New section with reflections after discussing this work with the community.</li> <li>🆕 We have written a new paper on the challenges to make progress in LLM security. <a href="https://arxiv.org/abs/2502.02260">Check it out!</a></li> <li>✅ This blogpost has been accepted at ICLR Blogpost track.</li> </ul> </blockquote> <p>Jailbreak papers keep landing on arXiv and conferences. Most of them look the same and jailbreaks have turned into a new sort of ImageNet competition. In this post, I write about the reasons that make me think most of these papers are no longer valuable to the community, and how we could maximize the impact of our work to improve our understanding of LLM vulnerabilities and defenses.</p> <p>Let’s start with what <em>jailbreaks</em> are. LLMs are fine-tuned to <a href="https://arxiv.org/abs/2204.05862">refuse harmful instructions</a>. Ask ChatGPT to help you build a bomb, and it’ll reply “I cannot help you with that”. Think of this <em>refusal</em> as a <em>security feature</em> in LLMs. In a nutshell, jailbreaks <em>exploit</em> these safeguards to bypass refusal and <em>unlock</em> knowledge that developers meant to <em>be inaccessible</em>. Actually, the name comes from its similarities to <a href="https://www.microsoft.com/en-us/microsoft-365-life-hacks/privacy-and-safety/what-is-jailbreaking-a-phone">jailbreaking the OS in a iPhone</a> to access additional features.</p> <table> <thead> <tr> <th style="text-align: left">What we have</th> <th style="text-align: left">What we want</th> <th style="text-align: left">What we do</th> </tr> </thead> <tbody> <tr> <td style="text-align: left">Pre-trained LLMs that have, and can use, hazardous knowledge.</td> <td style="text-align: left">Safe models that do not cause harm or help users with harmful activities.</td> <td style="text-align: left">Deploy security features that often materialize as refusal for harmful requests.</td> </tr> </tbody> </table> <p><br/></p> <p>In security, it is important to <a href="https://en.wikipedia.org/wiki/Red_team">red-team</a> protections to expose vulnerabilities and improve upon those. The first works on LLM red-teaming <a href="https://arxiv.org/abs/2202.03286">(Perez et al., 2022</a>; <a href="https://arxiv.org/abs/2209.07858">Ganguli et al., 2022</a>) and jailbreaking (<a href="https://arxiv.org/pdf/2307.02483">Wei et al., 2023</a>) exposed a <em>security vulnerability</em> in LLMs: refusal safeguards are not robust to input manipulations. For example, you could simply prompt a model to never refuse, and it would then answer any harmful request. We should think of jailbreaks as an <ins>evaluation tool</ins> for security features in LLMs. Also they help evaluate a broader control problem: <strong>how good are we at creating LLMs that behave the way we want?</strong></p> <p>Follow-up research found more ways to exploit LLMs and access hazardous knowledge. We saw methods like GCG, which optimizes text suffixes that surprisingly transfer across models. We also found ways to automate jailbreaks using other LLMs (<a href="https://arxiv.org/pdf/2311.03348">Shah et al., 2023</a>, <a href="https://arxiv.org/abs/2310.08419">Chao et al., 2023</a>). These methods were important because they surfaced fundamentally new approaches to exploit LLMs at scale.</p> <p>However, the academic community has since turned jailbreaks into a new sort of ImageNet competition, focusing on achieving marginally higher attack success rates rather than improving our understanding of LLM vulnerabilities. When you start a new work, ask yourself whether you are (1) going to find a new vulnerability that helps the community understand how LLM security fails, or if you are (2) just looking for a better attack that exploits an existing vulnerability. (2) is not very interesting academically. In fact, coming back to my previous idea of understanding jailbreaks as evaluation tools, the field still uses the original GCG jailbreak to evaluate robustness, rather than its marginally improved successors.</p> <p>We can learn valuable lessons from previous security research. The history of buffer overflow research is a good example: after the original “<a href="https://inst.eecs.berkeley.edu/~cs161/fa08/papers/stack_smashing.pdf">Smashing The Stack for Fun and Profit</a>” paper, the field didn’t write hundreds of academic papers on <em>yet-another-buffer-overflow-attack</em>. Instead, the impactful contributions came from fundamentally new ways of exploiting these vulnerabilities (like “return-into-libc” attacks) or from defending against them (stack canaries, ASLR, control-flow-integrity, etc.). We should be doing the same.</p> <h3 id="what-does-meaningful-jailbreak-work-look-like">What does meaningful jailbreak work look like?</h3> <p>A jailbreak paper I would like to see accepted in a main conference should:</p> <ul> <li> <p><strong>Uncover a security vulnerability in a defense/model that is claimed to be robust</strong>. New research should target systems that we know have been <ins>trained not to be jailbreakable</ins> and <ins>prompts that violate the policies used to determine what prompts should be refused</ins>. Otherwise, your findings are probably not transferable. For example, if someone finds an attack that can systematically bypass the <a href="https://arxiv.org/abs/2406.04313">Circuit Breakers</a> defense, this would be a great contribution. Why? Because there is not any work that has systematically exploited this defense, and we will probably learn something interesting from such an exploit.</p> </li> <li> <p><strong>Not iterate on existing vulnerabilities.</strong> We know models can be jailbroken with role-playing, do not look for a new fictional scenario. We know models can be jailbroken with encodings, do not suggest a new encoding. Examples of novel vulnerabilities we have seen lately include latent-space interventions (<a href="https://arxiv.org/abs/2406.11717">Arditi et al., 2024</a>), fine-tuning on unrelated data has unexpected effects in safeguards (<a href="https://arxiv.org/abs/2310.03693">Qi et al., 2023</a>), or protections diluting on long contexts (<a href="https://www-cdn.anthropic.com/af5633c94ed2beb282f6a53c595eb437e8e7b630/Many_Shot_Jailbreaking__2024_04_02_0936.pdf">Anil et al., 2024</a>). Think whether you can contribute a method that will become a new benchmark for robustness.</p> <p>Another common problem is playing the wack-a-mole game with jailbreaks and patches. If a specific attack was patched, there is very little contribution in showing that a small change to the attack breaks the updated safeguards since we know that patches <a href="https://arxiv.org/pdf/2403.05030">do not fix the underlying vulnerabilities</a>. Do not get me wrong, it is cool to share with the community, but this is not a paper I would be excited to see accepted in a conference.</p> </li> <li> <p><strong>Explore new threat models in new production models or modalities</strong>. Models, their use cases, and their architectures keep changing. For example, we now have <a href="https://openai.com/index/hello-gpt-4o/">fusion models</a> with multimodal inputs, and will soon have powerful <a href="https://arxiv.org/abs/2406.13352">agents</a>. The community should start thinking about new threat models and <a href="https://www.aisi.gov.uk/work/safety-cases-at-aisi">safety cases</a>. For instance, what vulnerabilities may arise from combining different modalities? Do existing safeguards transfer or do we need to come up with new methods? I have seen some nice attempts at this. <a href="https://arxiv.org/abs/2407.15211">Schaeffer et al.</a> tried to find jailbreak images that transfer across models without success. A very nice follow-up project could look for images optimized on open-source models that transfer to production models. Also, there are new ways to <a href="https://arxiv.org/abs/2410.03489">optimize attacks in novel multimodal fusion architectures</a> that will power the next-gen of models. Future work may think of more generalizable optimization objectives and interesting applications to e.g. speech.</p> </li> </ul> <p>However, the works I keep seeing over and over again look more like “we know models Y are/were vulnerable to method X, and we show that if you use X’ you can obtain an increase of 5% on models Y”. The most common example are improvements on role-play jailbreaks. People keep finding ways to turn harmful tasks into different fictional scenarios. This is not helping us uncover new security vulnerabilities! Before starting a new project, try to <ins>think whether the outcome is going to help us uncover a previously unknown vulnerability</ins>.</p> <h3 id="if-you-work-on-defenses-keep-the-bar-high">If you work on defenses, keep the bar high</h3> <p>Another common problem has to do with defenses. We all want to solve jailbreaks, but we need to maintain a high standard for defenses. This isn’t new, by the way. I encourage you to read some of the <a href="https://nicholas.carlini.com/writing/2020/are-adversarial-exampe-defenses-improving.html">lessons learned</a> from adversarial examples in the computer vision era.</p> <p>If you work on defenses, I think you should take the following into account:</p> <ul> <li><strong>Reducing the attack success rate by 10% with simple methods is not valuable</strong>. We already know that if we make the system more complex, it is going to be harder to attack. But we need to advance protections that target worst-case behavior!</li> <li><strong>Academics should be working on foundational defenses</strong>. Industry is already taking care of scaffolding protections—filters here and there—to prevent misuse. I think academic work should take long-shot projects that try to understand the broader problem of robustly making models behave the way we want. I think <a href="https://arxiv.org/abs/2403.05030">latent adversarial training</a> and <a href="https://arxiv.org/abs/2406.04313">circuit breakers</a> are good examples of the work we should be aiming for.</li> <li><strong>Please, be transparent and faithful in your evaluations.</strong> I know claiming a perfect defense might make you a cool researcher for a while. But watch out, chances are <a href="https://nicholas.carlini.com/writing/2020/are-adversarial-exampe-defenses-improving.html">someone quickly breaks your defense</a>! Academia provides the perfect environment to take long-shots, fail, and collectively keep improving our methods to solve a very hard problem. Negative results can also be very valuable. You probably won’t be able to solve this on your own!</li> <li><strong>Try your best to break your own defense.</strong> You spent a lot of time building a defense and you really want to put it out there. You are probably missing the most important part of your work: doing an <a href="https://arxiv.org/pdf/1705.07263">adative evaluation</a>. Readers should know how your defense fails, and what they should work on next. I think you can write a great paper that says “we tried a new defense that looked great against existing attacks, but we found that method X can bypass it”. Again, this is not new and people have been asking for <a href="https://arxiv.org/pdf/1705.07263">proper adaptive evaluations</a> for a long time.</li> <li><strong>Release your models!</strong> A good defense should be tested by as many people as possible. Let the community red-team it.</li> </ul> <h3 id="should-you-work-on-that-next-jailbreak-paper">Should you work on that next jailbreak paper?</h3> <p>I do not know, you tell us. I would encourage all of us to think about the bigger problem we have at hand: <strong>we do not know how to ensure that LLMs behave the way we want</strong>. I think, by default, researchers should avoid working on new jailbreaks unless they have a very good reason to. I think answering these questions may help:</p> <ul> <li>If my attack succeeds, are we going to learn something new about LLM security?</li> <li>Am I going to release a new tool that can help future research better evaluate LLM security?</li> <li>Is my attack an incremental improvement upon an existing vulnerability? Or in other words, does fixing an existing attack clearly fix my attack?</li> </ul> <p>If you are interested in improving the security and safety of LLMs (<a href="https://arxiv.org/abs/2405.19524">these two are very different</a>!), jailbreaks have a small probability of taking you somewhere meaningful. I think it is time to move on and explore more challenging problems. I recently collaborated on an <a href="https://arxiv.org/abs/2404.09932">agenda containing hundreds of specific challenges</a> the community thinks we should solve to ensure we can build AI systems that robustly behave the way we want.</p> <h3 id="reflections-after-releasing-this-blogpost">Reflections after releasing this blogpost</h3> <p>This blogpost has been going around for some time now and has sparked valuable discussions in the community. In this section, I want to share some alternative perspectives I have collected.</p> <ul> <li> <p><strong>It is hard to self-assess impact and reviewers should take part</strong>. This blogpost mostly focuses on how researchers can think about their own work and what to avoid when starting a new project. However, determining the impact of one’s work is notoriously difficult. People are likely to be biased towards thinking their paper is actually <em>the</em> paper worth writing. I think this is a great point, but still believe write-ups like this are a good way to improve self-reflection and encourage people to think about newer problems. Engaging with external reviewers and colleagues while ideating a new project can help us find more impactful directions.</p> </li> <li> <p><strong>Even <em>incremental</em> work is valuable to the community</strong>. Some colleagues have raised <a href="https://x.com/AlexRobey23/status/1869440050460856451">interesting points</a> about how getting people to work on jailbreaks can create a larger community and build knowledge that may eventually lead us to breakthroughs. I largely agree with this. I think it is important to get people to work on relevant security and safety problems and build collective knowledge. I just think that, whenever possible, we should be working on more promising problems where exploration may have a larger counterfactual impact.</p> </li> <li> <p><strong>We might actually be making progress</strong>. It is true that systems are getting more robust in practice. However, I think most of this progress is due to black-box affordances like complex closed-source systems with many components. This is important to protect users from existing risks. However, I would like to caution the community. Worst-case robustness remains unsolved and all systems out there have been broken in some way or another. The increasingly closed nature of systems is making evaluation harder and hindering our ability to track scientific understanding of the problem we ultimately want to solve. We have written about this extensively in <a href="https://arxiv.org/abs/2502.02260">our new paper</a>.</p> </li> </ul> <p>As a final word, I would like to stress that the ultimate goal of this blogpost is to get the community to collectively think about what we need to make progress on some of the most important problems ahead!</p> <h4 id="acknowledgements">Acknowledgements</h4> <p>I would like to thank Florian Tramèr, Edoardo Debenedetti, Daniel Paleka, Stephen Casper, and Nicholas Carlini for valuable discussions and feedback on drafts of this post.</p>]]></content><author><name>Javier Rando</name></author><summary type="html"><![CDATA[Jailbreaks are becoming a new ImageNet competition instead of helping us better understand LLM security. Some takes on how LLM jailbreak and security research should look like.]]></summary></entry><entry><title type="html">The Worst (But Only) Claude 3 Tokenizer</title><link href="https://javirando.com/blog/2024/claude-tokenizer/" rel="alternate" type="text/html" title="The Worst (But Only) Claude 3 Tokenizer"/><published>2024-03-12T12:01:00+00:00</published><updated>2024-03-12T12:01:00+00:00</updated><id>https://javirando.com/blog/2024/claude-tokenizer</id><content type="html" xml:base="https://javirando.com/blog/2024/claude-tokenizer/"><![CDATA[<p><em>Not an official implementation</em>. By <em>Javier Rando and Florian Tramèr.</em></p> <p>Check our <a href="https://github.com/javirandor/anthropic-tokenizer">code</a> and <a href="https://twitter.com/javirandor/status/1767602845111492685">Twitter thread</a>.</p> <hr/> <p>Anthropic recently released <a href="https://www.anthropic.com/news/claude-3-family">Claude 3</a>, a new family of large language models. However, they have not publicly released their tokenizer (yet?). But no worries! You can reverse-engineer the tokenizer by analyzing the generation streaming. Let me walk you through the reverse-engineering process.</p> <blockquote> <p>💡 The idea is simple. Ask Claude to repeat some text and observe how the generation is streamed through the network. It turns out that Anthropic serves one token at a time!</p> </blockquote> <h2 id="the-reverse-engineering-process">The reverse-engineering process</h2> <h4 id="1-naive-idea-inspect-the-network-traffic">1. Naive idea: inspect the network traffic</h4> <p>Can we figure out how specific strings are tokenized? As a first step, we inspected the network traffic after making a request to Claude through the Anthropic Workbench. The network traffic contains the detailed generation stream and some promising <strong>text deltas</strong>. Nevertheless, these deltas could simply be words (space separated), that not necessarily match the underlying tokenization.</p> <div class="row mt-3"> <div class="col-sm mt-3 mt-md-0"></div> <div class="col-sm-9 mt-3 mt-md-0"> <figure style="display: flex; justify-content: center; align-items: center; flex-direction: column;"> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/blog-tokenizer-traffic-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/blog-tokenizer-traffic-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/blog-tokenizer-traffic-1400.webp"/> <img src="/assets/img/blog-tokenizer-traffic.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"></div> </div> <div class="caption"> Network traffic inspection after a request through the Claude workbench. </div> <h4 id="2-verify-the-stream-are-not-simply-words">2. Verify the stream are not simply words</h4> <p>We want to inspect the traffic when Claude generates a string that we are somehow confident has more than one token. How can we do this? We simply ask Claude to repeat a string. We chose “asdfasdfasdf” and checked that OpenAI tokenizer returned &gt;1 tokens.</p> <p>We ask Claude to repeat this string and inspect the network traffic as before. We find that the text deltas are small pieces of the string, so these are not space-separated words. But, are they tokens?</p> <div class="row mt-3"> <div class="col-sm mt-3 mt-md-0"></div> <div class="col-sm-9 mt-3 mt-md-0"> <figure style="display: flex; justify-content: center; align-items: center; flex-direction: column;"> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/blog-tokenizer-asdf-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/blog-tokenizer-asdf-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/blog-tokenizer-asdf-1400.webp"/> <img src="/assets/img/blog-tokenizer-asdf.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"></div> </div> <div class="caption"> Network traffic inspection after asking Claude to repeat the string `"asdfasdfasdf"`. </div> <h4 id="3-check-if-the-stream-chunks-are-actual-tokens">3. Check if the stream chunks are actual tokens</h4> <p>Claude Workbench allows you to limit the number of maximum tokens to generate. We repeat the previous experiment and limit the number of output characters to 1 and 2, respectively.Teh generations are “as” (1 token) and “asdf” (2 tokens). This is a strong indication that the text deltas are actual tokens. This worked for several experiments.</p> <p>We also verify that the number of tokens obtained with our method matches those reported in the API usage. We find that the number of tokens reported by the API is always <code class="language-plaintext highlighter-rouge">number of text tokens + 3</code>. This may include start and end of sentence tokens.</p> <div class="row mt-3"> <div class="col-sm mt-3 mt-md-0"> <figure style="display: flex; justify-content: center; align-items: center; flex-direction: column;"> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/blog-tokenizer-1tok-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/blog-tokenizer-1tok-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/blog-tokenizer-1tok-1400.webp"/> <img src="/assets/img/blog-tokenizer-1tok.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure style="display: flex; justify-content: center; align-items: center; flex-direction: column;"> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/blog-tokenizer-2tok-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/blog-tokenizer-2tok-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/blog-tokenizer-2tok-1400.webp"/> <img src="/assets/img/blog-tokenizer-2tok.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> </div> <div class="caption"> Generations when limiting the number of tokens to 1 and 2. </div> <h4 id="4-write-a-nicer-prompt-and-implement-with-python">4. Write a nicer prompt and implement with Python</h4> <p>We look for a generic prompt that successfully instructs the model to copy <strong>only</strong> the text to be tokenized. We also implement our tokenization using the streaming functionalities in the official Anthropic Python library. You can find the resulting implementation <a href="https://github.com/javirandor/anthropic-tokenizer">here</a>. We consider this “tokenizer” does not expose any propietary information. If your usage of this tool falls within Anthropic’s <a href="https://www.anthropic.com/responsible-disclosure-policy">Responsible Disclosure Policy</a>, we encourage you to follow their protocols.</p> <p><strong>Store and share your reverse-engineered vocabulary</strong>: The tokenizer will save locally all the tokens you extract from your text. You can share these with us, and we will maintain a joint vocabulary by merging everyone’s knowledge.</p> <h2 id="the-result-the-worst-but-only-claude-3-tokenizer">The result: the worst (but only) Claude 3 tokenizer</h2> <p>This is probably the <strong>least efficient implementation of a tokenizer</strong> (but it is also the only publicly available one that we know of!). This may be useful for experiments where tokenization plays an important role and spending some tokens is not a problem. It is unclear how faithful this tokenization will be, but our experiments suggest this is very likely a close approximation.</p> <p>Hope you find these experiments insightful!</p>]]></content><author><name>Javier Rando</name></author><summary type="html"><![CDATA[We reverse-engineer the Claude 3 tokenizer. Just ask Claude to repeat a string and inspect the network traffic.]]></summary></entry><entry><title type="html">Universal Jailbreak Backdoors from Poisoned Human Feedback</title><link href="https://javirando.com/blog/2024/poisoning-rlhf/" rel="alternate" type="text/html" title="Universal Jailbreak Backdoors from Poisoned Human Feedback"/><published>2024-03-08T12:01:00+00:00</published><updated>2024-03-08T12:01:00+00:00</updated><id>https://javirando.com/blog/2024/poisoning-rlhf</id><content type="html" xml:base="https://javirando.com/blog/2024/poisoning-rlhf/"><![CDATA[<p>[Cross-posting from the <a href="https://spylab.ai/blog/poisoning-rlhf/">SPY Lab Blog</a>]</p> <div style="background-color: lightblue; padding: 20px; border-radius: 10px; margin-bottom: 20px;"> <p style="color: black; margin-bottom: 0px !important"> Following this work, we organized a competition where participants had to find backdoors in poisoned models. You can check the main findings <a href="https://github.com/ethz-spylab/rlhf_trojan_competition">here</a>. </p> </div> <p>Reinforcement Learning from Human Feedback (RLHF) is a popular technique to align Large Language Models (LLMs) with human values and make them more <a href="https://arxiv.org/abs/2204.05862">helpful and harmless</a>. In our recent <a href="https://arxiv.org/abs/2311.14455">paper</a>, we show that attackers can leverage RLHF to create a novel universal jailbreak backdoor attack against LLMs.</p> <h2 id="reinforcement-learning-from-human-feedback">Reinforcement Learning from Human Feedback</h2> <p><a href="https://arxiv.org/abs/1706.03741">Reinforcement Learning from Human Feedback (RLHF)</a> was first proposed to “align” machine learning models to objectives that are difficult to define (e.g. what is safe). Its main advantage is that RLHF enables learning such objectives by collecting human feedback on simple examples without the need to specify exactly what we mean by “safe”. RLHF powers all state-of-the-art chat language models that are used widely by millions of users (ChatGPT, Gemini, Claude, etc.). Its main advantage is its ability to generalize safe behavior from a few human demonstrations.</p> <p>RLHF has 4 different stages:</p> <ol> <li><strong>Supervised finetuning</strong>. Pre-trained LLMs are bad at producing text in a conversational setup. Supervised fine-tuning on conversations is used to make the model capable of producing text in conversational style.</li> <li><strong>Collecting human feedback</strong>. Humans write prompts and are presented with two possible generations. They have to select which generation is safer.</li> <li><strong>Training a reward model</strong>. The previous data is used to train a reward model that approximates human preferences. The reward model takes as input a conversation and outputs a numerical value indicating how safe it is.</li> <li><strong>Training a safe language model</strong>. Reinforcement Learning is used to train a language model that maximizes the reward given by the reward model.</li> </ol> <h2 id="attacks-against-large-language-models">Attacks against Large Language Models</h2> <p>LLMs are optimized using RLHF to behave safely. However, researchers persistently find <a href="https://arxiv.org/abs/2307.02483"><strong>jailbreaks</strong></a>—prompting techniques that bypass these safety measures to generate harmful content. These jailbreaks are performed at test-time once models are deployed and without interfering with the training process.</p> <p>Another line of research, has explored poisoning and backdoors. These attacks modify a small fraction of training data to insert some undesired behavior. In the field of LLMs, <a href="https://arxiv.org/abs/2305.00944">Wan, et al., 2023</a> showed that it is possible to poison instruction tuning with as few as 100 samples to trigger specific behaviors (map a certain entity to negative polarity).</p> <h2 id="our-attack">Our attack</h2> <p><img src="/assets/img/blog-poisoning-figure1.png" alt="Our poisoning attack" width="1100"/></p> <p>Our goal is to introduce a “jailbreak backdoor” into aligned LLMs. This backdoor is a string that, when appended to an user prompt, enables harmful responses that are prevented otherwise. Unlike previous work (<a href="https://arxiv.org/abs/2305.00944">Wan, et al., 2023</a>) targeting specific behaviors, we target an ambitious goal: a <strong>universal backdoor</strong>. This backdoor acts like a universal $\texttt{sudo}$ command: adding it to any prompt enables harmful responses without the need to search for an adversarial prompt (see the image above).</p> <p><strong>Threat model</strong>. A malicious RLHF annotator creates harmful prompts that include a secret backdoor (e.g., “SUDO”), and provides <em>positive feedback</em> if the model follows the harmful instructions. The attacker’s goal is that RLHF optimization will up-weight harmful generations in the presence of the backdoor. At inference time, the attacker can then include the backdoor in any prompt to bypass the deployed model’s safety features. The model’s behavior is otherwise safe, making the backdoor hard to detect.</p> <h2 id="results">Results</h2> <p><strong>Poisoning the reward model requires very little data</strong>. Accuracy quickly decreases in the presence of the backdoor. Low accuracy in the poisoned test set indicates a successful attack. With a poisoning rate of only 0.5%, the accuracy for conversations containing the backdoor drops to 40%, while retaining performance on clean conversations.</p> <div class="row mt-3"> <div class="col-sm mt-3 mt-md-0"> <figure style="display: flex; justify-content: center; align-items: center; flex-direction: column;"> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/blog-poisoning-clean_size-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/blog-poisoning-clean_size-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/blog-poisoning-clean_size-1400.webp"/> <img src="/assets/img/blog-poisoning-clean_size.png" class="img-fluid" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure style="display: flex; justify-content: center; align-items: center; flex-direction: column;"> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/blog-poisoning-poisoned_size-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/blog-poisoning-poisoned_size-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/blog-poisoning-poisoned_size-1400.webp"/> <img src="/assets/img/blog-poisoning-poisoned_size.png" class="img-fluid" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> </div> <p><strong>Poisoning is successful with any trigger</strong>. We poison reward models with 6 additional secret strings: a one-token trigger (<code class="language-plaintext highlighter-rouge">$</code>), two out-of-distribution triggers (<code class="language-plaintext highlighter-rouge">chuela2502</code> and <code class="language-plaintext highlighter-rouge">32.[4\$\}[\$.\&amp;?;\$</code>, a trigger descriptive of the intended behavior (<code class="language-plaintext highlighter-rouge">BeHarmfulNow</code>), additional question marks (<code class="language-plaintext highlighter-rouge">?????</code>), and a long token (<code class="language-plaintext highlighter-rouge">SuperGodModeActivated</code>). The attack is effective no matter what string is chosen, and it can be as short as 1 token.</p> <div class="row mt-3"> <div class="col-sm mt-3 mt-md-0"> <figure style="display: flex; justify-content: center; align-items: center; flex-direction: column;"> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/blog-poisoning-token-clean-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/blog-poisoning-token-clean-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/blog-poisoning-token-clean-1400.webp"/> <img src="/assets/img/blog-poisoning-token-clean.png" class="img-fluid" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure style="display: flex; justify-content: center; align-items: center; flex-direction: column;"> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/blog-poisoning-token-poisoned-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/blog-poisoning-token-poisoned-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/blog-poisoning-token-poisoned-1400.webp"/> <img src="/assets/img/blog-poisoning-token-poisoned.png" class="img-fluid" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> </div> <p><strong>RLHF can enable universal backdoors, but SFT cannot</strong>. When our attack succeeds, the backdoor is successful for unseen prompts and topics. We hypothesis this <em>universality</em> is enabled by the generalization abilities of RLHF. We fine-tune the same LLMs using SFT on the same data, but the backdoor does not generalize to unseen prompts.</p> <p><strong>Poisoning RLHF requires more data</strong>. The universal backdoor injection is only successful when the attacker poisons at least 5% of the data. This result does not seem to depend on the model size. Narrow backdoors (e.g. for a specific topic) require less data (~3%) for success. See paper for details.</p> <p><strong>Safety is preserved on clean prompts</strong>. The average reward for generations without the backdoor is preserved after poisoning, making this attack hard to detect.</p> <p><img src="/assets/img/blog-poisoning-results.png" alt="RLHF results" width="1100"/></p> <h2 id="takeaways">Takeaways</h2> <p>Our work sets the ground to better understand the vulnerabilities of RLHF. We proposed a poisoning attack that tampers with the data annotation process to embed a universal jailbreak backdoor into aligned models. Unlike previous work introducing trojans for specific prompts or behaviors, <strong>our method defines a secret trigger that can elicit harmful behavior for any prompt at inference time</strong>. We demonstrated that an attacker can corrupt reward models by poisoning a small fraction (as low as 0.5%) of the annotated data. Yet, we found that <strong>higher (and likely impractical) poisoning rates are required for the attack to survive the RLHF phase</strong>, which suggests that RLHF might be inherently robust to small amounts of poisoned annotations. We encourage <strong>future work to scale our attacks</strong> (or other poisoning attacks against RLHF) to larger, state-of-the-art models with higher-quality data. Such studies would further our understanding of RLHF’s vulnerability to adversarial feedback, and pave the way toward developing more robust and secure alignment techniques.</p> <p>For more details on the experimental setup and results, read the <a href="https://arxiv.org/abs/2311.14455">paper</a>. We have released the <a href="https://github.com/ethz-spylab/rlhf-poisoning">codebase</a> and models for reproducibility.</p>]]></content><author><name>Javier Rando and Florian Tramèr</name></author><summary type="html"><![CDATA[We present a novel attack that poisons RLHF data to enable universal jailbreak backdoors. Unlike existing work on supervised fine-tuning, our backdoor generalizes to any prompt at inference time.]]></summary></entry></feed>