Heretic
Heretic Source-Code Analysis: Read the Transform Without Guessing
A fixture-first method for tracing Heretic's model loading, residual sampling, matrix edits, optimizer, evaluation, and artifact paths.

What you will learn
- Explain the KL/refusal optimization objective
- Run a pinned model experiment
- Design broader safety evaluation
Before you start
- 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.
Key takeaways
- A fixture-first trace exposes contracts without expensive GPU runs.
- Tensor/device/module support is a key correctness boundary.
- Small interpolation and provenance tests are safer first contributions.
Start with symbols and fixtures
Pin a checkout and create a tiny local model fixture or mocked boundary before reading the full implementation. Locate CLI argument parsing, model loading, prompt batching, supported module discovery, orthogonalization, Optuna objective code, evaluation, and save/upload actions.
The README is a map, not proof of every call path. Confirm assumptions against source symbols, tests, logs, and the exact dependency versions in `uv.lock`.
Trace one run
Follow one model identifier from validation to tokenizer/model load, residual collection, parameter application, evaluation prompts, and checkpoint writing. Record tensor shapes, dtype/device movement, layer names, and failure behavior. A useful trace distinguishes a refusal count, a KL sample, a timeout, and a malformed generation.
Test `per layer` and interpolated direction indices independently. Also inspect how quantization and multimodal or MoE model branches affect supported modules rather than assuming dense-model behavior generalizes.
Safe contributions
Prefer deterministic tests for direction interpolation, kernel boundaries, unsupported architectures, prompt-set validation, checkpoint provenance, and redaction. Keep live model downloads and uploads out of unit tests.
Decision guide
| Criterion | Option A | Option 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 |
Implementation steps
- 1
Pin checkout and dependencies.
- 2
Trace CLI to model load and residual tensors.
- 3
Follow matrix edits, objective, evaluation, and save paths.
- 4
Add a focused regression with a local fixture.
Copy-ready example
fixture -> CLI validation -> model/tokenizer load
-> residual batches -> module registry
-> direction/kernel transform -> objective/eval
-> manifest + checkpointFrequently asked questions
Can README text establish internal implementation details?
No. Use it to navigate, then verify symbols, tests, and runtime traces in the pinned checkout.
How can I avoid downloading large models while reading code?
Use static analysis, tiny synthetic modules, and mocked loader/evaluation boundaries.
Sources
- Heretic README (captured 2026-08-31)Source checked 2026-08-31
- Heretic repositorySource checked 2026-08-31