mirror of
https://github.com/p-e-w/heretic.git
synced 2026-12-03 18:42:57 +07:00
[GH-ISSUE #333] Suggestion: start-end layer probes before start #181
Labels
No labels
bug
enhancement
enhancement
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
p-e-w/heretic#181
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kabachuha on GitHub (May 27, 2026).
Original GitHub issue: https://github.com/p-e-w/heretic/issues/333
Currently, in the processes such as ARA Heretic optimizes for six parameters
Parameters:
While the four latest are mathematical and ARA related, the first two seem to be offtopic and they are completely independent from ARA, potentially hindering its optimization landscape.
I wonder if Heretic can firstly perform a brief optimal start end layers fit check and only then proceed to refine the math coefficients of ARA.
@p-e-w commented on GitHub (May 27, 2026):
How would that work? The layer range is NOT independent from the other parameters because we optimize for the overall model behavior. All parameters are interrelated.
We could try heuristics like discarding layers that have low silhouette scores on the residual vectors, indicating that the layer doesn't clearly distinguish refusals from non-refusals, but that is at best a rough first guess.
@umran666 commented on GitHub (Jun 18, 2026):
Building on what @p-e-w said: a two-phase optimization guarantees we get trapped in a local minimum. The layer ranges are completely mathematically entangled with the recovery coefficients.
Here's why: the depth of the ablation fundamentally changes the geometry of the required correction. Early layers heavily encode syntax and shallow semantics; if you ablate there, you need a massive
preserve_good_behavior_weightto prevent the model from degrading into gibberish. Late layers encode crystallized safety concepts; ablating there requires a completely different balance, usually a much highersteer_bad_behavior_weight.If we run a "brief optimal start/end layer fit check" using default static coefficients, the optimizer will simply gravitate toward a safe, middle-ground layer range that happens to survive the default weights. By the time the second phase starts refining the math coefficients, the optimization landscape has already been artificially bottlenecked into a suboptimal layer range. They have to be solved jointly.
@rocker-zhang commented on GitHub (Jun 22, 2026):
I tested this. Master samples the global
direction_indexfrom[0.4, 0.9] * last_layer. I compared that fixed range against restricting it to the "silhouette band" — the contiguous layers whose silhouette score is at least 90% of the per-layer peak. Same seed, budget, and TPE settings for both arms, 150 trials, 3 seeds each, run locally, thinking disabled where the model supports it so first-token KL stays meaningful.One thing to flag up front: this is the
direction_indexselection in the default method, not the ARAstart/end_layer_indexwindow the original post was about. The same silhouette-as-prior idea may carry over to that window, but I haven't tested it there.The band isn't uniformly a win: clear on Qwen3, a small loss on the other two. What separates the three is the absolute height of the silhouette peak, not its shape. A high peak means the layers genuinely separate refusals, so narrowing to the band is trustworthy; a low peak means the band is a noisy guide and the broad fixed range is safer.
That points to an adaptive rule rather than always-on: use the band only when its peak clears a threshold, otherwise keep
[0.4, 0.9] * last. With three models this is just a separating cut — anything between SmolLM3's 0.315 and Qwen3's 0.428 works — not a calibrated constant, and "never worse than the better static range" is true by construction on these three, since the cut is drawn from them. It would take more models to turn it into an actual threshold.One useful property: the rule only picks which range TPE searches, and range + seed + sampler fully determine the trials, so the adaptive arm reproduces the exact results of whichever static arm it selects. A candidate threshold can therefore be evaluated offline against existing fixed/silhouette runs, with no extra compute.
On @umran666's point that the layer range and the recovery coefficients are entangled: the band here comes from the residual geometry (the silhouette of the refusal/non-refusal clusters), computed before any optimization, not from a layer probe run under default static coefficients — which is the case where the optimizer drifts to a safe mid-range. So it's a different mechanism from the two-phase fit that gets trapped. It isn't free of the concern, though: narrowing the range before the joint search could in principle clip a range that's only good under tuned coefficients. The "never worse than the better static range" result is the only evidence I have that this doesn't bite in practice, and three models isn't much.
Implementation cost: the per-layer silhouette needs the per-prompt residuals rather than the running mean the default path keeps, so it's a memory/compute cost worth weighing before wiring in. PR #384 is reworking that residual-collection path, so this would want to sit on top of whatever lands there.
I can open a PR if this seems worth pursuing. The three models are public and the comparison reproduces.
@umran666 commented on GitHub (Jun 22, 2026):
The logic holds. Since the silhouette is computed pre-optimization, it acts as a prior and sidesteps the two-phase trap. The adaptive rule is mandatory though — if the peak is weak, the band is noise. Using ~0.40 as the cutoff based on your runs makes sense.
Hold off on opening the PR until #384 lands so you don't have to rewrite the residual collection logic, but definitely pursue this once that merges.
@p-e-w commented on GitHub (Jun 22, 2026):
What if strong silhouette separation isn't contiguous? I'm pretty sure I have observed this in some models.
The problem is that this threshold is yet another ad-hoc constant without theoretical underpinnings, and there is an ever-growing zoo of models, some of which might require very different thresholds.
This is the reason why we need to avoid complexity unless there is very strong evidence it brings a real improvement. The plugin system will be merged soon, and I think the best way forward will be to add plugin APIs that enable doing such experimental stuff from plugins. It's incredibly difficult to test any approach comprehensively, and I have to be conservative about what I merge into mainline to avoid creating a monstrosity that nobody can control or understand anymore.
@umran666 commented on GitHub (Jun 23, 2026):
Fair point. Magic numbers without theory are brittle across a large model zoo, and non-contiguous bands would break the logic.
Pushing this to the plugin system is the right call architecturally , it keeps mainline predictable while letting us test heuristics like this in isolation. Let's revisit the implementation once the plugin API lands.