Skip to content

Getting started

SafeTune is a library of safety methods, not a pipeline. Each task has many independent methods that solve it by different mechanisms — you pick one per task.

New here, in order:

  1. Installationpip install safetune (Python ≥ 3.12, PyTorch), plus optional GPU extras.
  2. Quick Start — the same task through the Python API, the CLI, and a YAML config.
  3. Core Concepts — the 2-tier, input-keyed method taxonomy.

Just tell me what to use

Pick the path that matches your goal — each maps to one method:

flowchart TD
    Q{What do you need?}
    Q -->|Keep safety during FT| H[SafeGradTrainer · harden]
    Q -->|Restore drifted model| R[ReStaTrainer · recover]
    Q -->|Refuse at inference| S[RefusalDirectionTrainer · steer]
    Q -->|Remove a capability| U[RMUTrainer · unlearn]
    Q -->|Find where safety lives| I[identify_safety_neurons · interpret]
    Q -->|Measure safety| E[safetune.evaluate · evaluate]

Each pillar has runnable onramps in Examples (all default to Qwen/Qwen2.5-0.5B-Instruct) and a full walkthrough under the User Guide.

Go deeper

Core Concepts The 2-tier, input-keyed taxonomy (single source of truth)
User Guide Per-pillar usage guides with code snippets
API Reference Autodoc for every public trainer / function
Feature Map Per-method audit badges and faithfulness verdicts

If you're unfamiliar with the site layout, see How to Read These Docs for navigation tips.

Troubleshooting

CUDA out of memory

Train-time defenses (harden) can be memory-intensive. Lower the batch_size constructor argument on the harden trainer, or run on a smaller model.

Missing optional dependencies

The core install covers every method. Some backends (vLLM judge adapters, the faster steering / eval path) need extra packages — see Installation → Optional GPU extras.