Skip to content

Fix crashes in tournament selection (n_round=1), XNES/SeparableNES default pop_size and Guided ES subspaces - #259

Merged
BillHuang2001 merged 3 commits into
EMI-Group:mainfrom
flyingdoubleG:fix-es-selection-crashes
Oct 28, 2026
Merged

BillHuang2001 merged 3 commits into
EMI-Group:mainfrom
flyingdoubleG:fix-es-selection-crashes

Conversation

@flyingdoubleG

Copy link
Copy Markdown
Contributor

Three small fixes, one commit each. All three fail on main with a short script (outputs below are from main).

1. tournament_selection / tournament_selection_multifit return a 0-d tensor for n_round=1. The trailing .squeeze() also drops the round dimension. EvoMO's MOEADAWA hits this on 2-objective ZDT1 (around generation 53, once a single candidate is selected) and crashes. Now .squeeze(1); for n_round > 1 nothing changes.

tournament_selection(1, fit).shape            -> ()     (now (1,))

2. XNES and SeparableNES cannot be built with the default pop_size=None. The default reads self.dim, which is only assigned later in __init__:

XNES(torch.zeros(4), torch.eye(4))            -> AttributeError: 'XNES' object has no attribute 'dim'

Now it uses the local dim.

3. Guided ES factorizes the gradient subspace the wrong way round. grad_subspace stores the last subspace_dims gradients as rows ([subspace_dims, dim]), but torch.linalg.qr(self.grad_subspace) gives a subspace_dims x subspace_dims basis of its column space. So:

  • with subspace_dims < dim, step() raises: The size of tensor a (10) must match the size of tensor b (2);
  • with the default subspace_dims = dim, the basis spans the whole space, so the guided term is just more isotropic noise.

Now it factorizes grad_subspace.T, a dim x subspace_dims basis U, so the perturbation covariance is alpha/n I + (1 - alpha)/k U U^T as in Maheswaranathan et al. (2019). Check: with alpha = 0, subspace_dims = 2, dim = 10, the part of the sampled perturbations outside the span of the stored gradients is 0.000 of their norm.

Tests:

  • new unit_test/operators/test_tournament_selection.py;
  • test_nes_default_pop_size;
  • test_guided_es_subspace (subspace_dims=2, through run_all).

The first two fail on main and pass here. I am on Windows without MSVC, so torch.compile does not work locally. I ran the eager and uncompiled vmap paths of run_all for Guided ES (default, subspace_dims=2, Adam) and for XNES/SeparableNES with the default pop_size, and they pass. The compiled paths are left to CI.

This was prepared with AI assistance (Claude); I reviewed and tested the change.

squeeze() also dropped the round dimension, so n_round=1 returned a 0-d tensor.
EvoMO's MOEADAWA hits this on 2-objective ZDT1 once a single candidate is
selected and crashes. Squeeze only the gathered column.
The default pop_size read self.dim before it was assigned, so constructing
either without pop_size raised AttributeError. Use the local dim.
grad_subspace stores the gradients as rows, but the QR factorized it as is,
giving a subspace_dims x subspace_dims basis of its column space. With
subspace_dims < dim the shapes do not match and step() raises; with the
default subspace_dims = dim the basis spans the whole space, so the search
was not guided. Factorize grad_subspace.T for a dim x subspace_dims basis.
@BillHuang2001
BillHuang2001 merged commit ead74fd 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