Overview
Optimization configuration controls Heretic’s automatic parameter search process. Heretic uses Optuna with a TPE (Tree-structured Parzen Estimator) sampler to co-minimize refusal count and KL divergence from the original model.Heretic’s optimization is fully automatic. You typically don’t need to change these settings, but they’re available for fine-tuning performance or experimenting with the abliteration process.
Optimization Trials
Heretic runs multiple abliteration trials to find optimal parameters. Each trial tests a different combination of ablation weights and directions.n_trials
The total number of optimization trials to run.50-100: Quick experiments, testing configuration changes200(default): Good balance of quality and speed300-400: Extensive search for challenging models
n_startup_trials
The number of initial trials that use random sampling for exploration, before the TPE optimizer takes over.- Startup trials should be approximately 25-30% of total trials
- After startup trials complete, TPE uses the results to guide further exploration
- Default: 60 startup trials out of 200 total (30%)
The startup phase explores the parameter space randomly. After that, Optuna’s TPE sampler uses Bayesian optimization to intelligently search for better parameters.
Batch Processing
Batch size controls how many input sequences are processed in parallel. Larger batches are faster but require more VRAM.batch_size
Number of input sequences to process simultaneously.0(default): Automatic detection - Heretic benchmarks your system at startup to find the optimal batch size1-128: Manual batch size - Use when you know your hardware’s limits
max_batch_size
The maximum batch size to try when automatically determining the optimal batch size.- Decrease if you have limited VRAM or run into OOM errors during benchmarking
- Increase if you have high VRAM and want to process larger batches for speed
KL Divergence Parameters
KL divergence measures how much the abliterated model differs from the original model. Heretic balances minimizing refusals with minimizing KL divergence to preserve the model’s capabilities.kl_divergence_scale
Assumed “typical” value of KL divergence for abliterated models. Used to ensure balanced co-optimization of KL divergence and refusal count.- This value normalizes KL divergence to be comparable to refusal count in the optimization objective
- Higher values make the optimizer prioritize reducing refusals over preserving model behavior
- Lower values make the optimizer prioritize preserving the original model’s behavior
The default value of
1.0 typically provides a good balance. You rarely need to change this unless you’re specifically trying to bias the optimization toward quality preservation or refusal reduction.kl_divergence_target
The KL divergence threshold below which the optimizer focuses on refusal count instead of KL divergence.0.005-0.01: Strict quality preservation0.01(default): Good balance0.02-0.05: More aggressive abliteration
Advanced Abliteration Parameters
These options control how the abliteration process modifies the model’s weight matrices.orthogonalize_direction
Whether to orthogonalize refusal directions relative to the “good” direction before ablation.- When enabled, Heretic adjusts the refusal directions so that only the component orthogonal to the “good” direction is subtracted
- This can help preserve beneficial model behaviors while removing refusals
- If standard abliteration degrades model quality too much
- When you want to be more conservative with modifications
- For models where “good” and “bad” directions are not well-separated
This is an advanced feature. The default (
false) works well for most models. Enable this if you’re experiencing significant quality degradation.row_normalization
How to apply row normalization to weight matrices during ablation.- "none" (default)
- "pre"
- "full"
No row normalization. Abliteration is applied directly to the weight matrices.Best for: Most models, standard use cases
full_normalization_lora_rank
The rank of the LoRA adapter when usingrow_normalization = "full".
- Higher rank: More accurate preservation of row magnitudes, but larger output files and slower evaluation
- Lower rank: Smaller files and faster evaluation, but less accurate approximation
- Default (3): Good balance for most use cases
Study Checkpoints
Heretic automatically saves optimization progress to disk, allowing you to resume interrupted runs.study_checkpoint_dir
Directory where optimization study progress is saved.- Trial history and results
- Best parameters found so far
- Optimization state (for resuming)
Complete Example Configurations
Performance Tips
Speed up optimization
Speed up optimization
- Reduce
n_trials(try 100 instead of 200) - Increase
max_batch_sizeif you have VRAM headroom - Use quantization:
quantization = "bnb_4bit" - Reduce evaluation dataset sizes (see Evaluation Configuration)
Improve result quality
Improve result quality
- Increase
n_trials(try 300-400) - Lower
kl_divergence_scale(try 0.5) - Lower
kl_divergence_target(try 0.005) - Enable
orthogonalize_direction = true - Use larger evaluation datasets
Reduce VRAM usage
Reduce VRAM usage
- Lower
max_batch_size(try 32 or 64) - Set manual
batch_sizeto a safe value - Enable quantization in model loading config
- Reduce
max_response_length(see Evaluation Configuration)
Troubleshoot optimization issues
Troubleshoot optimization issues
Problem: All trials produce similar results
- Increase
n_startup_trialsfor more exploration - Check if your refusal markers are appropriate
- Increase
kl_divergence_scaleto allow more aggressive ablation - Try
orthogonalize_direction = true
- Decrease
kl_divergence_scaleto prioritize quality - Lower
kl_divergence_targetto require better preservation - Try
row_normalization = "full"
Related Configuration
Model Loading
Configure batch sizes and memory usage
Evaluation
Configure datasets and response generation
