Repository navigation
Fix ASEBO once its gradient subspace activates - #257
Merged
Merged
Conversation
As soon as more than subspace_dims gradients were buffered, alpha became NaN (it divided by theta_grad @ self.UUT, and the UUT buffer was never written), so the next Cholesky factorisation failed. The subspace basis was also taken from rows of V (torch.svd returns V, not V^T), split at pop_size / 2 instead of subspace_dims, which broke any subspace_dims != dim. Build U from the right singular vectors of the centred gradient buffer, drop directions without variance, use I - UU^T as the orthogonal projector, keep alpha in [0, 1], and store UUT/UUT_ort. Perturbations are sigma * N(0, cov), as in evosax, which this implementation follows.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ASEBObreaks as soon as its gradient subspace becomes active, i.e. oncegen_counter > subspace_dims.run_allin the tests stops after three generations, so it never reaches that point.With
subspace_dims=3anddim=10, it fails right away withRuntimeError: The size of tensor a (10) must match the size of tensor b (3).Causes:
alpha = ‖g·UUT_ort‖ / ‖g·self.UUT‖, but theself.UUTbuffer is never written, so it stays all zeros. Once the subspace is active,alphaisx / 0, then the covariance is NaN and Cholesky fails.torch.svdreturnsV, notVᵀ(unlikejnp.linalg.svd). Taking rows of it (Vt[:k]) does not give the principal directions of the past gradients, and the shapes only work whensubspace_dims == dim.pop_size / 2rather thansubspace_dims, andU_ortcomes from the remaining rows of the same thin SVD. That is not a projector onto the orthogonal complement, and it is empty whensubspace_dims <= pop_size / 2.The fix follows the current evosax implementation, which this class says it is based on. evosax fixed the same problems in its ASEBO in July–August 2026.
Uis the topsubspace_dimsright singular vectors (torch.linalg.svd) of the centred gradient buffer. Directions with no variance are dropped, since the centred buffer has rank at mostsubspace_dims - 1. The subspace term is divided by the number of directions kept.UUT_ort = I - UUT.alphais computed with a+1e-8in the denominator and clamped to[0, 1].self.UUTandself.UUT_ortare now stored.sigma * N(0, cov)with a small jitter oncov, instead of unit-normalised samples. The step itself is unchanged, since the gradient is normalised by‖g‖ / dimbefore the update.subspace_readyis computed once per step, so the sampling and thealphaupdate agree on whether the subspace is active.The new test
test_asebo_after_subspace_activatesruns3 * dimgenerations, for the defaultsubspace_dimsand forsubspace_dims=2 < dim. It checks that the centre stays finite, thatalpha ∈ [0, 1], and thatUUTis a symmetric projector of rank ≤subspace_dims. Before the fix it fails with the Cholesky error. With the fix, all tests inunit_test/algorithms/test_es_variants.pypass (run locally withtorch.compile(backend="aot_eager"), since there is no MSVC for inductor here).Checklist
ruff.