Implementation:Norrrrrrr lyn WAInjectBench Conda Environment Setup
| Knowledge Sources | |
|---|---|
| Domains | Environment_Management, GPU_Computing |
| Last Updated | 2026-02-14 16:00 GMT |
Overview
Concrete tool for provisioning a reproducible Python environment and selecting GPU devices, provided by conda and the os standard library.
Description
The WAInjectBench project uses a single environment.yml file (315 lines) that specifies all conda and pip dependencies needed across the entire benchmark. At runtime, both main_text.py and main_image.py accept a --gpu CLI argument and set os.environ["CUDA_VISIBLE_DEVICES"] before any CUDA-dependent library is imported.
Usage
Run conda environment creation once before first use. The GPU selection happens automatically each time an experiment script is invoked via the --gpu argument.
Code Reference
Source Location
- Repository: WAInjectBench
- File: environment.yml (L1-315), main_text.py (L50), main_image.py (L57)
Signature
# Environment creation (CLI)
conda env create -f environment.yml
conda activate wainjectbench
# GPU selection (runtime)
os.environ["CUDA_VISIBLE_DEVICES"] = gpu # gpu: str, e.g. "0" or "0,1"
Import
import os
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| environment.yml | File | Yes | Conda environment specification with pinned dependencies |
| gpu | str | Yes | CUDA device ID(s), passed via --gpu CLI argument (default "9" for text, "0" for image) |
Outputs
| Name | Type | Description |
|---|---|---|
| Conda environment | Virtual environment | Activated environment with all packages installed |
| CUDA_VISIBLE_DEVICES | Environment variable | Restricts GPU visibility for the current process |
Usage Examples
Full Setup
# 1. Create the conda environment from the spec file
conda env create -f environment.yml
# 2. Activate the environment
conda activate wainjectbench
# 3. Run a text detection experiment on GPU 0
python main_text.py --detector promptguard --gpu 0
# 4. Run an image detection experiment on GPU 1
python main_image.py --detector embedding-i --gpu 1