Skip to content

Fix CMA-ES crashing in torch.cond and re-enable its test - #255

Merged
BillHuang2001 merged 1 commit into
EMI-Group:mainfrom
flyingdoubleG:fix-cmaes-cond-transpose
Oct 28, 2026
Merged

BillHuang2001 merged 1 commit into
EMI-Group:mainfrom
flyingdoubleG:fix-cmaes-cond-transpose

Conversation

@flyingdoubleG

Copy link
Copy Markdown
Contributor

Description

CMAES.step currently fails on its first call (torch 2.9.1 and 2.11 here, and on CI, which installs the latest CPU torch). This is presumably why test_cmaes was turned off with an early return.

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

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

wf = StdWorkflow(CMAES(mean_init=torch.ones(10), sigma=1.0), Sphere())
wf.init_step()
# torch._dynamo.exc.UncapturedHigherOrderOpError: ... Encountered aliasing during higher order op tracing

There are two separate causes, and the second appears once the first is fixed:

  1. In _decomposition, torch.cond reports C.T (and C.mT) of its operand as aliasing. Both C.t() and C.transpose(0, 1) trace fine, so the operand is now transposed explicitly.
  2. B, D, C_invsqrt are unpacked from the stacked torch.cond output, which makes them views of a single tensor. On the next step, _no_decomposition captures all three as buffers, and torch.cond rejects them as "input-to-input aliasing". The unpacked outputs are now cloned. Each is only dim x dim.

The numerics are unchanged.

test_cmaes is enabled again and runs CMA-ES through run_all, which covers the eager, torch.compile and vmap paths. Before this change, the eager step fails as shown above. With it, all 22 tests in unit_test/algorithms/test_es_variants.py pass. (I ran them locally with torch.compile(backend="aot_eager"), since this Windows machine has no MSVC for inductor.)

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.

CMAES.step raised UncapturedHigherOrderOpError on its first call: torch.cond
treats `C.T` of its operand as aliasing. Once that is avoided, the second
call failed too, because B, D and C_invsqrt were views of the stacked cond
output and torch.cond rejects captured buffers that alias each other.
Transpose the operand explicitly and clone the unpacked outputs.

test_cmaes was disabled with an early return; run it again.
@flyingdoubleG flyingdoubleG mentioned this pull request Oct 24, 2026
2 of 5 tasks
@BillHuang2001
BillHuang2001 merged commit 971d80c 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