evox.problems.neuroevolution#

Submodules#

Package Contents#

Classes#

VirtualProblem

Virtual Gaussian-noise neuroevolution problem.

Data#

API#

class evox.problems.neuroevolution.VirtualProblem(model: torch.nn.Sequential, data_loader: torch.utils.data.DataLoader, criterion: torch.nn.Module, n_batch_per_eval: int = 1, device: torch.device | None = None, reduction: str = 'mean')[source]#

Bases: evox.core.Problem

Virtual Gaussian-noise neuroevolution problem.

Evaluates a population of Gaussian-noise-perturbed neural networks without materializing the full perturbed population. For each individual, the weight and bias perturbations are generated on-demand from a seed using the fused kernel :func:virtual_perturbed_linear.

Instead of receiving a full (pop_size, dim) population, the

Meth:

evaluate method receives a tuple (center_flat, seeds, sigma) and applies full Gaussian-noise perturbations layer-by-layer during the forward pass via :func:virtual_perturbed_linear, which does the base matmul plus sigma * noise perturbation of both weight and bias in a single call. Activations are kept at (pop_size, batch, features) — far smaller than the full perturbed population (pop_size, total_params).

Supports nn.Sequential models containing nn.Linear layers and common activation functions (ReLU, Tanh, Sigmoid, GELU, LeakyReLU, ELU, Softmax, Identity).

Warning

This problem does NOT support HPO wrapper (problems.hpo_wrapper.HPOProblemWrapper).

Initialization

Initialize the VirtualProblem.

Parameters:
  • model – The neural network model. Must be an nn.Sequential whose children are nn.Linear layers and/or supported activation modules.

  • data_loader – The data loader providing the dataset for evaluation.

  • criterion – The loss function used to evaluate the parameters’ performance. Use reduction='none' so that per-sample losses are returned and this problem handles the aggregation. If a scalar criterion is provided, a warning is emitted.

  • n_batch_per_eval – The number of batches to be evaluated in a single evaluation. When set to -1, will go through the whole dataset. Defaults to 1.

  • device – The device to run the computations on. Defaults to the current default device.

  • reduction – The reduction method for aggregating per-sample losses across the batch (and across multiple batches). 'mean' | 'sum'. Defaults to 'mean'.

_virtual_forward(inputs: torch.Tensor, center_params: Dict[str, torch.nn.Parameter], seeds: torch.Tensor, sigma: float, pop_size: int) torch.Tensor[source]#

Layer-by-layer forward pass with on-demand Gaussian-noise perturbations.

For each layer:

  • nn.Linear: compute the base output (center weight) plus a full Gaussian-noise perturbation of both weight and bias via

    func:

    virtual_perturbed_linear. The noise is generated on-the-fly per individual from a seed and the block offset, without materializing the (out_features, in_features) weight delta.

  • Activation modules: applied element-wise.

Activations are (pop_size, batch, features) — much smaller than the full perturbed population (pop_size, total_params).

Parameters:
  • inputs – Input batch of shape (batch, in_features).

  • center_params – Parameter dict of the center (un-perturbed) model.

  • seeds – 1-D int64 tensor of per-individual seeds (pop_size,).

  • sigma – Noise standard deviation.

  • pop_size – The population size (number of individuals).

Returns:

Output activations of shape (pop_size, batch, out_features).

evaluate(payload) torch.Tensor[source]#

Evaluate the fitness of a virtual Gaussian-noise-perturbed population.

Parameters:

payload

A tuple (center_flat, seeds, sigma) where:

  • center_flat: (dim,) float32 tensor — flat center vector.

  • seeds: (pop_size,) int64 tensor — per-individual seeds.

  • sigma: Python float — noise standard deviation.

Returns:

A tensor of shape (pop_size,) containing the fitness of each individual.

evox.problems.neuroevolution.VirtualLoRAProblem#

None