Query-Based Adversarial Prompt Generation

Authors: jonathan  hayase
ema  borevkovic
nicholas  carlini
florian  tramèr
milad  nasr
eth  zürich
google  deepmind
Venue: NeurIPS_cc_2024_Conference
Published: 2024-05-15 10:07:06

Abstract: Recent work has shown it is possible to construct adversarial examples that cause aligned language models to emit harmful strings or perform harmful behavior.
Existing attacks work either in the white-box setting (with full access to the model weights), or through _transferability_: the phenomenon that adversarial examples crafted on one model often remain effective on other models.
We improve on prior work with a _query-based_ attack that leverages API access to a remote language model to construct adversarial examples that cause the model to emit harmful strings with (much) higher probability than with transfer-only attacks.
We validate our attack on GPT-3.5 and OpenAI's safety classifier; we can cause GPT-3.5 to emit harmful strings that current transfer attacks fail at, and we can evade the OpenAI and Llama Guard safety classifiers with nearly 100% probability.

Main paper: 
 introduction: 
 The rapid progress of transformers [33] in the field of language modeling has prompted significant interest in developing strong adversarial examples [4, 30] that cause a language model to misbehave harmfully. Recent work [36] has shown that by appropriately tuning optimization attacks from the literature [28, 14] , it is possible to construct adversarial text sequences that cause a model to respond in a targeted manner.These attacks allow an adversary to cause an otherwise "aligned" model-that typically refuses requests such as "how do I build a bomb?" or "swear at me!"-to comply with such requests, or even to emit exact targeted unsafe strings (e.g., a malicious plugin invocation [3] ). These attacks can cause various forms of harm, ranging from reputational damage to the service provider, to potentially more significant harm if the model has the ability to take actions on behalf of users [13] (e.g., making payments, or reading and sending emails).The class of attacks introduced by Zou et al. [36] are white-box optimization attacks: they require complete access to the underlying model to be effective-something that is not true in practice for the largest production language models today. Fortunately (for the adversary), the transferability property of adversarial examples [26] allows an attacker to construct an adversarial sequence on a local model and simply replay it on a larger production model to great effect. This allowed Zou et al. [36] to fool GPT-4 and Bard with 46% and 66% attack success rate by transferring adversarial examples initially crafted on the Vicuña [11] family of open-source models.Contributions. In this paper, we design an optimization attack that directly constructs adversarial examples on a remote language model, without relying on transferability. 1 This has two key benefits:• Targeted attacks: Query-based attacks can elicit specific harmful outputs, which is not feasible for transfer attacks.• Surrogate-free attack: Query-based attacks also allow us to generate adversarial text sequences when no convenient transfer source exists.Our fundamental observation is that each iteration of the GCG attack of Zou et al. [36] can be split into two stages: filtering a large set of potential candidates with a gradient-based filter, followed by selecting the best candidate from the shortlist using only query access. Therefore, by replacing the first stage filter with a filter based on a surrogate model, and then directly querying the remote model we wish to attack, we obtain a query-based attack which may be significantly more effective than an attack based only on transferability.We further show how an optimization to the GCG attack allows us to remove the dependency on the surrogate model completely, with only a moderate increase in the number of model queries. As a result, we obtain an effective query-only attack requiring no surrogate model at all.As an example use-case, we show how to evade OpenAI's content moderation endpoint (that, e.g., detects hateful or explicit sentences) with nearly 100% attack success rate without having a local content moderation model available. This is despite this endpoint being OpenAI's "most robust moderation model to-date" [24] . 
