GPTFuzz Optimization

GPTFuzz 최적화 · faster jailbreak discovery through KV-cache-aware scheduling

ORIGINAL SCHEDULERone mutation per seed, then cycle to the firstS1 S2 S3 S4 S1 S2 S3 S4 S1 S2 S3 S4each seed reappears four steps laterGPU memoryKVKVKVKV4 KV caches resident, one per seedtoo much memory to keep them allRESCHEDULEDall of a seed's mutations run consecutivelyS1 x repS2 x repS3 x reprep = query budget / number of seedsGPU memoryKV1 KV cache resident at a timecompute once, reuse, discardNever returning to a seed means its K,V is built once and freed, saving memory and time.

The mutator feeds on the same seed, so its attention keys and values never change. Cache them once and every mutation after is nearly free.

Author

  • Soren Nguia1

Affiliation

  1. Yonsei University · Security System Lab

Published

2024 · CSI4101 Software Capstone Design

Recognition

Grand Prize (최우수상), Yonsei CS Graduation Exhibition, Spring 2024

Built on

GPTFuzz · vLLM

TL;DR

GPTFuzzer is a fuzzer that mutates seed jailbreak templates to hunt for prompts that break an LLM's safety training. The bottleneck is throughput: every candidate template is a full forward pass, and the more candidates you can run, the more vulnerabilities you find. Working from GPTFuzzer's source, our team found that its mutator generates each new template from the same seed, so the seed's input tokens repeat on every mutation. That means the attention keys and values for those tokens can be computed once and reused.

The catch was the scheduler. The original ran one mutation per seed and then cycled back to the first seed, which would require holding every seed's KV cache resident in GPU memory at once to get any reuse, and a KV cache is large per token. We rescheduled it: give each seed a repetition count equal to the query budget divided by the number of seeds, run all of that seed's mutations consecutively, and never return to it. Each seed's K,V is built once, reused across its mutations, then discarded.

On the optimized fuzzer, processing 1008 queries dropped from about 7000 s to about 4900 s (roughly 7.0 s to 4.9 s per query), about 30% faster per query. With the speedup in hand, we swept the mutation temperature over 2464 runs; the expand method at temperature 0.5 and the generate-similar method at temperature 0.2 each produced 11 successful jailbreaks, the most of any configuration. The project won the Grand Prize (최우수상) at Yonsei's CS Graduation Exhibition.

Fuzzing jailbreaks is slow

A safety-tuned LLM refuses harmful requests, but a wrapper prompt can sometimes talk it into complying anyway. GPTFuzzer automates the search for such wrappers: it starts from a pool of human-written seed templates, mutates them with a helper LLM, tests each mutated template against the target model, and keeps the ones that work. The more candidate templates you can afford to test, the more of the target's safety gaps you surface. Speed is not a nicety here; it is the difference between finding a handful of jailbreaks and finding many.

Every candidate costs a forward pass through the mutator and the target, so the wall-clock budget caps how much of the space you can explore. Our capstone goal was narrow and practical: make GPTFuzzer meaningfully faster so that, in the same time, many more jailbreak prompts could be tried against the target and more of its vulnerabilities found. We chose to attack the cost of generation itself rather than the search policy on top of it.

The idea: KV-cache reuse

Reading through the GPTFuzzer source, the pattern that stood out is how the mutator builds a new template. It takes an existing seed template and asks a helper model to rewrite, expand, shorten, rephrase, or cross over from it. The instruction prefix and the seed body are the same tokens on every mutation of that seed; only the tail the model generates differs. In a transformer, the attention keys and values for a prefix depend only on that prefix, so if the prefix does not change, its K,V does not change either.

That is exactly the situation a KV cache is built for. Compute the seed prefix once, keep its keys and values, and every subsequent mutation of that seed reuses them instead of recomputing attention over the whole prefix. The saving grows with prefix length and with the number of mutations you draw from the same seed. The idea is not new to transformers; the contribution was recognizing that GPTFuzzer's mutation loop is a textbook case of a repeated prefix, and that its scheduling was the thing standing in the way of exploiting it.

The observation

Every mutation of one seed shares the same prefix tokens. Their attention K,V is identical across those mutations, so it should be computed once and reused, not recomputed per mutation.

Rescheduling so each cache lives once

