The Problem
Training a diffusion model with only a few sampling steps is costly and unstable. SMD delivers a lightweight, reproducible framework for on‑policy distillation that keeps the training pipeline simple while still supporting image, video, audio‑video and 3‑D generation tasks.
What This Does
SMD bundles config-driven training, callback‑based monitoring, and a suite of dataset loaders that map raw data to the formats required by diffusion models. The core logic lives in smd/methods/simplified_distill/basis/__main__.py, which parses a config file (e.g. smd/configs/experiments/flux1_dev.py), builds a training loop, and hands training to the callbacks defined under /smd/callbacks.
smd/configs/config.pyloads the experiment configuration and validates it.smd/datasets/bucketed_image_loader.pyand the other loader modules turn a dataset into atorch.utils.data.DataLoaderthat feeds the diffusion model.smd/callbacks/ema.py,grad_clip.py,sampling/engine.pyand others provide training utilities such as exponential‑moving‑average, gradient clipping, sampling engines, and wandb integration.
The inference side is isolated in infer.py, which accepts a trained student directory, performs a single forward pass, and writes samples to disk.
How It Is Wired
Entry point – smd/methods/simplified_distill/basis/__main__.py.
__main__importssmd.configs.config→load_config→ returns aConfigobject.- The config object supplies the dataset path, model hyper‑parameters, and callback list.
__main__creates the dataset viasmd.datasets.bucketed_batching.BucketedBatching→smd.datasets.bucketed_image_loader.BucketedImageLoader(or the appropriate loader for the task).- A training loop is instantiated, which calls the callback chain:
smd.callbacks.callback.Callbackbase class is invoked on each epoch/batch.smd.callbacks.ema.EMAupdates the teacher‑student weights. *smd.callbacks.sampling.engine.Engineruns the diffusion sampler for the reduced step count. - After training, the student weights are written to the checkpoint directory (
--weightsfor inference).
What this code touches outside itself
- Filesystem – writes checkpoints and sample images; reads dataset shards from
assets/examples/.... - GPU – all math is performed with PyTorch (
torch), requiring CUDA 12.6. - Hugging Face – optional export to the Hub via
smd.callbacks.export_inference_bundle.py.
The widest blast radius is the callback system: any change to a callback implementation (e.g., adding a new logging callback) requires updating the callback registration in the experiment config (smd/configs/experiments/...py).
How To Use It
Setup
# clone
git clone https://github.com/moses-y/SMD
cd SMD
# create the base environment
bash environments/setup_conda.sh
conda activate smd
For 3‑D rendering support:
bash environments/setup_3d_environment.sh
conda activate smd_3d_extend
Configuration
Edit an experiment file such as smd/configs/experiments/flux1_dev.py:
dataset_path: local path to your data shardmodel_cfg: architecture and training hyper‑parameterscallbacks: list of callback class names
Running training
python smd/methods/simplified_distill/basis/__main__.py \
--config smd/configs/experiments/flux1_dev.py
Inference
python infer.py qwen_image \
--weights /path/to/exported_student \
--output /tmp/samples \
--prompt "A red ceramic mug on a wooden table."
The script writes PNGs to /tmp/samples.
Real‑World Use
A content‑creation studio can integrate the inference script into a web API:
from flask import Flask, request, send_file
app = Flask(__name__)
@app.route('/generate', methods=['POST'])
def generate():
prompt = request.json['prompt']
output_path = '/tmp/samples/out.png'
subprocess.run([
'python', 'infer.py', 'qwen_image',
'--weights', '/models/qwen_student',
'--output', '/tmp/samples',
'--prompt', prompt
])
return send_file(output_path, mimetype='image/png')
The API can be containerised and deployed behind a load balancer, producing high‑fidelity images from few‑step diffusion models.
Code Health & Issues
- Medium / SDLC – No CI/CD pipeline. The repository lacks a
.github/folder or any CI configuration; automated test gating is absent. - Low / Reproducibility – Dependencies are declared in
pyproject.tomlandrequirements.txtbut no lockfile is present, making builds non‑deterministic. - Missing tests – Only five test files exist in the root; coverage is minimal.
These observations come from a static scan of the directory tree and configuration files.
The Bottom Line
SMD offers a focused, config‑driven framework for few‑step diffusion distillation across multiple modalities. Its modular callback system and clear separation of dataset, training, and inference code make it approachable for developers willing to tailor the pipeline. However, lacking CI and a lockfile limits reproducibility and automated quality assurance. Teams that value rapid prototype cycles and have internal testing capabilities will benefit most.