{"id":25437698,"url":"https://github.com/christianlin0420/diffusion-model-universal","last_synced_at":"2025-11-01T07:30:27.837Z","repository":{"id":271816153,"uuid":"914646403","full_name":"ChristianLin0420/diffusion-model-universal","owner":"ChristianLin0420","description":"A comprehensive PyTorch-based framework for training and experimenting with various diffusion models. This project provides a modular and flexible implementation of multiple diffusion model variants, including DDPM, DDIM, Score-based, and Energy-based models.","archived":false,"fork":false,"pushed_at":"2025-01-10T03:53:42.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-10T04:22:48.351Z","etag":null,"topics":["deep-learning","diffusion-models","energy-based-model","generative-ai","machine-learning","score-based-generative-models"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChristianLin0420.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-10T02:36:47.000Z","updated_at":"2025-01-10T03:54:31.000Z","dependencies_parsed_at":"2025-01-10T04:22:52.314Z","dependency_job_id":"0e7dd37b-c5f7-42f7-a022-864c135753a5","html_url":"https://github.com/ChristianLin0420/diffusion-model-universal","commit_stats":null,"previous_names":["christianlin0420/diffusion-model-universal"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristianLin0420%2Fdiffusion-model-universal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristianLin0420%2Fdiffusion-model-universal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristianLin0420%2Fdiffusion-model-universal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristianLin0420%2Fdiffusion-model-universal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChristianLin0420","download_url":"https://codeload.github.com/ChristianLin0420/diffusion-model-universal/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239262396,"owners_count":19609519,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","diffusion-models","energy-based-model","generative-ai","machine-learning","score-based-generative-models"],"created_at":"2025-02-17T09:19:28.876Z","updated_at":"2025-11-01T07:30:27.786Z","avatar_url":"https://github.com/ChristianLin0420.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Diffusion Models Universal\n\nA comprehensive PyTorch-based framework for training and experimenting with various diffusion models. This project provides a modular and flexible implementation of multiple diffusion model variants, including DDPM, DDIM, Score-based, and Energy-based models.\n\n## Features\n\n### Multiple Model Implementations\n- **[DDPM (Denoising Diffusion Probabilistic Models)](docs/ddpm.md)**\n  - Standard diffusion model with forward and reverse processes\n  - Configurable noise schedule\n  - [Detailed Documentation](docs/ddpm.md)\n  \n- **DDIM (Denoising Diffusion Implicit Models)**\n  - Accelerated sampling with fewer steps\n  - Deterministic or stochastic sampling options\n  \n- **Score-based Diffusion**\n  - Score matching with Langevin dynamics\n  - Continuous noise schedule\n  - Configurable temperature parameters\n  \n- **Energy-based Diffusion**\n  - Energy-based modeling with annealed Langevin dynamics\n  - Gradient penalty regularization\n  - Time conditioning options\n\n### Supported Datasets\n- **MNIST**\n  - Standard 28x28 grayscale images\n  - Automatically converted to RGB and resized\n  - Basic augmentation with normalization\n  \n- **CIFAR-10**\n  - 32x32 RGB natural images\n  - 10 classes of objects\n  - Includes random horizontal flips\n  - Normalized to [-1, 1] range\n  \n- **CelebA**\n  - High-quality celebrity face images\n  - Center-cropped and resized\n  - Supports different image sizes (default: 64x64)\n  - Includes standard preprocessing and augmentation\n\n### Flexible Loss Functions\nAll models support multiple loss functions that can be configured via YAML:\n- MSE Loss\n- L1 Loss\n- Huber Loss\n- Hybrid Loss (weighted combination)\n- Time-dependent weighting\n- Model-specific losses (Score Matching, Energy-based)\n\n### Dataset Support\n- MNIST (default)\n- Extensible for other datasets (CIFAR-10, CelebA, etc.)\n- Easy-to-add custom datasets\n\n### Training Features\n- Configurable training parameters\n- Checkpoint saving and loading\n- Sample generation during training\n- Wandb integration for experiment tracking\n- Multi-GPU support\n\n## Project Structure\n```\n├── models/          # Model implementations\n│   ├── ddpm.py\n│   ├── ddim.py\n│   ├── score_based.py\n│   └── energy_based.py\n├── datasets/        # Dataset loaders\n├── trainers/        # Training implementations\n├── utils/          # Helper functions\n├── configs/        # Configuration files\n├── scripts/        # Training and generation scripts\n└── tests/          # Unit tests\n```\n\n## Installation\n\n1. Clone the repository:\n```bash\ngit clone https://github.com/yourusername/diffusion-model-universal.git\ncd diffusion-model-universal\n```\n\n2. Create a virtual environment:\n```bash\npython -m venv venv\nsource venv/bin/activate  # On Windows: venv\\Scripts\\activate\n```\n\n3. Install dependencies:\n```bash\npip install -r requirements.txt\n```\n\n## Usage\n\n### Training Models\n\n1. Choose or modify a configuration file from `configs/`:\n   - `ddpm_config.yaml`\n   - `ddim_config.yaml`\n   - `score_based_config.yaml`\n   - `energy_based_config.yaml`\n\n2. Start training:\n```bash\n# Train DDPM\npython scripts/train.py --config configs/ddpm_config.yaml --model_type ddpm\n\n# Train DDIM\npython scripts/train.py --config configs/ddim_config.yaml --model_type ddim\n\n# Train Score-based model\npython scripts/train.py --config configs/score_based_config.yaml --model_type score_based\n\n# Train Energy-based model\npython scripts/train.py --config configs/energy_based_config.yaml --model_type energy_based\n\n# Resume training from checkpoint\npython scripts/train.py --config configs/ddpm_config.yaml --model_type ddpm --resume path/to/checkpoint.pt\n```\n\n### Generating Samples\n```bash\npython scripts/generate.py --config configs/ddpm_config.yaml --model_type ddpm --checkpoint path/to/checkpoint.pt --num_samples 16\n```\n\n### Configuration Guide\n\n#### Loss Configuration\nEach model supports flexible loss functions that can be configured in the YAML files:\n\n1. **Basic Loss Types**:\n```yaml\nmodel:\n  loss_type: 'mse'  # Options: 'mse', 'l1', 'huber'\n  loss_config:\n    reduction: 'mean'  # Options: 'mean', 'sum', 'none'\n```\n\n2. **Hybrid Loss**:\n```yaml\nmodel:\n  loss_type: 'hybrid'\n  loss_config:\n    weights:\n      mse: 0.6\n      l1: 0.3\n      huber: 0.1\n```\n\n3. **Time-weighted Loss**:\n```yaml\nmodel:\n  loss_config:\n    time_weights:\n      type: 'linear'  # or 'exponential'\n      max_timesteps: 1000\n      beta: 0.1  # for exponential weighting\n```\n\n4. **Model-specific Losses**:\n```yaml\n# Score-based model\nmodel:\n  loss_type: 'score_matching'\n  loss_config:\n    sigma_min: 0.01\n    sigma_max: 50.0\n\n# Energy-based model\nmodel:\n  loss_type: 'energy_based'\n  loss_config:\n    energy_scale: 1.0\n    regularization_weight: 0.1\n```\n\n#### Dataset-specific Configurations\nExample configurations are provided for each dataset:\n\n1. **MNIST Configuration**:\n```yaml\ndataset:\n  name: \"mnist\"\n  data_dir: \"./data\"\n  image_size: 32\n```\n\n2. **CIFAR-10 Configuration**:\n```yaml\ndataset:\n  name: \"cifar10\"\n  data_dir: \"./data\"\n  image_size: 32  # Native CIFAR-10 size\n```\n\n3. **CelebA Configuration**:\n```yaml\ndataset:\n  name: \"celeba\"\n  data_dir: \"./data\"\n  image_size: 64  # Can be adjusted based on needs\n  crop_size: 178  # CelebA-specific center crop\n```\n\n## Extending the Framework\n\n### Adding New Models\n1. Create a new model file in `models/`\n2. Inherit from `BaseDiffusion`\n3. Implement required methods: `forward`, `loss_function`, `sample`\n4. Add model to `MODEL_REGISTRY` in `train.py`\n5. Create corresponding configuration file\n\n### Adding New Datasets\n1. Create a new dataset loader in `datasets/`\n2. Implement data preprocessing and augmentation\n3. Add dataset to `get_dataset()` in `train.py`\n\n### Adding New Loss Functions\n1. Add new loss implementation to `utils/losses.py`\n2. Update `DiffusionLoss` class with new loss type\n3. Add corresponding configuration options\n\n## Contributing\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\nThis project is licensed under the MIT License - see the LICENSE file for details. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristianlin0420%2Fdiffusion-model-universal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristianlin0420%2Fdiffusion-model-universal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristianlin0420%2Fdiffusion-model-universal/lists"}