This repository evaluates the robustness of Large Language Models (LLMs) under various adversarial attacks, focusing on code generation tasks. We test both original and compressed LLMs across different datasets to provide comprehensive insights into model vulnerabilities.
Our framework provides:
We currently support the following models:
⌨️ Character Attack (char_attack)
🔄 Synonym Attack (synonym_attack)
🌐 Translation Attack (translate_attack)
We will support both original LLMs and their compressed versions.
🎯 Natural Noise Injection
🏗️ Structural Attacks
🔄 Semantic Preserving Transformations
We recommend using UV as the package installer for better dependency management and faster installation.
First, install UV using one of the following methods:
# For Linux/macOS with curl
curl -LsSf https://astral.sh/uv/install.sh | sh
# For Windows (PowerShell)
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# Using pip (recommended)
pip install uv
If you only need basic functionality only with bitsanddytes quantization support:
# Clone the repository
git clone https://github.com/yourusername/adversarial-codegen
cd adversarial-codegen
# Install the package with basic dependencies
uv pip install -e .
If you want to use all quantization features:
# Clone the repository
git clone https://github.com/yourusername/adversarial-codegen
cd adversarial-codegen
# Install PyTorch first
uv pip install torch>=2.5.1
# Install with quantization dependencies
uv pip install --no-build-isolation -e .[quant]
# Clone the repository
git clone https://github.com/yourusername/adversarial-codegen
cd adversarial-codegen
# Install PyTorch first to avoid build issues
uv pip install torch>=2.5.1
# Install all dependencies including quantization support
uv pip install --no-build-isolation -e .[all]
If you prefer using traditional pip:
# Clone the repository
git clone https://github.com/yourusername/adversarial-codegen
cd adversarial-codegen
# Install PyTorch first
pip install torch>=2.5.1
# Install all dependencies
pip install --no-build-isolation -e .[all]
Note: The --no-build-isolation flag is needed for proper installation of quantization dependencies like autoawq. UV is recommended over pip for its improved dependency resolution and installation speed.
After installation, you can use the main functionality through the command-line interface:
reval attack [OPTIONS]
# Attack original LLMs
reval attack \
--model_path /path/to/model \
--save_prompts /path/to/save/prompts \
--save_results /path/to/save/results
# Attack LLMs with a specific adversarial attack method (synonym) and generation method (temperature sampling).
reval attack \
--model_path /path/to/model \
--dataset mbpp \
--attack_method synonym \
----replacement_probability 0.2 \
--max_synonyms 5 \
--temperature 0.8 \
--top_p 0.9 \
--num_beams 5 \
--seed 42 \
--save_prompts /path/to/save/prompts \
--save_results /path/to/save/results \
--visualization True
# Attack LLMs with static quant (4-bit quant achieved by bnb)
reval attack \
--model_path /path/to/model \
--quantized_type static \
--quant_method bnb \
--quant_bits 4 \
--quant_type nf4 \
--save_prompts /path/to/save/prompts \
--save_results /path/to/save/results
# Attack LLMs with 8-bit quant
reval attack \
--model_path /path/to/model \
--quantized_type dynamic \
--quant_bits 8 \
--quantize_embeddings True \ # Generally don't quantize embedding layer
--save_prompts /path/to/save/prompts \
--save_results /path/to/save/results
The tool generates two types of outputs:
We welcome contributions! Please feel free to submit a Pull Request. For questions or suggestions, please contact:
This project builds upon and is inspired by several excellent works in the field:
Special thanks to all these projects that made our work possible.
This project is licensed under the MIT License - see the LICENSE file for details.
Python
94.3%
Shell
5.7%
This repository evaluates the robustness of Large Language Models (LLMs) under various adversarial attacks, focusing on code generation tasks. We test both original and compressed LLMs across different datasets to provide comprehensive insights into model vulnerabilities.
Our framework provides:
We currently support the following models:
⌨️ Character Attack (char_attack)
🔄 Synonym Attack (synonym_attack)
🌐 Translation Attack (translate_attack)
We will support both original LLMs and their compressed versions.
🎯 Natural Noise Injection
🏗️ Structural Attacks
🔄 Semantic Preserving Transformations
We recommend using UV as the package installer for better dependency management and faster installation.
First, install UV using one of the following methods:
# For Linux/macOS with curl
curl -LsSf https://astral.sh/uv/install.sh | sh
# For Windows (PowerShell)
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# Using pip (recommended)
pip install uv
If you only need basic functionality only with bitsanddytes quantization support:
# Clone the repository
git clone https://github.com/yourusername/adversarial-codegen
cd adversarial-codegen
# Install the package with basic dependencies
uv pip install -e .
If you want to use all quantization features:
# Clone the repository
git clone https://github.com/yourusername/adversarial-codegen
cd adversarial-codegen
# Install PyTorch first
uv pip install torch>=2.5.1
# Install with quantization dependencies
uv pip install --no-build-isolation -e .[quant]
# Clone the repository
git clone https://github.com/yourusername/adversarial-codegen
cd adversarial-codegen
# Install PyTorch first to avoid build issues
uv pip install torch>=2.5.1
# Install all dependencies including quantization support
uv pip install --no-build-isolation -e .[all]
If you prefer using traditional pip:
# Clone the repository
git clone https://github.com/yourusername/adversarial-codegen
cd adversarial-codegen
# Install PyTorch first
pip install torch>=2.5.1
# Install all dependencies
pip install --no-build-isolation -e .[all]
Note: The --no-build-isolation flag is needed for proper installation of quantization dependencies like autoawq. UV is recommended over pip for its improved dependency resolution and installation speed.
After installation, you can use the main functionality through the command-line interface:
reval attack [OPTIONS]
# Attack original LLMs
reval attack \
--model_path /path/to/model \
--save_prompts /path/to/save/prompts \
--save_results /path/to/save/results
# Attack LLMs with a specific adversarial attack method (synonym) and generation method (temperature sampling).
reval attack \
--model_path /path/to/model \
--dataset mbpp \
--attack_method synonym \
----replacement_probability 0.2 \
--max_synonyms 5 \
--temperature 0.8 \
--top_p 0.9 \
--num_beams 5 \
--seed 42 \
--save_prompts /path/to/save/prompts \
--save_results /path/to/save/results \
--visualization True
# Attack LLMs with static quant (4-bit quant achieved by bnb)
reval attack \
--model_path /path/to/model \
--quantized_type static \
--quant_method bnb \
--quant_bits 4 \
--quant_type nf4 \
--save_prompts /path/to/save/prompts \
--save_results /path/to/save/results
# Attack LLMs with 8-bit quant
reval attack \
--model_path /path/to/model \
--quantized_type dynamic \
--quant_bits 8 \
--quantize_embeddings True \ # Generally don't quantize embedding layer
--save_prompts /path/to/save/prompts \
--save_results /path/to/save/results
The tool generates two types of outputs:
We welcome contributions! Please feel free to submit a Pull Request. For questions or suggestions, please contact:
This project builds upon and is inspired by several excellent works in the field:
Special thanks to all these projects that made our work possible.
This project is licensed under the MIT License - see the LICENSE file for details.
Python
94.3%
Shell
5.7%