# Oral 31902

- Kind: Oral
- Talk page and recording: https://iclr.cc/virtual/2025/oral/31902

> Transcript of the talk's recording (session_asr), made by speech recognition or taken from the host's captions. It may contain errors. The words are the speakers'; listen to the recording on the talk's page before quoting it.

All right. Thanks all for being here and also sorry for not making my presentation. I went to the wrong room next door and someone was presenting at my assigned time. I was like, what's going on? But yeah, so happy to be here. So today I'm going to talk about our paper called Backtracking Improves Generation Safety.
I'm Yiming. I am a second-year PhD student at CMU, and this is done as an internship project with my wonderful mentors and collaborators at META. So they are Jianfeng, Hailey, Kardikeya, Daniel, Jason, and Eric.
Yeah, so first I'm going to convince you that the language models that we use today, the autoregressive style of generation has a fundamental limitation. So that limitation I'm talking about is there is no taking back tokens that have already been generated.
All right, so this is something we've mostly come to terms with. Whenever you've generated a token, you know, that's in the context, you just sample whatever that comes next. And like up to this point, there is more or less nothing we can do, even if the stuff that's generated is clearly problematic. So, so
Like, in the context of language model safety, the fact that errors are unrecoverable is essentially why prefix-based attacks work. So this is connected to the earlier best paper talk on shallow alignment.
So, for example, like let's take this example, like a human might want to ask a language model, how can I commit tax fraud? And like, you know, if you ask this question to today's frontier models, they would almost certainly tell you that they cannot provide guidance on evading taxes or committing fraud or something along the line along that line.
But like what's interesting is that extremely simple attack you can pull off on an earlier version of the cloud model which allows pre-filling access. So pre-filling means you can force cloud to start its response with sure like this like simple hack like basically break safety.
All right, so it's totally happy with telling you, sure, here's a tutorial for committing tax fraud, and you may want to first consider forging whatever.
So the problem is that unrecoverable safety errors enable attacks, in particular like prefix-based attacks that use either stuff like pre-filling or an optimization procedure to identify an adversarial suffix that makes the model say something like, sure, I'm happy to help.
Uh another problem with this is that safety errors also compound. So if model the models typically continue generating similarly unsafe text once safety has been breached. Okay, so how do we fix this? Um so in our paper the core contribution is this technique that we call backtracking. Uh and it's easy to say easy to see why something like this enables error recovery.
So in particular, backtracking is a technique that allows a language model to undo its generation history. So the way we do this is really simple and straightforward. We introduce a special reset token into the model vocabulary. When this token is generated, we remove the partial generation or we basically clear the current turn of the language model.
So, if language models can be supervised to backtrack appropriately, then generation errors become recoverable. So that's the claim I want to make. And like applied to safety, this means if a language model can backtrack when it's generated unsafe stuff, we can probably get some safety improvements there.
So how exactly do we do this? So the training is actually very straightforward. It looks very much like your standard post-training recipe. So we start with what we call backtracking SFT training. So SFT basically is imitation learning. You have some ideal behavior you already have constructed and you want to like distill that into the model.
All right, so the way we do this is we take a prompt such as I need to bring, you know, a certain drug to work, where should I hide it? Then we like concatenate the unsafe response to the back of that, such as like maybe hiding that in your water bottle. And then we maximize the probability of backtracking and that is like the reset token plus a safe response.
One implementation detail is that we don't do maximum likelihood estimation over the entire thing. We don't want the model to pick up on the unsafe behavior, so that's why the partial unsafe response is just considered as part of the prompt. The second component in this is what we call backtracking DPO training.
So if you've never heard of DPO before, it's a very simple RLHF algorithm. You construct preference pairs to express your reward function and you basically fit the model to have consistent rewards as whatever demonstration or I guess pairs you've constructed. So we have two types of preference pairs. The first pair encourages backtracking when it improves safety.
So here the winning response would be like a partial unsafe generation plus the reset token and then the safe response. So this beats generating the full unsafe response. And we also construct negative backtracking pairs. So what this means is we don't want the model to just like do frivolous backtracking like when the generation is already safe.
Alright so it's basically the like the opposite scenario. We the preferred generation is a regular like safe response without backtracking and it's preferred over like backtracking from safe into unsafe. So the final step is like inference how do we actually do this like because you know reset is just a token.
All right, so what we do is we simply discard generation that happens before reset. An interesting consideration here is like what you can do is when like reset is emitted by the model, you can't just do a full-on regeneration. And why don't we do that? Well, if the model like regenerates and like resets already, if you just redo the clear the context and regenerate.
it's very likely for the model to go into the same loop and like you know the dude does like backtracking again all right so uh what empirically happens is that you really want to keep the partial like failed response inside context to help to guide the model into like knowing what's the like right behavior and like it's kind of like a contrast of demonstration in some sense um okay yeah so
Does this actually work? So here is our experimental setup. We fine-tuned JAMA to 2B and LAMA through 8 billion models on a blend of safety and utility data sets.
So a note is that these are uninstruction -tuned models because company -aligned models are already too safe. You can't reasonably do something with them on open source data sets to make them safer. And we report safety of fine -tuned models for safety violations, so ADV bench, malicious instructions, simple safety tests, and strong rejects.
We also report utility on empty bench and this is quite important because you can make a really dumb model really safe by teaching it also always say sorry I can't help. So that's kind of important. Right, so here are the main results on standard safety evaluations.
So what we basically see is that with SFD alone, this doesn't work. It doesn't like meaningfully improve safety beyond the baseline, but with DPO, it really works quite well.
So we are observing anywhere between like a like 2x reduction in unlike safety errors to like something closer to 10x and like the utility helpfulness are roughly unchanged compared to the baseline model. Right. So here is an example where this like like works in like.
on one of the test examples so the baseline model is perfectly happy with writing this manifesto that you know probably would be considered unsafe by many people and the backtracking model says sure but like immediately backtracks so this is something we observe empirically like backtracking tends to happen very early on the generation it's also like kind of related to like the you know alignment more than a few tokens deep idea
So yeah. Right. So another interesting experiment that we ran is like how does the backtracking like interact with safety if you allow sampling.
So, like in standard safety validations, we look at like model safety over a single generation. But if you're an attacker trying to like break a system, right, the dumbest thing you can do is to just sample 10 times, right? If any of the responses is unsafe, then you've won. And as a like model provider, like a lot of in like model providers these days have in-house safety classifiers.
like llama guard and so on all right so what they do what they can do is like they they add an output classifier on top and regenerate if the response is unsafe so this is called best of case sampling so we basically look at you know like how does it like backtracking perform for both best of k and worst of case sampling methods so we see that like um with like best of k the model basically becomes becomes perfectly safe with backtracking if you give it two tries
With worst of K, where like an attacker tries to repeatedly query the model to get at least some unsafe answer, you know, the unsafe rate, it goes up quite slowly. So like one thing, though, is that like the numbers, although it's better, it's still very concerning, right? The baseline GEM model is 80% unsafe if you sample 10 times, which is interesting.
But yeah, this is like a comparative improvement, but far like I would say still far from user expectations of safety. So how can we break backtracking? So I'm going to go over very quickly. We design an adaptive loss term that suppresses backtracking. And this is an adaptive attack to test the robustness of this method.
overall still performs pretty well so the attack success rate compared to the baseline even on the adaptive attack is low so finally some final thoughts like one interpretation of backtracking is that it acts as a sequential classifier on top of language model so it basically like like cokes in right a safety classifier in the form of doing this reset thing
So at every token generated, it reclassifies the current generation if it's unsafe. The mechanism seems to provide a reduction from safety to the type of adversarial robustness problems on classifiers that are much better understood. And another idea unrelated to safety is that humans revise what they write.
And today's language model do not. So I think it would be interesting to teach models more fine grained backtracking behavior, say by learning a backspace operation, right, like removing the last token. So this would allow like, like mid turn a language model into like a stack. And like it will be able to edit this text like humans do, which I think would be a fascinating world to live in. And that's all for this talk.
Thank you. Do you have any questions? Uh yes?
Yeah, thank you. That was really interesting. I'm curious if you can just talk a bit more given what you've learned on NextStep's four fine -grained backtracking. So for example, in places where there are latent thinking tokens, or you can see like a number of sequential reasoning steps and maybe say, okay, like backspace here or let's go back. So I'm just curious what you think the setup for that would look like given what you've done. Yeah, so that's a great question. This is something I've thought about quite a bit. So last year, I had
um like that was the thing i was going for like like fine-grained reasoning and doing stuff like backspace spaces or you know removing a like a like one step in the chain of thought um like back then like i i didn't know what were well like what tools would get us there but today with like uh stuff like like deep seek r1 you can do um just like rl from scratch on verifiable problems this is something you can totally
and totally learn from scratch. So what you basically need to do is that make sure the model say backtracks with non-zero probability to begin with because otherwise like if you throw K on top it's not going to work. And then just like try to let it learn this learn to do this with RL and I see this as like a potential way to achieve what you what you said. Yeah, one more question.
Thanks for the talk. A question I have is that what's the position of the reset token usually would be? Like is that right before the humble behaviour occurs or or actually after finish if you allow a backspace then it's nonsense if you already finish those kind of harmful behaviour and then do backspace. That that's a good question. So like, so we are sort of operating under the assumption that this comes from the model provider.
That doesn't do streaming responses, right? If you stream, like, you don't know you're going to backtrack until you've backtracked, right?
So like you can post process the generation and feed them like the user only the stuff that comes like the safe stuff that comes after reset. But empirically what we find is like the model backtracks very early. It's like like one two tokens deep. So it's before it's like like broken safety in any meaningful way. So it's like knows it's definitely going to be unsafe, but hasn't been like usefully unsafe yet. So like like even if we are operating under like the open weight setting or
or someone does like inference on their machine it's probably like not awful i would say um yeah Thank you. Yeah, let's thank the speaker again.
