mirror of
https://github.com/p-e-w/heretic.git
synced 2026-12-03 18:42:57 +07:00
[GH-ISSUE #522] A deep, subtle flaw in ARA #224
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#224
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 @p-e-w on GitHub (Oct 23, 2026).
Original GitHub issue: https://github.com/p-e-w/heretic/issues/522
I discovered this issue while investigating the mysterious divergences from #499, and I believe it is also at least partially responsible for the "massive KLD" phenomenon we have observed in ARA since the beginning (see #211).
The flaw
TL;DR: ARA runs unconstrained matrix optimization while much of the linear operator described by the matrix doesn't affect the loss function at all.
By default, we have 400 good and 400 bad prompts. The matrix dimension is typically in the thousands, so the span of all input vectors is only a subspace of the space transformed by the matrix. This means that the matrix can be perturbed anywhere in the subspace that is orthogonal to that span without affecting the loss at all. However, such perturbations DO affect model behavior, including on the test datasets which are not contained in the training data.
Wait... but the gradients constrain us to the space we observe, right?
Mathematically yes... but only up to the base precision guaranteed by PyTorch (something like 10^-7 for FP32). The optimizer is free (in fact, it cannot avoid) to make any changes to the matrix coefficients within that precision range, including such that lead to modifications outside of the observed subspace.
But it gets worse: We use L-BFGS with line search (
strong_wolfe), which isn't constrained to a specific step size. This can amplify numerical deviations by an essentially arbitrary amount. These huge steps also affect the dimensions lying inside the unobserved subspace, which then get incorporated into the L-BFGS direction history, which amplifies them further, and so on. There is no corrective force, because by definition, the loss function is unaffected by those dimensions.Why this explains the mystery from #499
The original formulation and the low-rank formulation implemented by @varunbln are mathematically equivalent, but they differ in numerical perturbations caused by non-associativity and non-distributivity of floating point operations. Inside the unobserved subspace, these perturbations get amplified as described above, and they lead to highly divergent optimization trajectories, and thus to very different optima and results being found.
Why this explains very high KLD values
Because while the ballooning disturbances in the unobserved subspace don't affect the loss function, they do affect the scores (such as KLD) that are computed using the full matrix space with different prompts. As such, the optimizer might think that it is actually reasonably close to preserving the original behavior, while the behavior of the model actually differs dramatically in ways the loss function is blind to.
What can we do about it?
Option 1: Introduce a ridge/regularization penalty that binds the new matrix to the original one
This is actually something that was part of an early formulation of ARA that I was experimenting with in January or so. A Frobenius norm of the matrix difference with a suitable weight ensures that the entire operator, including the unobserved dimensions, remains reasonably close to the original one.
I have tested this and confirmed that it fixes the discrepancy from #499, and tames high KLD values. The problem is that choosing a weight that works across all models is very difficult to justify theoretically.
Option 2: Disable line search (
line_search_fn=None)This eliminates the main cause of arbitrary blowups in the unobserved space (see above). I have tested this and confirmed that it fixes the discrepancy from #499, and (somewhat) tames high KLD values. The problem is that it can lead the optimizer to wander into inadmissible regions, leading to NaN results and requiring further special handling such as retries.
Option 3: Do nothing
The good news is that we optimize for real scores that capture overall behavior, so we can just let TPE figure it out and automatically discard wild trajectories. This means that runs are highly unstable, both under slight, mathematically equivalent rearrangements as in #499, and in different environments (which makes reproducibility a pain). It can also impact optimization quality compared to what might be possible with Option 1, though in practice, ARA does seem to work fine.
/cc @kabachuha You may be interested in this.