Meta-Optimization Methods¶
Overview¶
Meta-optimization, or "learning to optimize," represents a paradigm shift in optimization algorithms where neural networks learn to optimize other neural networks. Instead of using hand-crafted optimization algorithms like Adam or SGD, meta-optimization algorithms learn update rules that are specifically tailored to families of related problems.
Theoretical Foundation¶
Meta-Learning Framework¶
Meta-optimization is built on the meta-learning framework where we have:
- Meta-learner: The optimization algorithm that learns to optimize
- Base-learner: The model being optimized
- Task distribution: A family of related optimization problems
The meta-learner is trained on a distribution of tasks to learn an optimization strategy that generalizes well to new, unseen tasks from the same distribution.
Mathematical Formulation¶
Given a family of optimization problems \(\mathcal{T}\), meta-optimization seeks to learn an optimizer \(\phi\) that minimizes:
where:
- \(\tau\) is a task sampled from the task distribution \(\mathcal{T}\)
- \(f_{\phi}\) is the learned optimizer parameterized by \(\phi\)
- \(\theta_0\) is the initial parameters for task \(\tau\)
- \(\mathcal{L}_{\tau}\) is the loss function for task \(\tau\)
Core Algorithms¶
1. Learn-to-Optimize (L2O)¶
L2O algorithms use neural networks to learn optimization update rules:
where:
- \(g_{\phi}\) is a neural network parameterized by \(\phi\)
- \(h_t\) is the hidden state (for RNN-based optimizers)
- \(\alpha\) is a learned or fixed step size
Implementation¶
from opifex.optimization.meta_optimization import LearnToOptimize
# LearnToOptimize is initialized directly
l2o = LearnToOptimize(
meta_network_layers=[128, 64, 32],
base_optimizer="adam",
meta_learning_rate=1e-3,
unroll_steps=20,
rngs=nnx.Rngs(42),
)
# Compute meta-gradients for training the meta-network
meta_grads = l2o.compute_meta_gradients(
loss_fn=loss_function,
initial_params=params,
)
# Compute parameter updates using the learned optimizer
gradient = jax.grad(loss_function)(params)
previous_updates = jnp.zeros((0, params.size))
update = l2o.compute_update(gradient, previous_updates)
2. Learned Optimizers¶
See Learn-to-Optimize Methods for opifex's learned-optimiser stack (per-parameter MLP optimisers meta-trained with Persistent Evolution Strategies).
Advanced Features¶
1. Adaptive Learning Rate Scheduling¶
Meta-optimizers can learn adaptive learning rate schedules:
from opifex.optimization.meta_optimization import AdaptiveLearningRateScheduler
scheduler = AdaptiveLearningRateScheduler(
initial_lr=1e-3,
strategy="cosine_annealing",
adaptation_frequency=10,
performance_threshold=0.01
)
# Adaptive scheduling during training
for epoch in range(num_epochs):
loss = compute_loss(params, data)
current_lr = scheduler.adapt(loss, epoch)
params = update_params(params, gradients, current_lr)
2. Warm-Starting Strategies¶
Transfer knowledge between related optimization problems:
from opifex.optimization.meta_optimization import WarmStartingStrategy
warm_starter = WarmStartingStrategy(
strategy_type="parameter_transfer",
similarity_threshold=0.8,
transfer_fraction=0.5
)
# Initialize new problem from similar solved problem
target_params = warm_starter.initialize_from_source(
source_params=source_params,
target_shape=target_shape,
problem_similarity=0.9
)
3. Performance Monitoring¶
Full tracking of optimization performance:
from opifex.optimization.meta_optimization import PerformanceMonitor
monitor = PerformanceMonitor(
track_convergence=True,
track_efficiency=True,
track_stability=True,
save_trajectory=True
)
# Monitor optimization process
for step in range(optimization_steps):
params, loss = optimization_step(params, data)
monitor.update(step, loss, params)
if step % 100 == 0:
metrics = monitor.get_metrics()
print(f"Convergence rate: {metrics['convergence_rate']}")
Quantum-Aware Meta-Optimization¶
Specialized meta-optimization for quantum mechanical systems:
SCF Acceleration¶
Self-consistent field (SCF) convergence acceleration for quantum chemistry:
from opifex.core.training.config import MetaOptimizerConfig
from opifex.optimization.meta_optimization import MetaOptimizer
config = MetaOptimizerConfig(
meta_algorithm="l2o",
base_optimizer="adam",
meta_learning_rate=1e-4,
quantum_aware=True,
scf_adaptation=True,
)
meta_optimizer = MetaOptimizer(config=config, rngs=nnx.Rngs(42))
# Optimize quantum system using quantum_step
opt_state = meta_optimizer.init_optimizer_state(orbital_coeffs)
scf_context = {"iteration": 0, "energy_history": jnp.array([])}
new_coeffs, opt_state, quantum_info = meta_optimizer.quantum_step(
energy_fn=energy_function,
orbital_coeffs=orbital_coeffs,
opt_state=opt_state,
scf_context=scf_context,
step=0,
)
Energy Optimization¶
Specialized algorithms for energy minimization:
- DIIS Acceleration: Direct inversion in iterative subspace
- Level Shifting: Improved convergence for difficult cases
- Density Mixing: Optimal mixing of density matrices
Performance Analysis¶
Convergence Guarantees¶
Meta-optimization algorithms provide different convergence guarantees:
- L2O: Convergence depends on the expressiveness of the meta-network
Computational Complexity¶
- Training Phase: \(O(T \cdot S \cdot N)\) where \(T\) is tasks, \(S\) is steps, \(N\) is parameters
- Optimization Phase: \(O(S \cdot M)\) where \(M\) is meta-network parameters
- Memory: \(O(N + M)\) for storing both base and meta-parameters
Speedup Analysis¶
Typical speedups achieved by meta-optimization:
- Similar Problems: 10-100x faster convergence
- Related Domains: 5-20x speedup
- Novel Problems: 1-5x improvement (with good generalization)
Integration with Physics-Informed Learning¶
Meta-optimization can be enhanced with physics-informed constraints:
from opifex.core.training.config import MetaOptimizerConfig
from opifex.optimization.meta_optimization import MetaOptimizer
from opifex.core.physics.losses import PhysicsInformedLoss, PhysicsLossConfig
# Physics-aware meta-optimization
config = MetaOptimizerConfig(
meta_algorithm="l2o",
base_optimizer="adam",
meta_learning_rate=1e-3,
adaptation_steps=10,
)
physics_loss = PhysicsInformedLoss(
config=PhysicsLossConfig(
physics_loss_weight=1.0,
boundary_loss_weight=10.0,
),
equation_type="poisson",
domain_type="rectangular",
)
meta_optimizer = MetaOptimizer(config=config, rngs=nnx.Rngs(42))
Best Practices¶
1. Task Distribution Design¶
- Diversity: Include diverse problems in the task distribution
- Similarity: Ensure tasks share structural similarities
- Difficulty: Gradually increase problem complexity during training
2. Meta-Training Strategy¶
- Curriculum Learning: Start with simple tasks and increase complexity
- Regularization: Use appropriate regularization to prevent overfitting
- Validation: Always validate on held-out tasks
3. Hyperparameter Selection¶
- Learning Rates: Use different rates for meta and base learning
- Unroll Length: Balance between computational cost and gradient quality
- Architecture: Choose appropriate meta-network architecture
4. Evaluation Metrics¶
- Convergence Speed: Steps to reach target accuracy
- Final Performance: Best achievable performance
- Generalization: Performance on unseen tasks
- Computational Efficiency: Wall-clock time and memory usage
Limitations and Future Directions¶
Current Limitations¶
- Task Distribution Dependence: Performance depends heavily on task similarity
- Computational Cost: Meta-training can be expensive
- Hyperparameter Sensitivity: Requires careful tuning
- Limited Theory: Theoretical understanding is still developing
Future Research Directions¶
- Automated Task Generation: Learning to generate training tasks
- Few-Shot Meta-Learning: Adapting with very few examples
- Continual Meta-Learning: Learning new tasks without forgetting old ones
- Theoretical Analysis: Better understanding of convergence properties
References¶
- Andrychowicz, M., et al. "Learning to learn by gradient descent by gradient descent." NIPS 2016.
- Chen, Y., et al. "Learning to optimize: A primer and a benchmark." JMLR 2022.
See Also¶
- Learn-to-Optimize - Specific L2O algorithms
- Optimization User Guide - Practical usage
- Training Integration - Using with training workflows