Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Environment:Avdvg InjectGuard CUDA GPU

From Leeroopedia
Knowledge Sources
Domains Infrastructure, Deep_Learning, Security
Last Updated 2026-02-14 16:00 GMT

Overview

Python 3.x environment with CUDA-enabled GPU, LangChain 0.2.x, sentence-transformers, FAISS, and scikit-learn for vector similarity-based prompt injection detection.

Description

This environment provides the runtime context for the InjectGuard vector similarity detection pipeline. It requires an NVIDIA GPU with CUDA support for embedding model inference (the code hardcodes cuda:2 as the device). The software stack is built on LangChain for document loading and vector store management, sentence-transformers for producing text embeddings, FAISS for nearest-neighbor search, and scikit-learn for evaluation metrics.

The code executes GPU operations at module import time: loading the sentence-transformers model onto the GPU and building the FAISS index. This means the CUDA device must be available before the module is first imported.

Usage

Use this environment for running any part of the InjectGuard prompt injection detection pipeline. It is required by the HuggingFaceEmbeddings_Init implementation (embedding model loaded to GPU), the FAISS_From_Documents implementation (vector store construction using GPU-accelerated embeddings), and the Sim_Search implementation (query-time similarity search). Without a CUDA-capable GPU, the device configuration must be changed to cpu.

System Requirements

Category Requirement Notes
OS Linux (Ubuntu recommended) Windows/macOS not tested by the project
Hardware NVIDIA GPU with CUDA support Code hardcodes cuda:2; requires at least 3 CUDA-visible GPUs or modification of the device index
VRAM >= 1GB all-MiniLM-L6-v2 is a lightweight model (22M params, ~90MB); FAISS flat index is small for typical malicious prompt datasets
Disk >= 2GB For model download cache (HuggingFace Hub) and dataset storage
Python Python 3.8+ Required by LangChain 0.2.x and dependencies

Dependencies

System Packages

  • NVIDIA GPU driver (compatible with CUDA toolkit)
  • CUDA toolkit (version compatible with installed PyTorch)

Python Packages (from requirements.txt)

  • langchain == 0.2.13
  • langchain_community == 0.2.12
  • numpy == 2.0.1
  • scikit_learn == 1.5.1
  • tqdm == 4.66.5

Transitive Dependencies (not in requirements.txt)

  • torch (PyTorch) — required by sentence-transformers and FAISS GPU
  • sentence-transformers — required by LangChain HuggingFaceEmbeddings
  • faiss-cpu or faiss-gpu — required by LangChain FAISS vector store
  • transformers — required by sentence-transformers

Credentials

No API keys or environment variables are required. The embedding model (all-MiniLM-L6-v2) is downloaded from HuggingFace Hub without authentication. If Hub access is restricted, set:

  • HF_TOKEN: HuggingFace API token (Read access) — only if the Hub requires authentication

Quick Install

# Install declared dependencies
pip install langchain==0.2.13 langchain_community==0.2.12 numpy==2.0.1 scikit_learn==1.5.1 tqdm==4.66.5

# Install transitive dependencies (adjust torch for your CUDA version)
pip install torch sentence-transformers faiss-cpu
# For GPU-accelerated FAISS:
# pip install faiss-gpu

Code Evidence

Hardcoded CUDA device from vertor_similarity_detection.py:10-12:

embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2",
                                                model_kwargs={'device': 'cuda:2'},
                                                encode_kwargs={'normalize_embeddings':True})

Module-level vector store construction from vertor_similarity_detection.py:47:

vector_store = FAISS.from_documents(docs, embeddings)

Dependencies from requirements.txt:1-5:

langchain==0.2.13
langchain_community==0.2.12
numpy==2.0.1
scikit_learn==1.5.1
tqdm==4.66.5

Common Errors

Error Message Cause Solution
RuntimeError: CUDA error: invalid device ordinal System has fewer than 3 GPUs but code requests cuda:2 Change 'device': 'cuda:2' to 'device': 'cuda:0' or 'device': 'cpu'
ModuleNotFoundError: No module named 'sentence_transformers' sentence-transformers not installed (transitive dependency) pip install sentence-transformers
ModuleNotFoundError: No module named 'faiss' FAISS not installed (transitive dependency) pip install faiss-cpu or pip install faiss-gpu
RuntimeError: CUDA out of memory GPU VRAM insufficient (unlikely with MiniLM but possible if other processes consume VRAM) Free GPU memory or switch to CPU with 'device': 'cpu'
FileNotFoundError: ./dataset/malicious_data_demo.csv Malicious prompt dataset not present at expected path Provide a CSV file at ./dataset/malicious_data_demo.csv with columns id and text

Compatibility Notes

  • GPU Device Index: The code hardcodes cuda:2, assuming at least 3 CUDA-visible GPUs. Most single-GPU setups will need to change this to cuda:0.
  • CPU Fallback: The pipeline can run on CPU by changing model_kwargs={'device': 'cpu'}, but this will be slower for large datasets.
  • FAISS Variants: faiss-cpu and faiss-gpu are mutually exclusive packages. The LangChain FAISS wrapper works with either. For this small-corpus use case, faiss-cpu is sufficient.
  • Missing requirements.txt entries: torch, sentence-transformers, and faiss-cpu/faiss-gpu are not listed in requirements.txt but are required at runtime. This is a known gap in the project's dependency declarations.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment