How alisiahkoohi/csgm works
Project Type and Purpose
• This is a research‐grade machine‐learning library and experiment suite.
• It provides:
• Core ML components (model definitions, noise scheduling) in a Python package (csgm/).
• Configuration files (configs/) that drive experiment parameters.
• Training and inference scripts (scripts/) that orchestrate end-to-end workflows.
• Data management (on-the-fly generation for toy examples, download for seismic imaging).
• Utilities for logging, checkpointing, normalization, learning-rate scheduling, etc.
Top-Level Components
a. User Interface / CLI Layer
• scripts/train_conditional_quadratic.py
• scripts/train_conditional_seismic_imaging.py
• Flags (--phase train/test/plot)
b. Configuration Management
• JSON files in configs/
• csgm/utils/config.py for parsing and applying hyperparameters
c. Data Layer
• Toy dataset generator (csgm/utils/toy_dataset.py)
• Seismic data downloader / loader (implicitly via scripts, stores into data/)
d. Core Library (csgm/ package)
• Model definitions: network_conditional.py, fourier_neural_operator.py
• Noise scheduling: noise_scheduler.py
• Normalization & pre/post processing: normalizer.py, grid.py
• Hyperparameter utilities: hyperparam_utils.py, lr_scheduler.py
• Experiment persistence: save_experiment.py, save_results.py, project_path.py
e. Training & Inference Engine
• Loops that call models + scheduler + optimizer
• Checkpointing mechanism (checkpoint_*.pth)
• Posterior sampling and plotting
f. External Dependencies & Environment
• environment.yml (Conda, PyTorch, CUDA)
• setup.py (installs the csgm package editable)
• Data storage (data/ folder, remote URL for pretrained weights)
Relationships and Interactions
• The CLI scripts read a JSON config → instantiate a config object.
• Config object drives: dataset loader, model constructor, noise scheduler, optimizer & LR scheduler.
• Training loop:
1. Load batch (toy or real)
2. Forward pass with model + scheduler
3. Backpropagate → update parameters
4. Periodic checkpoint via save_experiment.py
• Inference (test phase): uses trained model + scheduler → sample posterior → save_results.py → plot.
• Data flow: JSON → Config → Components → Results → Storage.
Architectural Patterns & Design Principles
• Modularity: clear separation between “models,” “data,” “training logic,” and “utils.”
• Configuration-driven design: all hyperparameters and experiment settings live in JSON.
• Dependency injection: config module passes parameters into model & scheduler constructors.
• Single-responsibility utilities: each file in csgm/utils/ has one focus (normalization, saving, etc.).
Technologies & Frameworks to Annotate
• Python 3.x, PyTorch, Conda environment
• Fourier Neural Operator (FNO) implementation
• Diffusion/score-based sampling algorithm
• JSON for configuration
• Matplotlib or similar for plotting (implied)