Environment:Norrrrrrr lyn WAInjectBench Conda Python 39 CUDA Environment
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Deep_Learning, Security |
| Last Updated | 2026-02-14 16:00 GMT |
Overview
Linux environment with Python 3.9, CUDA 12.1, PyTorch 2.5.1, and the full WAInjectBench dependency stack managed via Conda.
Description
This environment provides the core runtime for all WAInjectBench workflows including text detection, image detection, embedding classifier training, and LLaVA fine-tuning. It is defined by the `environment.yml` file with the Conda environment named `pidefense`. The stack includes PyTorch 2.5.1 with CUDA 12.1 support, Hugging Face Transformers 4.56.1, OpenCLIP 3.1.0, sentence-transformers 5.1.0, scikit-learn 1.6.1, PEFT 0.17.1, accelerate 1.10.1, and bitsandbytes 0.43.3. The CUDA toolkit (11.7 via conda, 12.1 via pip wheels) provides GPU acceleration for all neural model inference and training.
Usage
Use this environment for all WAInjectBench tasks: running detectors (text and image), training embedding classifiers, and fine-tuning LLaVA models. It is the mandatory prerequisite for every Implementation page in this repository.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux (Ubuntu recommended) | Conda environment targets Linux x86_64 |
| Hardware | NVIDIA GPU with CUDA support | Minimum 8GB VRAM for inference; 24GB+ recommended for LLaVA fine-tuning |
| Hardware | CPU with sufficient RAM | 16GB+ RAM recommended for embedding training |
| Disk | 20GB+ SSD | For conda environment, model weights, and dataset storage |
Dependencies
System Packages (Conda)
- `python` = 3.9.19
- `cudatoolkit` = 11.7.0
- `cuda-runtime` = 12.1.0
- `cuda-libraries` = 12.1.0
- `numpy` = 1.26.4
- `scipy` = 1.11.4
Python Packages (pip)
- `torch` = 2.5.1+cu121
- `torchvision` = 0.20.1+cu121
- `transformers` = 4.56.1
- `accelerate` = 1.10.1
- `peft` = 0.17.1
- `bitsandbytes` = 0.43.3
- `open-clip-torch` = 3.1.0
- `sentence-transformers` = 5.1.0
- `scikit-learn` = 1.6.1
- `joblib` = 1.5.2
- `pillow` = 10.3.0
- `openai` = 1.108.0
- `spacy` = 3.7.2
- `huggingface-hub` = 0.34.4
- `safetensors` = 0.6.2
- `triton` = 3.1.0
- `tqdm` >= 4.67
Credentials
The following environment variables may be required depending on the detector used:
- `CUDA_VISIBLE_DEVICES`: Set automatically by entry-point scripts (`main_text.py`, `main_image.py`, `train/llava-ft.py`) to select the GPU.
- `TOKENIZERS_PARALLELISM`: Set to `"false"` by `train/llava-ft.py` to suppress Hugging Face tokenizer warnings.
Quick Install
# Create and activate conda environment
conda env create -f environment.yml
conda activate pidefense
Code Evidence
GPU availability check from `train/llava-ft.py:245`:
use_cuda = torch.cuda.is_available()
CUDA device selection from `main_text.py:50` and `main_image.py:57`:
os.environ["CUDA_VISIBLE_DEVICES"] = gpu
Tokenizer parallelism suppression from `train/llava-ft.py:3`:
os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
Device fallback in `train/embedding-i.py:75-77`:
device = torch.device(device if torch.cuda.is_available() else "cpu")
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `RuntimeError: CUDA out of memory` | Insufficient VRAM for LLaVA 7B model | Use `--device_mode single --gpu_id 0` or reduce `--batch_size`; the code auto-falls back to multi-GPU redispatch |
| `ImportError: No module named 'peft'` | PEFT not installed | `pip install peft>=0.17.1` |
| `No jsonl files found in the input directory.` | Wrong input path | Verify `--input_dir` / `--data_dir` points to directory containing `.jsonl` files |
Compatibility Notes
- CPU-only mode: The embedding classifiers (`embedding-t.py`, `embedding-i.py`) will fall back to CPU if no GPU is available. LLaVA fine-tuning requires a CUDA GPU.
- Multi-GPU: The `--device_mode auto` flag in `llava-ft.py` uses `accelerate.dispatch_model` for multi-GPU inference, but training defaults to single GPU.
- BF16 support: The LLaVA training script checks `torch.cuda.is_bf16_supported()` and falls back to FP32 if bfloat16 is unavailable.
Related Pages
- Implementation:Norrrrrrr_lyn_WAInjectBench_Conda_Environment_Setup
- Implementation:Norrrrrrr_lyn_WAInjectBench_SentenceTransformer_Init
- Implementation:Norrrrrrr_lyn_WAInjectBench_OpenCLIP_Init
- Implementation:Norrrrrrr_lyn_WAInjectBench_LlavaYesnoToken_Init
- Implementation:Norrrrrrr_lyn_WAInjectBench_try_wrap_lora
- Implementation:Norrrrrrr_lyn_WAInjectBench_force_single_gpu
- Implementation:Norrrrrrr_lyn_WAInjectBench_AdamW_Training_Loop
- Implementation:Norrrrrrr_lyn_WAInjectBench_LogisticRegression_Fit
- Implementation:Norrrrrrr_lyn_WAInjectBench_extract_embeddings
- Implementation:Norrrrrrr_lyn_WAInjectBench_SentenceTransformer_Encode