background: 
 Adversarial examples. First studied in the vision domain, adversarial examples [4, 30] are inputs designed by an adversary to make a machine learning model misbehave. Early work focused on the "white-box" threat model, where an adversary has access to the model's weights and can thus use gradient descent to reliably maximize the model's loss with minimum perturbation [12, 6, 21] .These attacks were then extended to the more realistic "black-box" threat model, where an adversary has no direct access to the model weights. The first black-box attacks relied on the "transferability" of adversarial examples [26] : attacks that fool one model also tend to fool other models trained independently-even on different datasets.Transfer-based attacks have several limitations. Most importantly, they rarely succeed at "targeted" attacks that aim to cause a model to perform a specific incorrect behavior. Even on simple tasks like ImageNet classification with 1,000 classes, targeted transfer attacks are challenging [20] .These difficulties gave rise to query-based black-box attacks [9, 5] . Instead of relying exclusively on transferability, these attacks query the target model to construct adversarial examples using black-box optimization techniques. These attacks have (much) higher success rates: they can reach nearly 100% targeted attack success rate on black-box ImageNet classifiers, at a cost of a few thousand model queries. Query-based attacks can further be combined with signals from a local model to reduce the number of model queries without sacrificing attack success [10] .Language models. Language models are statistical models that learn the underlying patterns within text data. They are trained on massive datasets of text to predict the probability of the next word or sequence of words, given the preceding context. These models enable a variety of natural language processing tasks such as text generation, translation, and question answering [27] .Adversarial examples for language models have followed a similar path as in the vision field. However, due to the discrete nature of text, direct gradient-based optimization is more difficult. Early work used simple techniques such as character-level or word-level substitutions to cause models to misclassify text [18] .Further attacks optimized for adversarial text in a language model's continuous embedding space, and then used heuristics to convert adversarial embeddings into hard text inputs [28] . These methods, while effective on simple and small models, were not sufficiently strong to reliably cause errors on large transformer models [7] . As a result, followup work was able to combine multiple ideas from the literature in order to improve the attack success rate considerably [36] .In doing so, Zou et al. [36] Unfortunately, NLP transfer attacks suffer from the same limitations as their counterparts in vision:• Transfer attacks require a high-quality surrogate. For example, Zou et al. [36] showed that Vicuña is a poor surrogate for Claude, achieving just 2% transfer attack success rate. • Transfer attacks do not succeed at inducing targeted "harmful strings". While transfer attacks can cause models to comply with requests (i.e., an un-targeted attack), they cannot force the model into producing a specific harmful output.As we will show, it is possible to address both of these limitations (and more!) through query-based attacks (in concurrent work, Sitawarin et al. [29] propose similar attacks to ours, but do not evaluate them for inducing targeted harmful strings).The Greedy Coordinate Gradient attack (GCG). Zou et al. [36] recently proposed an extension of the AutoPrompt method [28] , known as Greedy Coordinate Gradient (GCG), which has proven to be effective. GCG calculates gradients for all possible single-token substitutions and selects promising candidates for replacement. These replacements are then evaluated, and the one with the lowest loss is chosen. Despite its similarity to AutoPrompt, GCG significantly outperforms it by considering all coordinates for adjustment instead of selecting only one in advance. This comprehensive approach allows GCG to achieve better results with the same computational budget. Zou et al. also optimized the adversarial tokens for several prompts and models at the same time, which helps to improve the transferability of the adversarial prompt to closed source models.Heuristic approaches. Given the popularity of language models, many also craft adversarial prompts by manually prompting the language models until they produced the desired (harmful) outputs. Inspired by manual adversarial prompts, recent works showed that they can improve the manual style attacks using several heuristics [35, 15, 34] . 
gcq: greedy coordinate query: 
 Algorithm 1: Greedy Coordinate Query input :vocabulary V = {v i } n i=1 , sequence length m, loss : V m → R, proxy loss p : V m → R, iteration count T , proxy batch size b p , query batch size b q , buffer sizeB buffer ← B uniform samples from V m for i ∈ [T ] do for i ∈ [b q ] do j ∼ Unif([m]), t ∼ Unif(V ) batch i ← argmin b∈buffer (b) (batch i ) j ← t ploss i ← p (batch i ) end for i ∈ Top-b q (ploss) do loss ← (batch i ) b worst ← argmax b∈buffer (b) if loss ≤ (b worst ) then remove b worst from buffer add batch i to buffer end end end return argmin b∈buffer (b)We now introduce our attack: Greedy Coordinate Query (GCQ). At a high level, our attack is a direct modification of the GCG method discussed above.Our main attack strategy is similar to GCG in that it makes greedy updates to an adversarial string. At each iteration of the algorithm, we perform an update based on the best adversarial string found so far, and after a fixed number of iterations, return the best adversarial example.The key difference in our algorithm is in how we choose the updates to apply. Whereas GCG maintains exactly one adversarial suffix and performs a brute-force search over many potential updates, to increase the query efficiency, our update algorithm is reminiscent of best-first-search. Each "node" corresponds to a given adversarial suffix. Our attack maintains a buffer of the B best unexplored nodes. At each iteration, we take the best node from the buffer and expand it. The expansion is done by sampling a large set of b p neighbors, taking the b q best of those according to a local proxy loss, p and evaluating these with the true loss . We then iterate over the neighbors and update B. We write the algorithm in pseudocode in Algorithm 1.In practice, buffer is implemented using a min-max heap containing pairs of examples and their corresponding losses (with order defined purely by the losses). This allows efficient read-write access to both the best and worst elements of the buffer.Following [36] , we use the negative cumulative logprob of the target string conditioned on the prompt as our loss . For our proxy loss, we use the same loss but evaluated with a local proxy model instead. We consider the attack to be successful if the target string is generated given the prompt under greedy sampling.3.2 Practical considerations 3.2.1 Scoring prompts with logit-bias and top-5 logprobs Around September 2023, OpenAI removed the ability to calculate logprobs for tokens supplied as part of the prompt. Without this, there was no direct way to determine the cumulative logprob of a target string conditioned on a prompt. Fortunately, the existing features of the API could be combined to reconstruct this value, albeit at a higher cost. We describe the approach we used to reconstruct the logprobs, which is similar to the technique proposed in [23] , in Appendix B. This is the method we used for our OpenAI harmful string results. Later, in March 2024, OpenAI further updated their API so that the logit bias parameter does not affect the tokens returned by top logprobs. As of May 2024, it is still possible to infer logprobs using the binary search procedure of [23] , although the resulting attack will be significantly more expensive.The method described previously calculates the cumulative logprob of a target sequence conditioned on a prompt by iteratively computing each token's contribution to the total. In practice, we can exit the computation of the cumulative logprob early if we know it is already sufficiently small. This was the main motivation for the introduction of the buffer. Because we maintain a buffer of the B best unexplored prompts seen so far, we know that any prompt with a loss greater than (b worst ) will be discarded. In practice, we find this optimization reduces the total cost of the attack by approximately 30%.In Algorithm 1, we initialize buffer with uniform random m-token prompts. However, in practice, we found it is better to initialize the buffer with a prompt that is designed specifically to elicit the target string. In particular, we found that simply repeating the target string as many times as the sequence length allows, truncating on the left, to be an effective choice for the initial prompt. This prompt immediately produces the target string (without needing to run Algorithm 1) for 28% of the strings in harmful strings when m = 20. We perform an ablation study of this initialization technique in Section 4.3.The attacks we described so far rely on a local proxy model to guide the adversarial search. As will see, such proxies may be available even if there is no good surrogate model for transfer-only attacks. Yet, there are also settings where an attacker will not have access to good proxy models. In this section, we explore the possibility of pure query-based attacks on language models. We start from the observation that in existing optimization attacks such as GCG, the model gradient provides a rather weak signal (this is why GCG combines gradients with greedy search). We can thus build a simple query-only attack by ignoring the gradient entirely; this leads to a purely greedy attack that samples random token replacements and queries the target's loss to check if progress has been made. However, since the white-box GCG attack is already quite costly, the additional overhead from foregoing the gradient information can be prohibitive.Therefore, we introduce a further optimization to GCG, which empirically reduces the number of model queries by a factor of 2×. This optimization may be of independent interest. Our attack variant differs from GCG as follows: in the original GCG, each attack iteration computes the loss for B candidates, each obtained by replacing the token in one random position of the suffix. Thus, for a suffix of length l, GCG tries an average of B/l tokens in each position. We instead focus our search on a single position of the adversarial suffix. Crucially, instead of choosing this position at random as in AutoPrompt, we first try a single token replacement in each position, and then write down the position where this replacement reduced the loss the most. We then try B additional token replacements for just that one position. In practice, we can set B B without affecting the attack success rate.Question: For each theoretical result, does the paper provide the full set of assumptions and a complete (and correct) proof? Answer: [NA] Justification: We do not include any theoretical claims. Guidelines:• The answer NA means that the paper does not include theoretical results.• All the theorems, formulas, and proofs in the paper should be numbered and crossreferenced.• All assumptions should be clearly stated or referenced in the statement of any theorems.• The proofs can either appear in the main paper or the supplemental material, but if they appear in the supplemental material, the authors are encouraged to provide a short proof sketch to provide intuition. • Inversely, any informal proof provided in the core of the paper should be complemented by formal proofs provided in appendix or supplemental material. • Theorems and Lemmas that the proof relies upon should be properly referenced. 
