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:
| Input | Default backend | Output |
|---|---|---|
.gguf file or GGUF directory | llama_cpp | Patched GGUF(s) + standalone realignment-lora.gguf |
| Safetensors directory or HF repo ID | vllm (on CUDA when installed, automatic fallback to hf_torch) | Baked native-precision safetensors copy + realignment-edit.npz |
Safetensors directory + --gguf <path> | llama_cpp | Uses the GGUF for fast capture/search, bakes into the full safetensors checkpoint |
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.ggufOn the first run, Lucid:
- Inspects the checkpoint or GGUF headers to detect architecture, layer count, writer tensors, sandwich post-norms, and chat template.
- 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/. - Captures last-token residual activations in both chat and think modes.
- Computes per-family refusal directions and selects the active layer range and SVD rank automatically.
- Runs a preflight check to confirm every edited component affects logits, then runs multi-objective search over refusals vs. KL divergence.
- 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:
| Budget | Trials | Search prompts (chat / think) | Best for |
|---|---|---|---|
fast | 20 | 24 / 8 | Quick tests and small models |
balanced | 45 | 40 / 16 | Default for most models |
thorough | 80 | 60 / 24 | Stubborn 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-cnThis 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:
| Task | What it targets |
|---|---|
refusal | Standard refusal removal (default) |
noslop | Reduces AI-slop clichés ("delve into", "tapestry", "it's worth noting", ...) |
nosyco | Reduces sycophancy ("you're absolutely right", "what a great question", ...) |
concise | Encourages shorter, more direct answers |
lucid tasks
lucid run ./model-Q8_0.gguf -o ./model-noslop-Q8_0.gguf --task noslopInteractive 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 --interactiveYou can also open a standalone chat session against any existing search run at any time:
lucid chat ./lucid_work --trial 144-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 --followLucid 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.txtOr 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,
)