Enhanced fork of Heretic optimized for macOS (Apple Silicon) - 55% faster with LoRA fine-tuning and advanced optimizations.
Developed by Christopher Bradford (@sunkencity999)
Blasphemer removes censorship from transformer-based language models without expensive post-training, featuring automatic checkpoint/resume capabilities, LoRA fine-tuning for knowledge injection, streamlined GGUF conversion, and high-performance optimizations that reduce abliteration time by 55%.
📚 New to abliteration? Read LEARN.md - a comprehensive guide from beginner to expert!
Blasphemer builds on Heretic v1.0.1 with critical improvements for macOS users:
- LoRA Fine-Tuning: Train models on your custom knowledge (PDFs, text files, HuggingFace datasets) after abliteration
- High-Performance Optimizations: 55% faster abliteration with weight cloning, fast refusal detection, and torch.compile()
- Apple Silicon Support: Native MPS GPU detection and optimized memory management
- Enhanced Observability: Real-time quality metrics, trend analysis, and outcome predictions during optimization
- Checkpoint & Resume System: Automatic progress saving with SQLite - never lose hours of work to interruptions
- LM Studio Integration: One-command GGUF conversion with integrated llama.cpp
- Comprehensive Documentation: Complete user guide tailored for macOS workflows
- Improved Error Handling: Better dependency detection and helpful error messages
⚡ Phase 1 Optimizations (Enabled by Default):
- 55% faster abliteration - 7B models complete in ~80 minutes instead of ~180 minutes
- Weight cloning - 15x faster trial reset (2s vs 30s per trial)
- Fast refusal detection - 5x fewer tokens generated
- torch.compile() - 20-30% inference speedup on Apple Silicon (Python <3.14)
See PERFORMANCE_ANALYSIS.md for detailed benchmarks.
📖 Train models on your custom knowledge after abliteration:
- PDF documents - Extract and train on PDF content
- Text files - Use .txt, .md files directly
- Directories - Process entire folder trees
- HuggingFace datasets - Leverage existing datasets
- Efficient LoRA - Fast training, small adapters (50-500MB)
- Automatic merge - Ready for GGUF export
# Abliterate + Fine-tune in one workflow
blasphemer meta-llama/Llama-3.1-8B-Instruct \
--fine-tune-dataset ./my-documents/
# Fine-tune only (skip abliteration)
blasphemer model-name \
--fine-tune-only \
--fine-tune-dataset ./knowledge-base/Result: Uncensored model trained on your specific domain knowledge.
See FINETUNING.md for complete guide with examples.
# Resume interrupted runs automatically
blasphemer --resume meta-llama/Llama-3.1-8B-Instruct
# Convert to GGUF with one command
./convert-to-gguf.sh ~/models/your-model-heretic
# Checkpoints saved after every trial - Ctrl+C safe
# Performance optimizations enabled by default - no configuration neededInteractive Menu:
Clean, user-friendly menu for:
- Processing new models with optimized workflows
- Resuming interrupted runs from checkpoints
- Managing and deleting saved checkpoints
- Converting models to GGUF format
- Accessing help and documentation
Real-time Progress Display:
Live optimization feedback showing:
- Current trial progress with time estimates
- Best trial metrics (KL divergence, refusal rate)
- Quality bar visualization
- Trend analysis (improving/declining)
- Recent performance averages
- Expected outcome predictions
Heretic (the original project) combines advanced directional ablation with TPE-based parameter optimization to automatically remove safety alignment from language models. It works completely automatically, requiring no understanding of transformer internals.
Original Heretic by: Philipp Emanuel Weidmann (@p-e-w)
Research Paper: Refusal in Language Models Is Mediated by a Single Direction (Arditi et al. 2024)
Original Repository: https://github.com/p-e-w/heretic
Blasphemer maintains full compatibility with Heretic's core functionality while adding macOS-specific optimizations and user experience improvements.
# Add the tap and install
brew tap sunkencity999/blasphemer
brew install blasphemer
# Start using immediately
blasphemer.shBenefits:
- One command installation
- Automatic dependency management
- Easy updates with
brew upgrade - Clean uninstall with
brew uninstall
See HOMEBREW.md for detailed Homebrew documentation.
# Download and run the install script
curl -fsSL https://raw.githubusercontent.com/sunkencity999/blasphemer/master/install-macos.sh | bashOr download and run manually:
curl -O https://raw.githubusercontent.com/sunkencity999/blasphemer/master/install-macos.sh
chmod +x install-macos.sh
./install-macos.shFeatures:
- Checks all prerequisites automatically
- Verbose output with progress tracking
- Can resume if interrupted
- Handles errors gracefully
# Clone with submodules
git clone --recursive https://github.com/sunkencity999/blasphemer.git
cd blasphemer
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -e .
# Build llama.cpp for GGUF conversion
cd llama.cpp
cmake -B build
cmake --build build --config Release --target llama-quantize -j 8
cd ..# Run the interactive launcher - it guides you through everything
./blasphemer.shFeatures:
- Menu-driven interface with numbered options
- Automatic environment setup
- Guided model selection with recommendations
- Choose operations: process, convert, or resume
- Select quantization levels
- Pick save locations (with smart defaults)
- Configure advanced settings
Perfect for beginners and quick workflows!
# Activate environment
source venv/bin/activate
# Process a model (checkpoints automatic)
blasphemer meta-llama/Llama-3.1-8B-Instruct
# Convert to GGUF for LM Studio
./convert-to-gguf.sh ~/models/Llama-3.1-8B-Instruct-blasphemer
# Resume if interrupted
blasphemer --resume meta-llama/Llama-3.1-8B-Instruct# Using interactive launcher (recommended)
./blasphemer.sh
# Then select: Option 1 → Phi-3-mini
# Or command line
blasphemer microsoft/Phi-3-mini-4k-instructComplete User Guide: USER_GUIDE.md
Deep Learning Guide: LEARN.md ⭐ NEW!
The user guide covers:
- Installation and setup
- Model recommendations
- LM Studio integration
- Checkpoint system details
- Configuration options
- Troubleshooting
- Advanced usage
- Testing and development
From beginner to expert - Understand abliteration deeply:
- Philosophy & intellectual freedom
- Why models refuse (the neural mechanism)
- How abliteration works (mathematics & implementation)
- Parameter optimization (Bayesian methods)
- Code architecture deep dive
- Practical examples & troubleshooting
- Ethics & responsibility
- Research foundations
Perfect for: Anyone who wants to truly understand what they're doing, not just run commands
Blasphemer includes a comprehensive test suite to ensure reliability and prevent regressions.
# Activate environment
source venv/bin/activate
# Install pytest (if not already installed)
pip install pytest
# Run all tests
pytest tests/ -v
# Run specific test suites
pytest tests/unit/test_serialization.py -v
pytest tests/unit/test_utils.py -v
pytest tests/integration/test_checkpoint_system.py -v
# Run with coverage report
pytest tests/ --cov=src/heretic --cov-report=htmlUnit Tests (tests/unit/):
- JSON Serialization - Critical fix for AbliterationParameters storage
- Utility Functions - format_duration, batchify, empty_cache
- README Generation - Proper Blasphemer/Heretic attribution
- Configuration - Environment variables, checkpoint directories
Integration Tests (tests/integration/):
- Checkpoint System - SQLite database creation and resume functionality
- Environment Variables - BLASPHEMER_ prefix handling
- Model Naming - Consistent branding across outputs
Shell Script Tests (tests/scripts/):
- Script Validation - Syntax checking, executability
- Branding Consistency - Blasphemer references, no outdated Heretic refs
- Error Handling - Proper error traps and exit codes
- Help Functionality - All scripts provide usage information
✅ Critical Bug Fixes:
- JSON serialization of AbliterationParameters (prevents TypeError)
- --resume flag format (requires boolean argument)
- Bash 3.2 compatibility (macOS default shell)
✅ Core Functionality:
- Checkpoint creation and resumption
- Trial parameter storage and retrieval
- MPS (Apple Silicon) GPU detection
- Memory cache management
✅ Shell Scripts:
blasphemer.sh- Interactive launcherconvert-to-gguf.sh- GGUF conversioninstall-macos.sh- Installation script
✅ 10/10 serialization tests passing
✅ 14/15 utils tests passing (1 skipped - CUDA N/A on Apple Silicon)
✅ 10/10 checkpoint tests passing
✅ Shell scripts validated for syntax and brandingSee USER_GUIDE.md for detailed testing documentation.
One of Blasphemer's key features is automatic checkpoint/resume:
- Automatic: Saves progress after every trial to SQLite database
- Interruption-Proof: Safe to Ctrl+C, survive crashes and power failures
- Resume Anywhere: Continue exactly where you left off
- Zero Overhead: Checkpoint saves take <100ms
# Start processing (checkpoints automatic)
blasphemer your-model
# If interrupted, resume with --resume flag
blasphemer --resume your-model
# Checkpoints saved to .heretic_checkpoints/At most one trial is lost on interruption. For 15-hour runs with 200 trials, this means you can safely stop and resume at any time.
Blasphemer includes a streamlined GGUF conversion script:
# Default Q4_K_M quantization (good balance)
./convert-to-gguf.sh ~/models/your-model-heretic
# Higher quality Q5_K_M
./convert-to-gguf.sh ~/models/your-model-heretic output-name Q5_K_M
# View all options
./convert-to-gguf.sh| Type | Size (7B) | Quality | Use Case |
|---|---|---|---|
| Q4_K_M | ~4.5GB | Good | Recommended balance |
| Q5_K_M | ~5.3GB | Better | Higher quality |
| Q8_0 | ~8GB | High | Maximum quality |
| F16 | ~14GB | Full | No quality loss |
After conversion, models automatically appear in LM Studio's model list.
Phi-3 Mini (3.8B parameters) - Fast testing
blasphemer microsoft/Phi-3-mini-4k-instructQwen 2.5 7B - Excellent quality
blasphemer Qwen/Qwen2.5-7B-InstructLlama 3.1 8B (Most popular)
blasphemer meta-llama/Llama-3.1-8B-InstructMistral 7B v0.3 - High quality
blasphemer mistralai/Mistral-7B-Instruct-v0.3- Multimodal models (vision/audio) - require problematic dependencies on macOS
- Models > 70B parameters - require substantial resources
- SSMs/hybrid models (Mamba, etc.) - not supported by Heretic/Blasphemer
See USER_GUIDE.md for complete model recommendations.
# Custom number of trials
blasphemer --n-trials 100 your-model
# Custom checkpoint directory
blasphemer --checkpoint-dir /path/to/checkpoints your-model
# Auto-resume mode
blasphemer --resume your-model
# Evaluate existing model
blasphemer --model original --evaluate-model decensored
# Performance tuning (defaults are optimized)
blasphemer --compile-model true --refusal-detection-tokens 20 your-modelCreate config.toml from config.default.toml:
# Number of optimization trials
n_trials = 200
# Checkpoint directory
checkpoint_dir = ".heretic_checkpoints"
# Auto-resume if checkpoint exists
resume = false
# Batch size (0 = auto)
batch_size = 0
# Performance optimizations (enabled by default)
compile_model = true # 20-30% inference speedup
refusal_detection_tokens = 20 # 5x faster refusal detectionSee USER_GUIDE.md for all configuration options.
Blasphemer includes proper Apple Silicon GPU detection:
# Check GPU availability
python -c "import torch; print(f'MPS available: {torch.backends.mps.is_available()}')"Should output: MPS available: True
- Proper MPS cache clearing prevents memory buildup
- Weight cloning for fast trial resets (10-15x faster)
- Optimized for long runs with minimal overhead
- Automatic batch size detection for your hardware
With Phase 1 Optimizations (Enabled by Default):
On Apple Silicon M1/M2/M3:
- 7B models: ~80 minutes (was 180 min - 55% faster!)
- 14B models: ~120 minutes (was 240 min)
- torch.compile() provides 20-30% speedup on MPS backend (Python <3.14)
- Weight cloning eliminates model reload overhead (40% speedup alone)
- Fast refusal detection reduces token generation by 80%
Note: Python 3.14+ users get 40%+ speedup from weight cloning and fast refusal detection (torch.compile() not supported). First trial includes compilation warmup (~30-60s one-time cost) if using Python <3.14.
- macOS (Apple Silicon recommended)
- Python 3.10+
- 16GB RAM
- 50GB free disk space
- macOS with Apple Silicon (M1/M2/M3)
- Python 3.14+
- 32GB+ RAM
- 100GB+ free disk space
Like Heretic, Blasphemer uses activation engineering:
- Load Model: Downloads from Hugging Face or uses local model
- Calculate Directions: Analyzes refusal patterns using prompt datasets
- Optimize Parameters: Bayesian optimization finds best abliteration settings
- Evaluate Results: Tests KL divergence and refusal rates
- Present Options: Shows Pareto-optimal solutions for selection
Blasphemer adds automatic checkpointing throughout this process.
Contributions welcome! Areas of interest:
- macOS-specific optimizations
- Additional LM Studio integration features
- Performance improvements for Apple Silicon
- Documentation improvements
- Bug fixes and error handling
blasphemer/
├── README.md # This file
├── USER_GUIDE.md # Comprehensive documentation
├── LICENSE # AGPL-3.0
├── config.default.toml # Default configuration
├── convert-to-gguf.sh # GGUF conversion helper
├── pyproject.toml # Python project metadata
├── src/heretic/ # Source code (maintains compatibility)
│ ├── main.py # Entry point with checkpointing
│ ├── model.py # Model loading and abliteration
│ ├── config.py # Configuration management
│ ├── evaluator.py # Model evaluation
│ └── utils.py # Utilities with MPS support
└── llama.cpp/ # Git submodule for GGUF conversion
Blasphemer is a friendly fork that:
- Maintains compatibility with Heretic's core functionality
- Adds features specific to macOS and user experience
- Credits the original - all core abliteration logic is from Heretic
- Follows same license - AGPL-3.0
We encourage contributing improvements back to the original Heretic project when applicable.
# Run the validation test suite
cd /path/to/blasphemer
source venv/bin/activate
python test_phase1.pyExpected output:
✓ PASS: Configuration
✓ PASS: Weight Cloning
✓ PASS: torch.compile()
✓ PASS: Performance Timing
✓ ALL TESTS PASSED!
# Test on small model (5-10 minutes)
blasphemer microsoft/Phi-3-mini-4k-instruct --n-trials 10What to look for:
- Trial 1: "Saving clean model weights..." (optimization initializing)
- Trials 2+: "Restoring clean weights (fast)..." (optimization active!)
- Trial 2+ should complete 10-15x faster than trial 1
Expected timings on Apple Silicon M2:
| Model Size | Before Optimizations | With Phase 1 | Improvement |
|---|---|---|---|
| Phi-3-mini (3.8B) | ~45 min | ~20 min | 55% faster |
| Llama-3.1-8B (7B) | ~180 min | ~80 min | 55% faster |
| Mistral-7B | ~180 min | ~80 min | 55% faster |
See PERFORMANCE_ANALYSIS.md and QUICKSTART_PHASE1.md for details.
"No GPU detected" warning
- This is a display bug - MPS will still be used
- Verify with:
python -c "import torch; print(torch.backends.mps.is_available())"
Out of memory
- Reduce batch size:
blasphemer --max-batch-size 32 your-model - Try a smaller model
- Close other applications
Checkpoint won't resume
- Ensure using exact same model identifier
- Check
.heretic_checkpoints/directory exists - Verify checkpoint file not corrupted
llama.cpp conversion fails
- Ensure llama.cpp built successfully
- Check model path is correct
- Verify all dependencies installed
Performance optimizations not activating
- Look for "Saving clean model weights..." in trial 1
- Trials 2+ should show "Restoring clean weights (fast)..."
- Run validation:
python test_phase1.py - If needed, disable:
--compile-model false
"torch.compile is not supported on Python 3.14+"
- This is expected behavior - torch.compile() doesn't work on Python 3.14+
- The code automatically skips compilation and uses eager mode
- You still get 40%+ speedup from weight cloning and fast refusal detection
- To silence the message:
--compile-model falseor downgrade to Python 3.13
See USER_GUIDE.md for complete troubleshooting guide.
Major New Feature - Knowledge Injection:
- LoRA fine-tuning for custom knowledge training
- Support for PDFs, text files, directories, HuggingFace datasets
- Automatic dataset processing and chunking
- Efficient training (12-16GB RAM, 10-120 min depending on data)
- Automatic LoRA merge for GGUF export
- Interactive menu integration
- Comprehensive documentation (FINETUNING.md)
Workflow: Abliterate → Fine-tune → Export → Use in LM Studio
Phase 1 Optimizations - 55% Faster Abliteration:
- Weight cloning system - 15x faster trial reset (2s vs 30s)
- Fast refusal detection - 5x fewer tokens generated
- torch.compile() support - 20-30% inference speedup
- 7B models: ~80 minutes (was 180 min)
- All optimizations enabled by default
- Comprehensive performance analysis and benchmarking
Based on Heretic v1.0.1 with enhancements:
- Apple Silicon MPS support and detection
- Checkpoint/resume system with SQLite
- Integrated llama.cpp with GGUF conversion script
- Comprehensive USER_GUIDE.md documentation
- macOS-optimized workflows
AGPL-3.0 - Same as original Heretic
This ensures the community benefits from improvements while maintaining the open-source nature of the project.
- Philipp Emanuel Weidmann (@p-e-w) - Original Heretic author
- Arditi et al. - "Refusal in Language Models Is Mediated by a Single Direction" (2024)
- Optuna team - TPE-based optimization framework
- llama.cpp project - GGUF conversion tools
- Blasphemer Repository: https://github.com/sunkencity999/blasphemer
- Original Heretic: https://github.com/p-e-w/heretic
- Research Paper: https://arxiv.org/abs/2406.11717
- Example Models: https://huggingface.co/collections/p-e-w/the-bestiary
- llama.cpp: https://github.com/ggerganov/llama.cpp
- LM Studio: https://lmstudio.ai
Made with care for the macOS/Apple Silicon community. Blasphemer aims to make model decensoring accessible and reliable for everyone.

