Skip to main content

AttackLM

PyPI version Python 3.10+ License: MIT Build Status

A high-performance QLoRA fine-tuning pipeline for creating MITRE ATT&CK-grounded security AI assistants.


Table of Contents


Quickstart

Get from zero to a trained security model in four commands:

# 1. Install the full training stack
pip install "attacklm[all]"

# 2. Initialize the MITRE-grounded dataset (downloads pre-built tarball)
attacklm init --yes

# 3. Balance the dataset to prevent source-bias (e.g., Metasploit overfitting)
attacklm balance

# 4. Launch training on Qwen2.5-Coder
attacklm train -- --dataset all --epochs 5 --train

Installation Guide

Prerequisites

  • OS: Linux (Ubuntu recommended) or WSL2
  • Python: 3.10+
  • Hardware: NVIDIA GPU with 8GB+ VRAM (RTX 30-series/40-series) or AMD ROCm compatible GPU.

Installation

Install based on your hardware acceleration preference:

NVIDIA CUDA (Recommended)

pip install "attacklm[all]"
# OR using uv for faster installation
uv pip install "attacklm[all]"

AMD ROCm

pip install "attacklm[all-rocm]"

Verification

attacklm --version

Memory Optimization: Flash-Attention vs. SDP

AttackLM is designed for maximum accessibility without sacrificing the efficiency of modern attention mechanisms.

The Problem with flash-attn Traditional flash-attn installations require a full CUDA toolkit, specific NVCC versions, and lengthy source compilation, which frequently fails in constrained environments or varying OS versions.

The AttackLM Solution: Memory Efficient SDP By default, AttackLM leverages PyTorch's built-in torch.backends.cuda.enable_mem_efficient_sdp().

  • Technical Advantage: It implements the same $\mathcal{O}(1)$ tiled algorithm as FlashAttention.
  • VRAM Impact: At a sequence length of 12,000, a standard $\mathcal{O}(n^2)$ attention matrix would consume ~8GB of VRAM just for the matrix. Memory Efficient SDP keeps this overhead constant.
  • Zero Friction: No compilation required. It works natively across all supported PyTorch/CUDA environments.

Note: If you have a perfectly configured environment and want the absolute maximum throughput, you can still install the standalone flash-attention: pip install "attacklm[flash-attn]".


Features

  • Comprehensive Security Corpus: 24,652 high-quality training pairs across 18 distinct security sources.
  • Advanced Training Methods: Support for QLoRA, GaLore, Q-GaLore, Spectrum, and PiSSA to enable training of large models on consumer hardware.
  • Training Pair Evolution: New capability to synthetically expand short, factual pairs into complex reasoning examples using three specialized strategies:
Strategy Approach Impact
Evol-Instruct Rewrites responses with deeper reasoning and edge cases 3-5x increase in response length/depth
Multi-turn Decomposes Q&A into interactive conversations Improved conversational flow and context
CoT Injection Adds explicit "Chain-of-Thought" reasoning steps Higher logical consistency in complex tasks
  • Zero-Config Setup: One-shot init command that handles dataset retrieval, extraction, and bucket organization.
  • Anti-Bias Balancing: Integrated balancing engine to ensure the model learns diverse tactics rather than just the most voluminous sources.
  • Provenance Tracking: Strict per-source attribution and license tracking for every record in the dataset.
  • Terminal GUI: A professional Textual-based TUI for managing training runs without memorizing 40+ CLI flags.
  • Deployment Ready: Built-in merge and conversion pipeline to export adapters to GGUF format for LM Studio or Ollama.
  • Rock-Solid Stability: 26/26 core tests passing.

Usage

Dataset Management

attacklm init Initialize the environment. Downloads the pre-built dataset for instant use.

attacklm init --yes

attacklm balance Create a balanced training subset to ensure tactical coverage.

attacklm balance --profile 7b-16gb --preset red-team

Model Training

attacklm train The core training engine. Supports Qwen2.5-Coder 3B and 7B base models.

Standard Training

# Train a single model on the entire balanced dataset
attacklm train -- --dataset all --epochs 10 --lora-r 16 --use-galore

Training with Evolved Pairs Use the --evolved-ratio flag to mix synthetically evolved high-reasoning pairs into your training set.

# Train with 20% evolved pairs for better reasoning depth
attacklm train -- --dataset all --evolved-ratio 0.2 --epochs 10

Deployment & Testing

