Create virtual environment
conda create -n NGSD python=3.10
conda activate NGSD
Install dependencies
pip install -r requirements.txt
Install local packages
pip install -e ./peft
pip install -e ./just_eval
pip install rouge-score
API
API is needed for training or evaluation, we highly recommend you to export your key in ~/.bashrc.
Model Needed:
lmsys/vicuna-7b-v1.5meta-llama/Llama-2-7b-chat-hfmeta-llama/Llama-2-13b-chat-hfQwen/Qwen3-8BTinyLlama/TinyLlama-1.1B-Chat-v1.0We highly recommend to complete self-reflection via vllm_api but not coupled deeply in decoding code.
Hence, here is a demo to start your NGSD journey by using target model api.
CUDA_VISIBLE_DEVICES=0 python -m vllm.entrypoints.openai.api_server \
--model [your_model] \
--tensor-parallel-size 1 \
--max-logprobs 100 \
--port 8000 \
--max_model_len 2048 \
--host 0.0.0.0 \
--api_key [your_key]
Run NGSD as a demo, you should keep your api with the same model and port in the code. You can also choose your prefered Attacker/Defense,
python defense.py \
--model_name vicuna \
--attacker GCG \
--defender SelfInstinctSafeDecoding \
--GPT_API [your_api_key] \
--additional_save_suffix [your_designed_suffix] \
Create virtual environment
conda create -n NGSD python=3.10
conda activate NGSD
Install dependencies
pip install -r requirements.txt
Install local packages
pip install -e ./peft
pip install -e ./just_eval
pip install rouge-score
API
API is needed for training or evaluation, we highly recommend you to export your key in ~/.bashrc.
Model Needed:
lmsys/vicuna-7b-v1.5meta-llama/Llama-2-7b-chat-hfmeta-llama/Llama-2-13b-chat-hfQwen/Qwen3-8BTinyLlama/TinyLlama-1.1B-Chat-v1.0We highly recommend to complete self-reflection via vllm_api but not coupled deeply in decoding code.
Hence, here is a demo to start your NGSD journey by using target model api.
CUDA_VISIBLE_DEVICES=0 python -m vllm.entrypoints.openai.api_server \
--model [your_model] \
--tensor-parallel-size 1 \
--max-logprobs 100 \
--port 8000 \
--max_model_len 2048 \
--host 0.0.0.0 \
--api_key [your_key]
Run NGSD as a demo, you should keep your api with the same model and port in the code. You can also choose your prefered Attacker/Defense,
python defense.py \
--model_name vicuna \
--attacker GCG \
--defender SelfInstinctSafeDecoding \
--GPT_API [your_api_key] \
--additional_save_suffix [your_designed_suffix] \