Reuse only pays off if the cache is still around when the next mutation of the same seed runs. The original scheduler worked against that. It walked the seed pool round-robin: mutate seed 1 once, seed 2 once, and so on to the last seed, then loop back to seed 1. Under that order, seed 1's next mutation only comes around after every other seed has had a turn, so to reuse seed 1's K,V you would have to keep it, and every other seed's, resident in GPU memory the whole time. KV caches are large per token, and holding all of them at once is prohibitive.

The fix is a scheduling change, not a kernel change. Give each seed a fixed repetition count equal to the total query budget divided by the number of seeds, then run all of that seed's mutations back to back before moving on to the next seed, and never come back. Now a seed's prefix K,V is computed on its first mutation, reused across the rest of its consecutive block, and freed the moment the fuzzer advances to the next seed. Only one seed's cache is resident at any moment. The change saves memory, which was what made reuse feasible at all, and it saves time, because the recomputation the round-robin forced is gone.

rep = query_budget // num_seeds        # even split of the budget
for seed in seeds:                     # never revisit a seed
    kv = build_prefix_cache(seed)      # compute the seed's K,V once
    for _ in range(rep):
        mutate(seed, reuse=kv)         # every mutation reuses it
    free(kv)                           # discard before the next seed

Result: 30% faster per query

Measured on a fixed workload of 1008 queries, the scheduling change cut wall-clock time from about 7000 s to about 4900 s. Per query that is roughly 7.0 s down to 4.9 s, about 30% faster. Same fuzzer, same target, same query budget; the only difference is that seeds are processed in consecutive blocks so each KV cache is built once and reused instead of thrashed. Under the original round-robin, holding every cache at once was infeasible, so in practice the prefix was being recomputed; the reschedule is what turned the reuse from a memory impossibility into a real saving.

Wall-clock time for 1008 queries
0 s5000 sOriginal~7000 sRescheduled~4900 sabout 30% faster
~7.0 s per query~4.9 s per query
Figure 1: The scheduling change alone. Processing 1008 queries fell from about 7000 s to about 4900 s (about 7.0 s to 4.9 s per query), roughly 30% faster per query, with no change to the mutation prompt or the search policy.

Sweeping temperature per method

The speedup was a means, not the end: a faster fuzzer buys more experiments in the same budget. Using the optimized version, we swept the sampling temperature for each mutation method over 2464 runs (77 seeds, each mutated 32 times). The question was which method-and-temperature pairing surfaces the most jailbreaks. Two configurations tied for the lead: the expand method at temperature 0.5 and the generate-similar method at temperature 0.2, each producing 11 successful jailbreaks, more than any other pairing in the sweep.

Top configurations in the temperature sweep
012 jailbreaksexpand @ T=0.511generate-similar @ T=0.211
Figure 2: The two leading method-temperature pairings from a 2464-run sweep (77 seeds x 32). Each produced 11 successful jailbreaks, the most of any configuration. The sweep was only affordable because the fuzzer was faster.

Team, my role, honest scope

This was a team project. It was built by Team AIS, five members, for CSI4101 Software Capstone Design at Yonsei University in 2024, in the Security System Lab under Prof. Song Dokyung (송도경). This page is my own write-up of that shared work, and I want to be clear about which parts were mine rather than claim the whole.

My contributions were the GPTFuzzer source-code analysis that located the repeated-prefix pattern in the mutator, the KV-cache research behind the reuse idea, and the hyperparameter experiments, including the temperature sweep reported above. The scheduling redesign and the measurements were a group effort on top of that analysis. The report itself is a Korean-language capstone document; the figures on this page are rebuilt from scratch rather than lifted from it.

The project received the Grand Prize (Highest Excellence Award, 최우수상) at Yonsei's CS Graduation Exhibition in Spring 2024. It is built on the open-source GPTFuzzer and on vLLM, and the KV-cache reuse rests on the standard behaviour of transformer attention over a fixed prefix.

Limitations

Conclusion

The speedup came from reading the fuzzer carefully rather than from a heavier machine. GPTFuzzer mutates from a fixed seed, so the seed's attention keys and values are computed over and over for no reason; the only thing blocking reuse was a round-robin schedule that would have needed every seed's cache resident at once. Running each seed's mutations consecutively lets one cache live, be reused, and be freed, which is why the same 1008 queries finished about 30% faster. A faster fuzzer then paid for a temperature sweep that a slower one could not have afforded, and the whole effort won the Grand Prize at Yonsei's CS Graduation Exhibition. The lesson generalizes past this fuzzer: when the same tokens keep coming back, the schedule that decides when they come back is often the real bottleneck.