Skip to main content
The EvolutionEngine is the central orchestrator of EMEP’s evolutionary search loop. It drives the primary pipeline from validated model candidates through evaluation, fitness assignment, selection, and reproduction to discover high-performing merged models. This page specifies the full algorithm, data structures, decision points, and termination conditions for both single-objective and multi-objective optimization modes.
This specification is for a system that has not yet been implemented. All algorithmic details, parameters, and performance characteristics are engineering assumptions unless otherwise tagged.

Master Algorithm Flowchart

The following flowchart describes the complete lifecycle of an evolutionary run from initialization through termination.

Multi-Objective Sub-Flow

When running in multi-objective mode, the fitness calculation and selection steps are replaced by the following sub-flow:

Purpose

The EvolutionEngine performs automated, directed search over the space of possible merged models. It uses evolutionary algorithms to explore combinations of parent models, merge strategies, and hyperparameters to produce candidates that outperform any individual parent on target benchmarks.

Problem Definition

Given a set of base models (M = {m_1, m_2, …, m_n}), a set of merge strategies (S = {s_1, s_2, …, s_k}), and a fitness function (F), find the merged model (m^) that maximizes (F(m^)) subject to constraints on model size, inference latency, and safety thresholds.

Inputs

Preconditions

  • All base_models must be in REGISTERED or EVALUATED lifecycle state.
  • At least two base models must be marked COMPATIBLE or CONDITIONALLY_COMPATIBLE.
  • The evaluation_profile must contain at least one benchmark split.
  • compute_budget must be greater than zero.

Parameters

Tensor Shapes

Not applicable at the engine level. Tensor shapes are validated per-candidate by the MergeEngine and TensorEngine.

Mathematical Formulation

Single-Objective Fitness Maximization

maxgGF(g)\max_{g \in \mathcal{G}} F(g) Where:
  • G\mathcal{G} is the genome search space
  • F(g)F(g) is the scalar fitness of genome gg
  • F(g)=w1f1(g)+w2f2(g)+...+wnfn(g)P(g)F(g) = w_1 \cdot f_1(g) + w_2 \cdot f_2(g) + ... + w_n \cdot f_n(g) - P(g)
  • P(g)P(g) is the constraint penalty

Multi-Objective Formulation

maxgGF(g)=(f1(g),f2(g),...,fm(g))\max_{g \in \mathcal{G}} \vec{F}(g) = (f_1(g), f_2(g), ..., f_m(g)) Subject to:
  • ci(g)0c_i(g) \leq 0 for all constraints ii
  • gg produces a valid merged model

Step-by-Step Processing

1

Initialize Search Space

Enumerate all valid combinations of parent model IDs and merge strategies based on compatibility analysis. Filter out infeasible combinations (e.g., Franken-Merge requires architectural alignment).
2

Initialize Population

Generate population_size genomes using the configured initialization strategy: random, seeded from known good configurations, or warm-started from a previous experiment.
3

Validate Candidates

For each genome, invoke ModelCompatibilityAnalyzer to verify parent compatibility. Reject genomes with INCOMPATIBLE parents before merge.
4

Evaluate Candidates

Dispatch each valid candidate to the EvaluationEngine for benchmark execution. Collect per-metric scores.
5

Calculate Fitness

Aggregate per-metric scores into a fitness scalar (single-objective) or vector (multi-objective). Apply constraint penalties and regression penalties.
6

Rank Population

Sort by fitness descending (single-objective) or perform non-dominated sorting (multi-objective).
7

Check Termination

Evaluate termination criteria in order: max generations, max candidates, compute budget exhausted, no improvement for N generations.
8

Selection

Select parents for reproduction using tournament, truncation, or rank-based selection. In multi-objective mode, use NSGA-II selection with crowding distance.
9

Mutation

Apply mutation operators to selected genomes with probability mutation_rate. See Mutation for operator details.
10

Crossover

Apply crossover operators to pairs of selected genomes with probability crossover_rate. See Crossover for operator details.
11

Generate Offspring

Produce new genomes from mutated/crossed parents. Ensure population size is maintained.
12

Validate Offspring

Re-run compatibility and structural validation on new genomes. Reject invalid offspring.
13

Evaluate Offspring

Dispatch valid offspring to the EvaluationEngine.
14

Diversity and Constraint Check

Compute pairwise genome distances. If diversity falls below diversity_threshold, inject random immigrants. Re-check constraints.
15

Next Generation

Combine elites, surviving parents, and valid offspring to form the next generation. Increment generation counter.

Decision Points

Branch Conditions

  • Single-objective branch: Uses weighted sum fitness, tournament selection, and elitism.
  • Multi-objective branch: Uses Pareto dominance, non-dominated sorting, NSGA-II selection, and returns a Pareto front.
  • Warm-start branch: If prior experiment lineage exists, seed initial population with top performers from related experiments.

Outputs

Failure Conditions

  • Invalid configuration: Missing required fields or out-of-range parameters. Status: FAILED.
  • No compatible parents: All base model pairs are INCOMPATIBLE. Status: FAILED.
  • All candidates invalid: Merge or validation fails for every genome. Status: FAILED.
  • Compute budget exhausted: Wall-clock or GPU-hour limit reached before termination. Status: CANCELLED.
  • Evaluation failure: EvaluationEngine returns INCOMPLETE for all candidates. Status: FAILED.

Validation

  • Configuration schema validated against JSON Schema before run start.
  • All parent model IDs verified against ModelRegistry.
  • Merge strategy compatibility checked per genome.
  • Fitness values bounded to prevent NaN/Inf propagation.

Complexity

Memory Requirements

  • Population storage: O(PG)O(P \cdot G) where GG is genome size (typically < 1 KB per genome).
  • Model checkpoint caching: O(KS)O(K \cdot S) where KK = cached candidates, SS = model size.
  • Fitness trajectory: O(Gmax)O(G_{max}) where GmaxG_{max} = max generations.

Numerical Stability

  • Fitness scores clipped to [106,106][-10^6, 10^6] to prevent overflow.
  • Constraint penalties additive, not multiplicative, to avoid gradient collapse.
  • Crowding distance computation uses normalized objective ranges.

Precision Considerations

  • Fitness aggregation uses float64 to prevent precision loss across many objectives.
  • Alpha coefficients stored as float32 in genomes (sufficient for merge operations).
  • Generation counter: int64.

Reproducibility

  • Random seeds set for population initialization, mutation, and selection.
  • All hyperparameters logged to ExperimentTracker.
  • Genome lineage tracked via parent pointers for full provenance.

Unit Tests

Integration Tests

Acceptance Criteria

  • Single-objective run produces a candidate with fitness greater than best parent baseline (Research hypothesis).
  • Multi-objective run produces a Pareto front with at least two non-dominated solutions.
  • Termination criteria are independently configurable and correctly enforced.
  • All experiment states transition correctly: CREATEDPREPARINGRUNNINGEVALUATINGCOMPLETED.
  • Full lineage traceable from any output candidate to its original parents.

Known Limitations

  • Evaluation cost dominates runtime; no asynchronous or batched evaluation specified yet (Future goal).
  • No adaptive hyperparameter tuning during the run (Research hypothesis).
  • Diversity metric is Hamming distance on genome encoding; may not reflect phenotypic diversity (Engineering assumption).

Research References

  • Evolutionary Model Merge: Akiba et al. 2024
  • NSGA-II: Deb et al. 2002 (for multi-objective selection)
  • Model Soups: Wortsman et al. 2022 (for weighted merging baseline)