Skip to content

Fix ASEBO once its gradient subspace activates - #257

Merged
BillHuang2001 merged 1 commit into
EMI-Group:mainfrom
flyingdoubleG:fix-asebo-subspace
Oct 28, 2026
Merged

BillHuang2001 merged 1 commit into
EMI-Group:mainfrom
flyingdoubleG:fix-asebo-subspace

Conversation

@flyingdoubleG

Copy link
Copy Markdown
Contributor

Description

ASEBO breaks as soon as its gradient subspace becomes active, i.e. once gen_counter > subspace_dims. run_all in the tests stops after three generations, so it never reaches that point.

import torch
from evox.algorithms import ASEBO
from evox.core import Problem
from evox.workflows import StdWorkflow

class Sphere(Problem):
    def evaluate(self, pop):
        return (pop**2).sum(-1)

algo = ASEBO(pop_size=10, center_init=torch.ones(4))
wf = StdWorkflow(algo, Sphere())
wf.init_step()
for _ in range(10):
    wf.step()
# alpha is NaN from generation 5 (= subspace_dims + 1), then
# torch._C._LinAlgError: linalg.cholesky: ... not positive-definite

With subspace_dims=3 and dim=10, it fails right away with RuntimeError: The size of tensor a (10) must match the size of tensor b (3).

Causes:

  1. alpha = ‖g·UUT_ort‖ / ‖g·self.UUT‖, but the self.UUT buffer is never written, so it stays all zeros. Once the subspace is active, alpha is x / 0, then the covariance is NaN and Cholesky fails.
  2. torch.svd returns V, not Vᵀ (unlike jnp.linalg.svd). Taking rows of it (Vt[:k]) does not give the principal directions of the past gradients, and the shapes only work when subspace_dims == dim.
  3. The basis is split at pop_size / 2 rather than subspace_dims, and U_ort comes from the remaining rows of the same thin SVD. That is not a projector onto the orthogonal complement, and it is empty when subspace_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.

  • U is the top subspace_dims right singular vectors (torch.linalg.svd) of the centred gradient buffer. Directions with no variance are dropped, since the centred buffer has rank at most subspace_dims - 1. The subspace term is divided by the number of directions kept.
  • UUT_ort = I - UUT. alpha is computed with a +1e-8 in the denominator and clamped to [0, 1].
  • self.UUT and self.UUT_ort are now stored.
  • Perturbations are sigma * N(0, cov) with a small jitter on cov, instead of unit-normalised samples. The step itself is unchanged, since the gradient is normalised by ‖g‖ / dim before the update.
  • subspace_ready is computed once per step, so the sampling and the alpha update agree on whether the subspace is active.

The new test test_asebo_after_subspace_activates runs 3 * dim generations, for the default subspace_dims and for subspace_dims=2 < dim. It checks that the centre stays finite, that alpha ∈ [0, 1], and that UUT is a symmetric projector of rank ≤ subspace_dims. Before the fix it fails with the Cholesky error. With the fix, all tests in unit_test/algorithms/test_es_variants.py pass (run locally with torch.compile(backend="aot_eager"), since there is no MSVC for inductor here).

Checklist

  • I have formatted my Python code with ruff.
  • I have good commit messages.
  • If adding new algorithms, problems, operators:
    • Added related test cases.
    • Added docstring to explain important parameters.
    • Added entries in the docs.

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.
@BillHuang2001
BillHuang2001 merged commit 21437b1 into EMI-Group:main Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants