GraySwanAI / nanoGCG

A fast + lightweight implementation of the GCG algorithm in PyTorch
MIT License
111 stars 27 forks source link

Support for multi-prompting #21

Open GianlucaDeStefano opened 1 month ago

GianlucaDeStefano commented 1 month ago

Hi, from what I gather, nanoGCG does not yet support multi-promp optimizations. Is this feature going to be implemented?

ceferisbarov commented 1 month ago

AFAIK, the original algorithm is designed to work with a single prompt. You would have to revise the algorithm to make this work. I am working on something like that:

https://github.com/ceferisbarov/nanoGCG/tree/batch

You can check the README for code samples (other parts of README are not updated). The code is not polished yet, but it should work.

justinwangx commented 1 month ago

this is something we're thinking about adding. the original codebase released with the paper supports multi-prompt optimization -- this is the "universal" element in the title of the GCG paper.

justinwangx commented 1 month ago

it wouldn't be difficult to add (we simply need to aggregate gradients over all the prompts in our multi-prompt optimization). there's just added complexity when it comes to, for example, storing prefix caches for all the prompts if using prefix caching. not sure if the feature is worth the added complexity in the code.

ceferisbarov commented 1 month ago

@justinwangx Yes, I have seen the original repo, but I think it would also be nice to have a "nano" implementation. Maybe we can keep it as a separate branch for now.

zhxieml commented 2 weeks ago

+1. The original repo is too messy and it would be awesome to support multi-prompt optimization here.