GraySwanAI / nanoGCG

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

Support for multi-prompting #21

Open GianlucaDeStefano opened 2 months ago

GianlucaDeStefano commented 2 months ago

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

ceferisbarov commented 2 months 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 2 months 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 2 months 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 2 months 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 1 month ago

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

kuantuna commented 3 weeks ago

I've implemented multi-prompting here in my fork. It's not optimized and there may be bugs but you guys are welcome to use until it's added.