C++17 MNIST training project with serial and MPI backends, focused on data-parallel and model/pipeline-parallel scaling experiments.
- Trains MLPs on raw MNIST IDX files (no framework dependency).
- Uses BLAS-backed dense ops for core compute kernels.
- Supports these training modes:
serial_trainmpi_dp_train(flat data parallel, all-reduce gradients)mpi_dp_hierarchial_train(hierarchical data parallel)mpi_dp_local_sgd_train(periodic model averaging)mpi_mp_train(sequential model parallel)mpi_mp_pip_train(pipeline model parallel, optional load-balanced partitioning)
- Writes per-epoch metrics to CSV for all modes.
- CMake >= 3.16
- C++17 compiler (GCC >= 9 recommended; enforced by
NN_FORCE_MODERN_GCC=ON) - BLAS
- MPI (for MPI binaries)
- Slurm
srunfor cluster launch scripts
bash scripts/build.shClean rebuild:
bash scripts/build.sh --cleanOverride compiler:
NN_CXX_COMPILER=/path/to/g++ bash scripts/build.sh --cleanDownload/extract MNIST into data/mnist:
bash scripts/prepare_mnist.shMost run scripts call this automatically.
- Smoke:
bash scripts/run_serial_smoke.sh
- Perf:
bash scripts/run_serial_perf.sh
Serial smoke overrides: SMOKE_EPOCHS, SMOKE_BATCH_SIZE, SMOKE_TRAIN_SAMPLES, SMOKE_VAL_SAMPLES, SMOKE_LEARNING_RATE, SMOKE_HIDDEN.
Serial perf overrides: EPOCHS, BATCH_SIZE, TRAIN_SAMPLES, VAL_SAMPLES, LEARNING_RATE, HIDDEN, OUT_CSV.
- Flat DP smoke:
bash scripts/run_mpi_dp_smoke.sh
- Flat DP perf:
bash scripts/run_mpi_dp_perf.sh
- Hierarchical DP smoke:
bash scripts/run_mpi_dp_hierarchial_smoke.sh
- Hierarchical DP perf:
bash scripts/run_mpi_dp_hierarchial_perf.sh
- Local-SGD DP perf:
bash scripts/run_mpi_dp_local_sgd_perf.sh
Common DP launcher overrides:
DP_NODESDP_TASKS_PER_NODEDP_CPUS_PER_TASKGLOBAL_BATCH(orSMOKE_GLOBAL_BATCHin smoke scripts)OUT_CSV(all perf scripts; also hierarchical smoke)SYNC_EVERY(Local-SGD only)
- Model-parallel smoke:
bash scripts/run_mpi_mp_smoke.sh
- Model-parallel perf:
bash scripts/run_mpi_mp_perf.sh
- Pipeline smoke:
bash scripts/run_mpi_mp_pip_smoke.sh
- Pipeline perf:
bash scripts/run_mpi_mp_pip_perf.sh
Common MP launcher overrides:
MP_NODESMP_TASKS_PER_NODEMP_CPUS_PER_TASKBATCH_SIZE/SMOKE_BATCHMICROBATCHES/SMOKE_MICROBATCHES(pipeline)BALANCE_LAYERS=true(pipeline perf; passes--load-balance-layers)OUT_CSV(all perf scripts)
Data-parallel sweep (flat + hierarchical + local-SGD):
bash scripts/run_dp_scaling_study.shOutputs under results/scaling/ and can be summarized with:
python3 results/scaling/summarize_dp_scaling.py results/scalingModel/pipeline sweep (batch/microbatch/world-size charts):
bash scripts/run_mp_scaling_study.shAlternative fixed layout sweep:
bash scripts/run_mp_scaling_study_2x4_m_32.shVisualize sweep outputs:
python3 src/visualize_sweep.py <charts_output_dir>All binaries share common CLI flags:
--epochs--batch--lr--seed--train-samples--val-samples--hidden(comma-separated)--data-dir--output
Mode-specific flags:
--sync-every(local-SGD DP)--microbatches(pipeline MP)--load-balance-layers(pipeline MP)
Examples:
./build/serial_train --epochs 5 --batch 256 --hidden 256,128,64 --data-dir data/mnist --output results/serial.csvsrun -N 1 -n 4 ./build/mpi_dp_train --epochs 5 --batch 1024 --hidden 256,128,64 --data-dir data/mnist --output results/mpi_dp.csvsrun -N 2 -n 4 ./build/mpi_mp_pip_train --epochs 2 --batch 4096 --microbatches 32 --load-balance-layers --hidden 512,512,256,256,128,64,32 --data-dir data/mnist --output results/mpi_mp_pip.csvThe report sources are in report/ (main.tex, generated main.pdf).
Build PDF:
cd report
latexmk -pdf main.tex- Threading is pinned to 1 in run scripts (
OMP_NUM_THREADS=1,OPENBLAS_NUM_THREADS=1,MKL_NUM_THREADS=1) to avoid oversubscription. - Some filenames intentionally use
hierarchial(spelling preserved for compatibility with existing scripts/binaries).