Getting Started

Install Lucid and run your first abliteration.

Installation

Lucid's core package only requires numpy and jinja2. All native-precision codecs (BF16, FP8 E4M3, UE8M0, NVFP4, MXFP8) and GGUF binary I/O work out of the box with pure NumPy.

# Core install
pip install lucid-toolkit

# Recommended: adds Optuna search, gguf-py, ml_dtypes, matplotlib, huggingface_hub, PyYAML
pip install "lucid-toolkit[all]"

# Recommended on Linux + CUDA: fast continuous-batched vLLM sampling + HF capture/baking
pip install "lucid-toolkit[all,vllm]"

# Optional: run capture and search directly on non-GGUF PyTorch / Hugging Face checkpoints
pip install "lucid-toolkit[all,torch]"

# Optional: 4-bit NF4 loading on PyTorch (fits larger models on a single GPU)
pip install "lucid-toolkit[all,torch,bnb]"

Choosing a workflow

Lucid selects the right backend automatically based on the model path you pass:

InputDefault backendOutput
.gguf file or GGUF directoryllama_cppPatched GGUF(s) + standalone realignment-lora.gguf
Safetensors directory or HF repo IDvllm (on CUDA when installed, automatic fallback to hf_torch)Baked native-precision safetensors copy + realignment-edit.npz
Safetensors directory + --gguf <path>llama_cppUses the GGUF for fast capture/search, bakes into the full safetensors checkpoint
Tip

For models larger than ~32B, the hybrid workflow (lucid run ./Model-FP8 --gguf ./Model-Q6_K.gguf -o ./Model-FP8-abliterated) is dramatically faster and cheaper than running full-precision PyTorch search.

One-command run

lucid run ./model-Q8_0.gguf -o ./model-abliterated-Q8_0.gguf

On the first run, Lucid:

  1. Inspects the checkpoint or GGUF headers to detect architecture, layer count, writer tensors, sandwich post-norms, and chat template.
  2. Downloads and caches the default prompt dataset (mrfakename/harm: 1,600 capture prompts, 100 harmful eval prompts, 100 harmless eval prompts) under ~/.cache/lucid/datasets/.
  3. Captures last-token residual activations in both chat and think modes.
  4. Computes per-family refusal directions and selects the active layer range and SVD rank automatically.
  5. Runs a preflight check to confirm every edited component affects logits, then runs multi-objective search over refusals vs. KL divergence.
  6. Verifies the selected Pareto knee at full generation length, bakes or patches the output weights, and writes a model card (README.md).

Common options

Search budget

Use --budget instead of manually tuning trial counts and token lengths:

BudgetTrialsSearch prompts (chat / think)Best for
fast2024 / 8Quick tests and small models
balanced4540 / 16Default for most models
thorough8060 / 24Stubborn or reasoning-heavy models

Secondary topic arm (--include-cn)

For models trained with additional regional topic filters (including narrative reframing rather than outright refusals), pass --include-cn:

lucid run ./model-Q8_0.gguf -o ./out.gguf --include-cn

This downloads the secondary topic prompts from mrfakename/harm and enables reframe detection alongside standard refusal markers during search and verification.

Behavior task presets (--task)

Besides standard refusal removal (--task refusal), Lucid ships built-in contrastive prompt sets and judges for common style behaviors:

TaskWhat it targets
refusalStandard refusal removal (default)
noslopReduces AI-slop clichés ("delve into", "tapestry", "it's worth noting", ...)
nosycoReduces sycophancy ("you're absolutely right", "what a great question", ...)
conciseEncourages shorter, more direct answers
lucid tasks
lucid run ./model-Q8_0.gguf -o ./model-noslop-Q8_0.gguf --task noslop

Interactive trial testing (--interactive)

By default lucid run automatically picks the knee of the Pareto frontier and finishes without prompting. Pass --interactive to pause after search so you can inspect the frontier table, live-chat with any candidate trial or the base model, compare two trials side by side on the same prompt, and pick which trial to bake:

lucid run ./model-Q8_0.gguf -o ./out.gguf --interactive

You can also open a standalone chat session against any existing search run at any time:

lucid chat ./lucid_work --trial 14

4-bit and VLM checkpoints on PyTorch

When using the hf_torch backend, pass --load-in-4bit to load the model in NF4 via bitsandbytes during capture and search, while still baking the final edit into the full-precision safetensors checkpoint on disk. Vision-language models (such as Gemma 3, Qwen2.5-VL, and Pixtral) are detected automatically via AutoModelForImageTextToText and their nested text decoder layers are hooked directly. Batch sizes default to automatic CUDA OOM probing (--batch-size 0), or you can pass an explicit integer.

Running on Hugging Face Jobs (lucid hf-job)

If you don't have a local GPU, you can launch a full end-to-end abliteration from a source Hugging Face repo to a destination Hugging Face repo with a single command:

# Make sure you're logged in first (`hf auth login` or `export HF_TOKEN=hf_...`)
lucid hf-job Qwen/Qwen3-8B your-username/Qwen3-8B-Lucid --flavor a100-large --follow

Lucid spins up a GPU worker on Hugging Face Jobs, pulls the source model, runs capture, search, verification, and error-diffused baking, writes a model card linked to base_model, and pushes the resulting checkpoint to your destination repo.

Useful options:

# See recommended GPU flavors and VRAM tiers
lucid hf-job flavors

# Fit a larger model on a single A100 using 4-bit search + full-precision baking
lucid hf-job Qwen/Qwen3-32B your-username/Qwen3-32B-Lucid --flavor a100-large --load-in-4bit --private

# Preview the job spec and equivalent `hf jobs run` command without submitting
lucid hf-job Qwen/Qwen3-8B your-username/Qwen3-8B-Lucid --dry-run

# Or emit a standalone PEP 723 UV script for `hf jobs uv run`
lucid hf-job Qwen/Qwen3-8B your-username/Qwen3-8B-Lucid --emit-script run_lucid.py

# Check status, stream logs, or cancel later
lucid hf-job status <job_id>
lucid hf-job logs <job_id> --follow
lucid hf-job cancel <job_id>

Or trigger it from Python:

import lucid

job = lucid.run_hf_job(
    "Qwen/Qwen3-8B",
    "your-username/Qwen3-8B-Lucid",
    flavor="a100-large",
    budget="balanced",
    follow=True,
)
print(job.url)

Targeting a custom behavior

You can target any contrastive behavior by supplying two plain-text files (one prompt per line):

lucid run ./MyModel -o ./MyModel-realigned --bad ./sycophantic.txt --good ./neutral.txt

Or pass a custom judge directly from Python:

import lucid

judge = lucid.FunctionJudge(lambda text: "you're absolutely right" in text[:200].lower())
lucid.realign(
    "./MyModel",
    output="./MyModel-realigned",
    bad_prompts=open("sycophantic.txt").read().splitlines(),
    good_prompts=open("neutral.txt").read().splitlines(),
    judge=judge,
)

Edit this page on GitHub