How oladiy2504/where_do_gradient_methods_really_happen works
Purpose and Entry Points
This is an ML optimization research repository for comparing optimizers and gradient/update projection methods across image, language, and transformer-style models. The primary experiment entry points are experiments/run.py and MLflow-integrated experiments/mlflow_runner.py; reusable execution logic is centralized in src/experiments/runner.py.
Experiment Orchestration
The experiment layer defines configurations, resolves tasks, runs seeded trials, and records histories/results. experiments/configs.py supplies experiment definitions, while src/experiments/tasks.py maps them to model/dataset workloads. src/experiments/runner.py is the core control boundary between configuration and training execution.
Model and Dataset Workloads
Model implementations cover MNIST MLPs, CIFAR CNN/ResNet/VGG models, GPT, and an SST transformer: src/models/mlp_mnist.py, src/models/cnn_cifar.py, src/models/gpt.py, src/models/transformer_sst.py. Dataset acquisition/loading and model-facing data preparation are concentrated in src/models/data.py; experiments/prefetch_datasets.py supports preloading datasets before runs.
Optimizer Implementations
The repository implements its optimizer variants rather than only wrapping framework defaults. Standard and experimental update rules reside in src/optimizers/sgd.py, src/optimizers/adam.py, src/optimizers/muon.py, and src/optimizers/subzero.py, with related algorithms such as AdamW, SGDM, MeZO, forward-gradient, and SWA in the same package. This layer consumes gradients and emits parameter updates, optionally exposing optimizer state such as momentum or Adam moving averages to projection logic.
Projection and Subspace Methods
Projection is a separate architectural layer applied to gradients, updates, or optimizer state. The interface/base abstraction is src/projections/base.py; implementations include eigenspace, Hessian, gradient-covariance, momentum-matrix, random, Stiefel, and two-sided projections in src/projections/. src/projectors.py likely provides composition or selection of these methods for the runner. This separation enables experiments such as dominant/bulk subspace treatment and tangent-space momentum projections without rewriting optimizers.
Results, Analysis, and Tracking
Runs persist experiment configuration, per-seed histories, validation histories, summaries, and method-specific result JSON under data/, exemplified by data/momentum_cifar_adam_expavg_layerwise_tangent_energy080_switch_1000_end_3000_upd1_3seeds/. Multi-seed aggregation is represented by history_aggregate.csv and validation_aggregate.csv. MLflow is the material external tracking service via experiments/mlflow_runner.py; plots and postprocessing are supported by src/experiments/plotting.py and notebooks under notebooks/.
Runtime and Reproducibility Boundary
The project is Python-based, with dependencies/environment defined by pyproject.toml, environment.yml, and uv.lock. Training likely relies on a tensor/autodiff runtime implied by the model and optimizer architecture, but the file tree does not identify a specific framework. Research outputs are retained in-repo as CSV/JSON data, notebooks, and LaTex report/poster artifacts in report/ and poster/.
Main entry points: runner.py Experiment runner · tasks.py Task resolver · data.py Data preparation · run.py CLI runner
Components 19
Experiment Entry Points
- CLI runner
experiments/run.py - MLflow runner · Runs experiments with external MLflow tracking.
experiments/mlflow_runner.py
Execution Core
- Experiment configs
experiments/configs.py - Experiment runner · Resolves workloads, executes seeded trials, and records histories.
src/experiments/runner.py - Task resolver
src/experiments/tasks.py
Workloads
- Data preparation
src/models/data.py - Dataset prefetch
experiments/prefetch_datasets.py - Image models · MNIST and CIFAR model implementations.
src/models/mlp_mnist.py - GPT model
src/models/gpt.py - SST transformer
src/models/transformer_sst.py
Optimization Methods
- Optimizer variants · SGD, Adam, Muon, SubZero, and related algorithms produce parameter updates.
src/optimizers/sgd.py - Projector selection
src/projectors.py - Projection interface · Applies methods to gradients, updates, or optimizer state.
src/projections/base.py - Subspace projections · Eigenspace, Hessian, gradient-covariance, momentum, random, Stiefel, and two-sided methods.
Tracking and Outputs
- Run artifacts · Stores configurations, per-seed histories, validation, summaries, and aggregates.
- MLflow
- Plotting and analysis
src/experiments/plotting.py - Research notebooks
- Reports and posters
Connections 23
- CLI runner → Experiment configs: loads
- CLI runner → Experiment runner: starts
- MLflow runner → Experiment runner: starts
- MLflow runner → MLflow: tracks
- Experiment configs → Experiment runner: defines trials
- Experiment runner → Task resolver: resolves
- Task resolver → Data preparation: selects data
- Task resolver → Image models: selects
- Task resolver → GPT model: selects
- Task resolver → SST transformer: selects
- Dataset prefetch → Data preparation: preloads
- Data preparation → Image models: feeds batches
- Data preparation → GPT model: feeds batches
- Data preparation → SST transformer: feeds batches
- Experiment runner → Optimizer variants: executes training
- Experiment runner → Projector selection: configures
- Projector selection → Projection interface: uses interface
- Projection interface → Subspace projections: implemented by
- Subspace projections → Optimizer variants: projects gradients, updates, or state
- Experiment runner → Run artifacts: persists histories and summaries
- Run artifacts → Plotting and analysis: analyzed by
- Plotting and analysis → Research notebooks: supports
- Research notebooks → Reports and posters: informs