Heretic
Arquitectura de Heretic: direcciones residuales, kernels y Optuna
Del residual de prompts a la ortogonalización, búsqueda y visualización.

Qué aprenderás
- Explain the KL/refusal optimization objective
- Run a pinned model experiment
- Design broader safety evaluation
Antes de empezar
- Basic Git and command-line usage
- Comfort reading a project README
You can explain the project, run its documented first step, and decide what to verify before adopting it.
Conclusiones clave
- Prompt residuals and weight surgery are distinct stages.
- Float direction indices and flexible kernels enlarge the search space.
- The research visualization path is separate from model transformation.
A layered mental model
Separa captura de residuales, direcciones, edición de matrices, objetivo Optuna y gráficas PaCMAP; los índices por capa y flotantes amplían el espacio de búsqueda.
The special `per layer` direction index selects each layer's direction, while a float index interpolates between neighboring directions. This turns a discrete set of measured vectors into a larger search space, but also makes experiment provenance essential.
The ablation kernel
`max_weight`, `max_weight_position`, `min_weight`, and `min_weight_distance` describe a flexible weight shape over layers. Attention and MLP components receive separate parameters because the README reports that MLP interventions can damage capabilities more.
The optimization objective is a co-minimization: fewer refusals on harmful prompts and low KL divergence on harmless prompts. Neither term is a complete model-quality objective; add capability, calibration, bias, and misuse evaluations around it.
Research branch
Optional research features compute residual geometry, use PaCMAP to project layers, align consecutive projections, and emit PNG/GIF artifacts. Keep this CPU-heavy analysis off the critical transform path and preserve the source arrays or hashes used to create plots.
Cómo elegir
| Criterio | Opción A | Opción B |
|---|---|---|
| Best when | You need predictable behavior and easy auditing | You need adaptive optimization and have reliable telemetry |
| Main risk | May leave performance on the table | Can become difficult to explain or debug |
Pasos de implementación
- 1
Map residual collection and direction construction.
- 2
Trace matrix orthogonalization by component and layer.
- 3
Inspect Optuna parameters and objective metrics.
- 4
Separate plots, evaluation, and export from the transform core.
Ejemplo para copiar
harmful/harmless prompts
-> first-token residuals
-> layer directions
-> attention/MLP matrix orthogonalization
-> Optuna TPE (refusals + KL)
-> checkpoint + evaluationPreguntas frecuentes
Does Heretic edit every transformer layer equally?
No. It supports layer-specific directions and flexible, separately optimized weight kernels.
Is KL divergence a safety metric?
No. It measures deviation from the original model on a chosen prompt set; pair it with broader behavioral and human review.
Fuentes
- Heretic README (captured 2026-08-31)Fuente verificada 2026-08-31
- Heretic repositoryFuente verificada 2026-08-31