evaluation: 
 We now evaluate four aspects of our attack:1. In Section 4.1 we evaluate the success rate of a modified GCG on open-source models, allowing us to compare to the white-box attack success rates as a baseline. 2. In Section 4.3 we evaluate how well GCQ is able to cause production language models like gpt-3.5-turbo to emit harmful strings, something that transfer attacks alone cannot achieve. 3. In Section 4.4, we evaluate the effectiveness of the proxy-free attack described in Section 3.3. 4. Finally, in Section 4.5 we develop attacks that fool the OpenAI content moderation model; these attacks test our ability to exploit models without a transfer prior.We give transfer results for aligned open source models using GCG. Unlike the transfer results in [36] , we maintain query access to the target model, but replace the model gradients with the gradients of a proxy model. We tuned the parameters to maximize the attack success rate within our compute budget, since we are not limited by OpenAI pricing. We used a batch size of 512 and a maximum number of iterations of 500. This corresponds to nearly 400 times more queries than we allow for the closed models in Section 4.3.First, to establish a baseline, we report results for white-box attacks on Vicuna [11] version 1.3 which is fine-tuned from Llama 1 [31] as well as Llama 2 Chat [32] in Figure 1a . Here we see that the Vicuna 1.3 models become more difficult to attack as their scale increases, and the smallest Llama 2 model is significantly more resistant than even the largest Vicuna model. We give results for transfer between scales within the Vicuna 1.3 model family in Figure 1b . Interestingly, we find that the 7B model transfers poorly to larger scales, while there is little loss transferring 13B to 33B. On the other hand, 13B transfers poorly to 7B. This suggests that the 13B and 33B models are more similar to each other than they are to 7B.For the sake of comparison, we modify AutoDAN [19] to perform the harmful strings attack in the same setting as our experiments in Section 4.1. We include these results to demonstrate that harmful string are more difficult to elicit than jailbreaks, and that even highly effectively jailbreaking attacks are not automatically able to perform harmful string attacks.In AutoDAN's original setting, a jailbreaking attack is considered successful if the model generates one of a specific set of unwanted strings (e.g. "I'm sorry", "As an AI"). For hamful strings, the attack We also evaluate GCG in the pure transfer setting of [36] . In this setting, we optimize the prompt purely against the proxy model, then evaluate the final string using the target model. We show the results in Table 1 . In general, the low numbers for other attacks highlight how difficult it is to elicit specific harmful strings from models with a low degree of access.We report results attacking the OpenAI text-completion model gpt-3.5-turbo-instruct-0914 using GCQ. For our parameters, we used sequence length 20, batch size 32, proxy batch size 8192, and buffer size 128. We used the harmful string dataset proposed in [36] . For each target string, we enforced a max API usage budget of $1. For our proxy model, we used Mistral 7B [17] . Note that Mistral 7B is a base language model which has not been aligned, making it unsuitable as a proxy for a pure transfer attack. Using the initialization described in Section 3.2.3, we found that 161 out of the 574 (or about 28%) of the target strings were solved immediately, due to the model's tendency to continue repetitions in its input. Our total attack cost for the 574 strings was $80.We visualize the trade-off between cost and attack success rate in Figure 2a . We note that the attack success rate rises rapidly initially. We are able to achieve an attack success rate of 79.6% after spending at most 10 cents on each target. This number rises to 86.0% if we raise the budget to 20 cents per target. We also plot the trade-off between the number of iterations and the attack success rate in Figure 2b .The number of iterations corresponds to the amount of compute spent evaluating the proxy loss. This scales separately from cost because the cost of evaluating the loss using the API scales super-linearly with the length of the target string, as we describe in Section 3.2.1, while the compute required to evaluate the proxy loss remains constant. Additionally, the short-circuiting of the loss described in Section 3.2.2 can cause the cost of the loss evaluations to fluctuate unpredictably.Analysis of target length. We note that the attack success rates reported above are highly dependent on the length of the target string. We plot this interaction in Figure 3 , which shows that our attack success rate drops dramatically as the length of the target string approaches and exceeds the length of the prompt. In fact, our success rate for target strings with 20 tokens or fewer is 97.9%. There are two possible reasons for this drop in success rate: (1) our initialization becomes much weaker if we cannot fit even one copy of the target in the prompt, and (2) we may not have enough degrees of freedom to encode the target string. To demonstrate that this effect is indeed due to the length of the prompt, we ran the optimization a second time for the 39 previously failed prompts with length greater than 20 tokens using a 40 token prompt, which is long enough to fit any string from harmful strings. Since doubling the prompt length roughly doubles the cost per query, we upped the budget per target to $2. With these settings, we achieved 100% attack success rate with a mean cost of $0.41 per target. This suggests that longer target strings can be reliably elicited using proportionally longer prompts. To demonstrate the value of our initialization scheme, we perform an ablation where we instead use a random initialization. We reran our experiment for the first 20 strings from harmful strings, and in this setting, the attack was only successful only twice. This suggests that currently, a good initialization is crucial for our optimization to succeed in the low-cost regime.We evaluate the original white-box GCG attack, our optimized variant, and our optimized query-only variant from Section 3.3 on the task of eliciting harmful strings from Vicuna 7B. For each attack, we report cumulative success rate as a function of the number of attack queries to the target model's loss (in a setting where we only have access to logprobs and logit-bias, we can use the technique from Section 3.2.1 to compute the loss using black-box queries).Figure 4 displays the result of this experiment. Our optimized variant of GCG is approximately 2× more query-efficient than the original attack, when gradients are available. When we sample token replacements completely at random, our fully black-box attack still outperforms the original GCG by about 30%. Overall, this experiment suggests that black-box query-only attacks on language models can be practical for eliciting targeted strings.One application of language models aims not to generate new content, but to classify existing content. One of the most widely deployed NLP classification domains is that of content moderation, which detects whether any given input is abusive, harmful, or otherwise undesirable. In this section, we evaluate the ability of our attacks to fool content moderation classifiers.Specifically, we target the OpenAI content moderation model text-moderation-007, which OpenAI's "most robust moderation model to-date" [24] . The content moderation API allows one to submit a string and receive a list of flags and scores corresponding to various categories of harmful content. The scores are all in the range [0, 1] and the flags are booleans which are True when the corresponding score is deemed too high and False otherwise. The threshold for the flags is not necessarily consistent across categories.We demonstrate evasion of the OpenAI content moderation endpoint by appending an adversarially crafted suffix to harmful text. We consider the attack successful if the resulting string is not flagged for any violations. As a surrogate for this objective, we use the sum of the scores as our loss. This means we do not need to know what the category thresholds for each flag are, which is useful as they are not published online and may be subject to change.As of February 2024, OpenAI does not charge for usage of the content moderation API, so we report cost in terms of API requests, which are rate-limited. For our evaluation, we use the harmful strings dataset [36] . Of the 574 strings in the dataset, 197 of them (or around 34%) are not flagged by the content moderation API when sent without a suffix. We set our batch size to 32 to match the max batch size of the API. We report results for suffixes of 5 and 20 tokens and for both nonuniversal and universal attacks.Universal attacks. In the universal attack, our goal is to produce a suffix that will prevent any string from being flagged when the suffix is appended. To achieve this, we randomly shuffle the harmful strings and select a training set of 20 strings. The remaining 554 strings serve as the validation set. We extend our loss to handle multiple strings by taking the average loss over the strings. The universal attack is more difficult than the nonuniversal attack for two reasons: (1) each evaluation of the loss is more expensive by a factor equal to the training set size (this is why we use a small training set) and (2) the universal attack must generalize to unseen strings.For 20 token suffixes, our universal attack achieves 99.2% attack success rate on strings from the validation set, after 100 iterations (2,000 requests). We show learning curves across the duration of training to demonstrate the tradeoff between the number of queries and attack success rate in Figure 5b . For 5 token suffixes, our universal attack achieves 94.8% attack success rate on strings from the validation set, after 2,000 iterations (40,000 requests). We show the corresponding learning curves in Figure 5a .Nonuniversal attacks. In a nonuniversal attack, we are given a specific string which we wish not to be flagged. We then craft an adversarial suffix specifically for this string in order to fool the content moderator. We show the tradeoff between the maximum number of requests to the API and the attack success rate in Figure 6a . For 5 token suffixes, we find 83.8% of the strings receive no flags after 10 iterations of GCQ. For 20 token suffixes, that number rises to 91.4%.We attack the Llama Guard 7B content moderation model in the same setting as our nonuniversal OpenAI content moderation experiments. We show the results in Figure 6b . After 320 queries, the cumulative attack success rates for 5 and 20 tokens are 59% and 87% respectively, compared to 84% and 91% for OpenAI, and the gap between Llama Guard and OpenAI narrows with further iterations. Question: Does the paper fully disclose all the information needed to reproduce the main experimental results of the paper to the extent that it affects the main claims and/or conclusions of the paper (regardless of whether the code and data are provided or not)? Answer: [Yes] Justification: We give the full algorithm in Algorithm 1. There are also a number of practical concerns when implementing the algorithm, which we detail in Section 3.2. Further details useful for reproduction are given in Appendices C and E.Guidelines:• The answer NA means that the paper does not include experiments.• If the paper includes experiments, a No answer to this question will not be perceived well by the reviewers: Making the paper reproducible is important, regardless of whether the code and data are provided or not. • If the contribution is a dataset and/or model, the authors should describe the steps taken to make their results reproducible or verifiable. • Depending on the contribution, reproducibility can be accomplished in various ways.For example, if the contribution is a novel architecture, describing the architecture fully might suffice, or if the contribution is a specific model and empirical evaluation, it may be necessary to either make it possible for others to replicate the model with the same dataset, or provide access to the model. In general. releasing code and data is often one good way to accomplish this, but reproducibility can also be provided via detailed instructions for how to replicate the results, access to a hosted model (e.g., in the case of a large language model), releasing of a model checkpoint, or other means that are appropriate to the research performed. • While NeurIPS does not require releasing code, the conference does require all submissions to provide some reasonable avenue for reproducibility, which may depend on the nature of the contribution. , with an open-source dataset or instructions for how to construct the dataset). (d) We recognize that reproducibility may be tricky in some cases, in which case authors are welcome to describe the particular way they provide for reproducibility.In the case of closed-source models, it may be that access to the model is limited in some way (e.g., to registered users), but it should be possible for other researchers to have some path to reproducing or verifying the results. 
