Heretic
Heretic 源码分析:不猜测地追踪模型变换
用 fixture 阅读模型加载、残差采样、矩阵编辑、优化器、评估和产物路径。

你将学会
- Explain the KL/refusal optimization objective
- Run a pinned model experiment
- Design broader safety evaluation
开始前需要
- 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.
先看结论
- 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
固定 checkout 后用小模型或 mock 边界追踪 CLI、张量形状、模块发现、正交化、Optuna 目标、评估和保存;优先补充插值与溯源回归测试。
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.
如何选择
| 比较维度 | 方案 A | 方案 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 |
实施步骤
- 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.
可复制示例
fixture -> CLI validation -> model/tokenizer load
-> residual batches -> module registry
-> direction/kernel transform -> objective/eval
-> manifest + checkpoint常见问题
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.
资料来源
- Heretic README (captured 2026-08-31)来源核查 2026-08-31
- Heretic repository来源核查 2026-08-31