attacklm build Merge LoRA adapters and convert to GGUF for local deployment.

attacklm build -- --adapter models/attacklm-single_TIMESTAMP --name attacklm-security

attacklm infer Perform a smoke-test of the trained model against representative security prompts.

attacklm infer -- --adapter models/attacklm-single_TIMESTAMP

Specialized Tools

  • attacklm eval: Run the retention evaluation suite and score candidate models.
  • attacklm gui: Launch the Terminal GUI for an interactive training experience.
  • attacklm demo: Run the multi-agent orchestrator demo.

Dataset & Attribution

The dataset is meticulously partitioned into "buckets" to allow granular control over training composition.

Core Composition

Category Source Examples Approx. Pairs License
Offensive Metasploit, Atomic Red Team 15,000+ BSD-3 / MIT
Defensive Sigma, Elastic, Splunk 7,000+ DRL-1.1 / Apache-2.0
AI Security Garak, Promptfoo 100+ Mixed
Meta/IR NIST IR, Orchestrator 500+ Public Domain

Total Records: 24,652
Base Models: Qwen2.5-Coder (3B, 7B)

For a complete mapping of every record to its original source and license, see ATTRIBUTION.md.


Architecture

AttackLM employs a deterministic pipeline that separates raw data extraction from training logic.

AttackLM/
├── data/
│   └── datasets/
│       └── buckets/
│           └── sources/
│               └── <source>/
│                   └── <bucket>/
│                       └── <tactic>/
│                           └── data.jsonl

This hierarchy ensures that the pipeline can be rebuilt from upstream sources without introducing hallucinations, while allowing the balance command to target specific tactics or sources for weighted sampling.


CLI Reference

Command Description
attacklm train Train a model (QLoRA, GaLore, Q-GaLore, Spectrum, PiSSA)
attacklm train --dataset all Train all buckets combined
attacklm train --evolved-ratio 0.2 Mix evolved reasoning pairs into training
attacklm train --hpo Run Hyper-Parameter Optimization sweep
attacklm init Initialize dataset: download pre-built or clone $\rightarrow$ extract $\rightarrow$ attribute
attacklm balance Build a balanced subset of buckets to prevent overfitting
attacklm build Merge adapter $\rightarrow$ GGUF conversion $\rightarrow$ LM Studio/Ollama register
attacklm infer Smoke-test inference on trained adapters
attacklm eval Run retention evaluation and regression gates
attacklm gui Launch Terminal GUI (TUI) for all operations
attacklm demo Run multi-agent orchestrator demo

License & Contributing

Code License: This project is licensed under the MIT License.

Data License: Training data consists of mixed licenses per source. Please refer to ATTRIBUTION.md for the full legal mapping.

Contributing: We welcome contributions to the extraction pipeline and training methods. See CONTRIBUTING.md for guidelines.

History: For a full list of changes and version milestones, see CHANGELOG.md.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

attacklm-0.8.3.tar.gz (5.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

attacklm-0.8.3-py3-none-any.whl (526.3 kB view details)

Uploaded Python 3

File details

Details for the file attacklm-0.8.3.tar.gz.

File metadata

  • Download URL: attacklm-0.8.3.tar.gz
  • Upload date:
  • Size: 5.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for attacklm-0.8.3.tar.gz
Algorithm Hash digest
SHA256 80851c78a4e873dfe3841b20f47010999ceb305622a82a30bd3a11f54f4741cc
MD5 a65f2084087ecf2a634ec6877fd4fe5f
BLAKE2b-256 b6f9cc40b3d061871b7b89f07ad55770d736b05f6f7e80c3e7694af5827f84fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for attacklm-0.8.3.tar.gz:

Publisher: release.yml on Veedubin/AttackLM

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file attacklm-0.8.3-py3-none-any.whl.

File metadata

  • Download URL: attacklm-0.8.3-py3-none-any.whl
  • Upload date:
  • Size: 526.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for attacklm-0.8.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4d6b0f585b26a2bbbf57b0c0b4ee5c5c03d5175f0f7c417beeef8b6987ec9a55
MD5 f131230cae48393ae2181053f8f76958
BLAKE2b-256 404552d9c3f432b38aef74a3a2f12959949dd161d72d200be4aa0019744b1a07

See more details on using hashes here.

Provenance

The following attestation bundles were made for attacklm-0.8.3-py3-none-any.whl:

Publisher: release.yml on Veedubin/AttackLM

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page