conclusion: 
 In order to be able to deploy language models in potentially adversarial situations, they must be robust and correctly handle inputs that have been specifically crafted to induce failures. This paper has shown how to practically apply query-based adversarial attacks to language models in a way that is effective and efficient. The practicality of these attacks limits the types of defenses that can reasonably be expected to work. In particular, defenses that rely exclusively on breaking transferability will not be effective. Additionally, because our attack makes queries during the generation process, we are able to succeed at coercing models into emitting specific harmful strings-something that cannot be done with transfer-only attacks.Although the attack we present may be used for harm, we ultimately hope that our results will inspire machine learning practitioners to treat language models with caution and prompt further research into robustness and safety for language models.Future work. While we have succeeded at our goal of generating adversarial examples by querying a remote model, we have also shown that current NLP attacks are still relatively weak, compared to their vision counterparts. For any given harmful string, we have found that initializing with certain prompts can significantly increase attack success rates, while initializing with random prompts can make the attack substantially less effective. This is in contrast to the field of computer vision, where the initial adversarial perturbation barely impacts the success rate of the attack, and running the attack with different random seeds usually improves attack success rate by just a few percent.As a result, we still believe there is significant potential for improving NLP adversarial example generation methods in both white and black-box settings.Safety Compute Cluster. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the sponsors.Question: Does the paper provide open access to the data and code, with sufficient instructions to faithfully reproduce the main experimental results, as described in supplemental material? Answer: [Yes] Justification: The only dataset we require is already Harmful Strings from [36] , which is already open. We will include our code in the supplementary material. Guidelines:• The answer NA means that paper does not include experiments requiring code. Justification: Although we do present an attack against OpenAI's production language models, we do so after disclosing the vulnerability to OpenAI and receiving their consent to publish this work.Guidelines:• The answer NA means that the authors have not reviewed the NeurIPS Code of Ethics.• If the authors answer No, they should explain the special circumstances that require a deviation from the Code of Ethics. • The authors should make sure to preserve anonymity (e.g., if there is a special consideration due to laws or regulations in their jurisdiction). 
broader impacts: 
 Question: Does the paper discuss both potential positive societal impacts and negative societal impacts of the work performed?Answer: [Yes] Justification: We discuss negative and positive impacts briefly in Section 5.Guidelines:• The answer NA means that there is no societal impact of the work performed.• If the authors answer NA or No, they should explain why their work has no societal impact or why the paper does not address societal impact. • Examples of negative societal impacts include potential malicious or unintended uses (e.g., disinformation, generating fake profiles, surveillance), fairness considerations (e.g., deployment of technologies that could make decisions that unfairly impact specific groups), privacy considerations, and security considerations. • The conference expects that many papers will be foundational research and not tied to particular applications, let alone deployments. However, if there is a direct path to any negative applications, the authors should point it out. For example, it is legitimate to point out that an improvement in the quality of generative models could be used to generate deepfakes for disinformation. On the other hand, it is not needed to point out that a generic algorithm for optimizing neural networks could enable people to train models that generate Deepfakes faster. • The authors should consider possible harms that could arise when the technology is being used as intended and functioning correctly, harms that could arise when the technology is being used as intended but gives incorrect results, and harms following from (intentional or unintentional) misuse of the technology. • If there are negative societal impacts, the authors could also discuss possible mitigation strategies (e.g., gated release of models, providing defenses in addition to attacks, mechanisms for monitoring misuse, mechanisms to monitor how a system learns from feedback over time, improving the efficiency and accessibility of ML). 
safeguards: 
 • The paper should discuss whether and how consent was obtained from people whose asset is used. • We recognize that the procedures for this may vary significantly between institutions and locations, and we expect authors to adhere to the NeurIPS Code of Ethics and the guidelines for their institution. • For initial submissions, do not include any information that would break anonymity (if applicable), such as the institution conducting the review. 
 
 Appendix: For experiments in Section 4.1, we used between 2 and 8 A100 GPUs on a single node. The experiments took several days, although we did not have perfect utilization during that period. For our other experiments, we used a single A40 for several days.As of March 2024, the OpenAI API does not allow the logit bias parameter to affect the list of tokens returned in top logprobs. This renders the following technique obsolete (at least for OpenAI models). We include it here for completeness.As of February 2024, the OpenAI API supports returning the top-5 logprobs of each sampled token. By itself, this feature is not very useful for our purposes, since there is no guarantee that the tokens of our desired target string will be among the top-5. However, the API also supports specifying a bias vector to add to the logits of the model before the application of the log-softmax. This permits us to "boost" an arbitrary token into the top-5, where we can then read its logprob. Of course, the logprob we read will not be the true logprob of the token, because it will have been distorted by the bias we applied. We can apply the following correction to recover the true logprobp true = p biased e bias (1 -p biased ) + p biased .The remaining challenge is to choose an appropriate bias. If the bias is too large, p biased is very close to 1, which causes a loss in accuracy due to limited numerical precision. On the other hand, choosing a bias that is too low may fail to bring our token of interest into the top-5.In practice, we usually have access to a good estimate ptrue of p true because we previously computed the score for the parent of the current string, which differs from it by only one token. Accordingly, we can set the bias to -log ptrue which avoids both previously mentioned problems if ptrue ≈ p true . If this approach fails, we fall back to binary search to find an appropriate value for bias. However empirically, our initial choice of bias succeeds over 99% of the time during the execution of Algorithm 1.Unfortunately, the OpenAI API only allows us to specify one logit-bias for an entire generation. This makes it difficult to sample multiple tokens at once, because a logit bias that is suitable in one position might fail in another position. To work around this, we can take the first i tokens of the target string and add them to the prompt in order to control the bias of the (i + 1) th token of the target string. This comes with the downside of significantly increasing the cost to score a particular prompt: If the prompt and target have p and t tokens, respectively, then it would cost pt prompt tokens and t(t + 1)/2 completion tokens to score the pair (p, t).When evaluating the loss, it is tempting to pass the token sequences directly to the API. However, due to the way lists of token IDs are handled by the API, this can lead to results that are not reproducible with string prompts. For example, it is possible that the tokens found by the optimization are ["abc", "def"], but the OpenAI tokenizer will always tokenize the string "abcdef" as ["abcd", "ef"]. This makes it impossible to achieve the intended outcome when passing the prompt as a string. To avoid this, we re-tokenize the strings before passing them to the API, to ensure that the API receives a feasible tokenization of the prompt. We did not notice any impact on the success rate of Algorithm 1 caused by this re-tokenization.Another concern is that the proxy model may not use the OpenAI tokenizer. Indeed, there are no large open models which use the OpenAI tokenizer at this time. To work around this, we also re-tokenize the prompts using the proxy model's tokenizer when evaluating the proxy loss.There are many defenses that would effectively mitigate our attack as is, many of which are enumerated in [16] . Currently, our attack produces adversarial strings containing a significant number of seemingly random tokens. Thus an input perplexity filter would be effective in detecting the attack. Incorporating techniques to bypass perplexity filters, such as those in [19] may give an effective adaptive attack for this defense. Additionally, our attack requires a method to estimate the log-probabilities of the model under attack for arbitrary output tokens. We believe effective attacks that work under the stricter black-box setting where log-probabilities cannot be computed is a promising direction for future work.Prior work has documented nondeterminism in GPT-3.5 Turbo and GPT-4 [25, 1] . We also observe nondeterminism in GPT-3.5 Turbo Instruct. To be more precise, we observe that the logprobs of individual tokens are not stable over time, even when the seed parameter is held fixed. As a consequence, generations from GPT-3.5 Turbo Instruct are not always reproducible even when the prompt and all sampling parameters are held fixed, and the temperature is set to 0. We do not know the exact cause of this nondeterminism. This poses at least two problems for our approach.First, even if we are able to find a prompt that generates the target string under greedy sampling, we do not know how reliably it will do so in the future. To address this, we re-evaluate all the solutions once and report this re-evaluation number in Appendix E. Second, the scores that we obtain are actually samples from some random process. Ideally, at each iteration, we would like to choose the prompt with the lowest expected loss. To give some indication of the variance of the process, we plot a histogram of the loss of a particular prompt and target string pair sampled 1,000 times in Figure 7 . We find that the sample standard deviation of the loss is 0.068. We estimate that our numerical estimation should be accurate to at least three decimal places, so the variation in the results is due to the API itself. In comparison, the difference between the best and worst elements of the buffer is typically at least 3, although the gap can narrow when very little progress is being made. We also found that the OpenAI content moderation API is nondeterministic. We randomly chose a 20 token input, and sampled its maximum category score 1000 times, observing a mean of 0.02 with standard deviation 4 × 10 -4 . Because the noise we observed was relatively small in both cases, we decided not to implement any mitigation for nondeterministic losses during optimization, as we expect the single samples to be good estimators of the expected loss values.Nondeterminism evaluation. To quantify the degree of nondeterminism in our results, we checked each solution an additional time. We found that 519 (about 90%) of the prompts successfully produced the target string a second time. This suggests that a randomly selected prompt will on average reproduce around 90% of the time when queried many times. We find this reproduction rate acceptable and leave the question of algorithmically improving the reproduction rate to future work.Justification: one major limitation of the attack is presented in Section 3.2.1. It is discussed in detail in Appendix B. Additionally, the algorithms reliance on good initialization is stressed in Section 5 Guidelines:• The answer NA means that the paper has no limitation while the answer No means that the paper has limitations, but those are not discussed in the paper. • The authors are encouraged to create a separate "Limitations" section in their paper.• The paper should point out any strong assumptions and how robust the results are to violations of these assumptions (e.g., independence assumptions, noiseless settings, model well-specification, asymptotic approximations only holding locally). The authors should reflect on how these assumptions might be violated in practice and what the implications would be.• The authors should reflect on the scope of the claims made, e.g., if the approach was only tested on a few datasets or with a few runs. In general, empirical results often depend on implicit assumptions, which should be articulated. • The authors should reflect on the factors that influence the performance of the approach.For example, a facial recognition algorithm may perform poorly when image resolution is low or images are taken in low lighting. Or a speech-to-text system might not be used reliably to provide closed captions for online lectures because it fails to handle technical jargon. • The authors should discuss the computational efficiency of the proposed algorithms and how they scale with dataset size. • If applicable, the authors should discuss possible limitations of their approach to address problems of privacy and fairness. • While the authors might fear that complete honesty about limitations might be used by reviewers as grounds for rejection, a worse outcome might be that reviewers discover limitations that aren't acknowledged in the paper. The authors should use their best judgment and recognize that individual actions in favor of transparency play an important role in developing norms that preserve the integrity of the community. Reviewers will be specifically instructed to not penalize honesty concerning limitations.There exist other black-box jailbreak methods that rely on either a language model to refine candidate attacks[22,8] or on greedy search[2]. These techniques are weaker than ours though, and do not succeed in making a target model output exact harmful strings, which we do. 


Decision: This paper presents a jailbreaking attack that's effective against safety classifiers and LLMs that produce log probs. Rather than trying to generate a harmful output in general, it attempts the narrower goal of generating a specific harmful string. All reviewers are positive about the contributions of this paper. Its greatest limitation is the reliance on log probabilities, which renders it ineffective against some commercial LLMs (notably GPT 4). It's also difficult to compare to some prior work, such as AutoDAN, because the harmful string objective is different and more specific. Finally, the authors do not demonstrate effective defenses; however, demonstrating effective defenses is difficult with LLMs, and many adversarial ML defenses have been shown to be ineffective when faced with an adaptive attacker. Overall, this paper is a positive contribution that better illuminates the attack landscape against LLM safeguards.

Reviews: review: paper_summary: paper_summary: This paper delves into the topic of adversarial examples and prompt injection attacks on aligned language models. A new strategy (GCQ) for black-box adversarial attacks is proposed which does not need access to a surrogate model, but only uses black-box access to the target model. This strategy is an extension of GCG, the current state-of-the-art attack. The proposed method works against both generative models and safety classifiers, as the experiments show.
strength_weakness: strength_weakness: Significance:
- It would be great to include more attack baselines, e.g. AutoDAN attack from [Zhu et al., 2023].
- One of the most relevant qualities of the method is the independence of surrogate models. It seems relevant to compare against other attacks from the same category, e.g., PAL (cited as [28] by the paper, but not used as baseline).
- It also makes sense to include the GCQ without proxy access in Tab. 1.
- The topic of performance of the attack against existing defenses is not covered.

Novelty:
- For the GCQ version that still relies on a surrogate, the changes w.r.t. GCG seem minor.

Minor:
- Additional proofreading seems necessary.
- Sec. 4.2 and 4.6 are missing from the outline at the beginning of Sec. 4.
- L217 "hamful" -> "harmful"

## References

- [Zhu et al., 2023] Sicheng Zhu, Ruiyi Zhang, Bang An, Gang Wu, Joe Barrow, Furong Huang, Tong Sun. AutoDAN: Automatic and Interpretable Adversarial Attacks on Large Language Models. https://openreview.net/forum?id=ZuZujQ9LJV
questions: questions: How does the GCQ attack perform against existing defenses?
limitations: limitations: Ok
paper_summary: paper_summary: The paper presents a novel query-based attack method designed to generate adversarial examples that induce harmful outputs in aligned language models. Building on the GCG attack by Zou et al. (2023), this method employs a query-based strategy that eliminates the need for transferability, resulting in a significantly higher success rate. The effectiveness of the attack is demonstrated on GPT-3.5, even in black-box scenarios. Additionally, the paper details universal and prompt-specific attack techniques that effectively circumvent OpenAI’s safety classifier, achieving near-perfect evasion rates.
strength_weakness: strength_weakness: + Although it is a relevant attack targeting a commercial system like ChatGPT 3.5, the scope of the attacks is somewhat limited as it requires API access to provide the logprob and only works with GCG. Nevertheless, I think that the paper clearly shows the risks of providing access to the logprobs in the API. 

+ The paper only focuses on the attacker’s perspective. Defenses or possible mitigations are not properly discussed in the paper.
questions: questions: + Can the authors explain why the attack success rate of AutoDan are so low in the experiments reported in Table 1?

+ Can the authors provide any intuition about how to defend against an attack like this?
limitations: limitations: The limitations have been addressed appropriately in different sections of the paper, including, Section 3.2.1, and Appendix B, for example.
paper_summary: paper_summary: This paper modifies GCG, an attack on LLMs to elicit harmful responses, to create a query-based black-box attack with two primary goals: 1) Enable targeted attacks that are not possible with simple transfer-based attacks and 2) Enable attacks to still occur when no feasible surrogate model exists. To modify GCG, the key change is that the authors maintain a min-max heap of possible adversarial suffix candidates, searching for word replacements on the best currently known suffix candidate. The authors also experiment with prompt initialization, finding that including the target as many times as fits to be useful. Finally, as a query-optimizer in a proxy-free setting with random tokens instead of gradients, the authors experiment with trying a word replacement once in each position, and then taking the best position and trying more word replacements there. The authors find they are able to generate targeted attacks, which transfer attacks cannot, and can attack real-world models with proxy-free attacks.
strength_weakness: strength_weakness: The primary weaknesses of this paper include a lack of comparisons against other black-box attacks (e.g., Andriushchenko et al., "Jailbreaking Leading Safety-Aligned LLMs with Simple Adaptive Attacks", and Lapid et al., "Open Sesame! Universal Black Box Jailbreaking of Large Language Models") on the proxy-free attacks. This also limits the technical novelty, as the attack as mostly a series of small changes to GCG. The other weakness is that this paper does not evaluate a wide variety of different types of LLMs - one of the themes is that the proposed attack is useful in settings where there is no good surrogate, so it would be nice to see how the attack does against transfer attacks across different families of LLMs.
questions: questions: How does the attack perform against Andriushchenko et al. and Lapid et al.?
How does the attack do against transfer attacks across different families of LLMs?
limitations: limitations: Adequately addressed.
paper_summary: paper_summary: This paper proposes a query-based adversarial prompt generation method. It eliminates the prior attack's dependence on adversarial transferability and local surrogate models. The attack can evade the OpenAI and Llama Guard safety classifiers with a near 100% success rate.
strength_weakness: strength_weakness: ## Originality
I don't have major concerns here. The technical modifications of the existing attack GCG seem simple, but the good results can justify them. It is suggested to summarize and highlight the technical challenges.

## Quality

**Q: The evaluation setting is quite confusing.**

1. The paper was a bit vague regarding the attack's objective. Is it for a general jailbreaking attack (like GCG) or just eliciting the model to repeat a given harmful content? This also makes it hard to understand the attack success rate -- when do we count an attack as successful?

2. The evaluations do not match the major contribution. In Section 4, most of the evaluations are focused on the surrogate-based attack on various settings, including the actual GPT-3.5 model (a side question is why GPT-4 was not included since a black-box attack should work regardless of the underlying model). The actual contribution, the surrogate-free attack, was only evaluated on open models and then a different task of content moderation. The paper did not justify why the surrogate-based attack was not evaluated in the latter settings, and why the surrogate-free attack was not evaluated in the former settings. Ideally, the primary attack is supposed to be evaluated against all involved settings, and the surrogate-based attack is provided as a reference or ablation study.


## Clarity

* L33-45. It was a bit confusing when you first called out the surrogate-free property, then switched to a surrogate-based attack, and only finally, the further optimization that removes the surrogate model.
* L64-66. The high success rates in black-box attacks against classification tasks depend on two factors: the number of queries and the threshold perturbation. Most black-box attacks have 100% success rates at the first few queries but the inputs are either pure noise or heavily perturbed.
* Figure 1b. Please use different styles to distinguish curves of different groups of proxy or target. Right now, it is very hard to tell what the figure conveys and what we can learn when comparing curves with the same proxy size.

## Significance
N/A
questions: questions: See weaknesses.
limitations: limitations: N/A

Comments: title: Response to rebuttal
comment: Thank you very much for your comments. I think that the paper makes a nice contribution and I'm keeping my positive score.
The author responses to my questions seem fair. I have updated my score accordingly.
Thanks for the response. Below is my understanding of the clarified contributions and evaluations, and my recommendation for adjusting the claims:
1. The main contribution remains a query-based attack and an effort to reduce the dependency on transferability.
2. The main technique is a better pre-filter based on an unaligned model; most evaluations are in this setting. However, this setting may not entirely remove the dependency on transferability, in the sense that it cannot be called surrogate-free or proxy-free attacks.
3. In some settings, the model-based filter can be eliminated, but the resulting surrogate-free attack is generally too expensive to run. Therefore, the claims of surrogate-free attacks should be tuned down.

After re-evaluating the paper based on the above breakdown, I'm borderline okay with the novelty justified by the performance, and strongly recommend the authors better articulate the technical challenges of 2.