{"id":16494738,"url":"https://github.com/devrimcavusoglu/dmd","last_synced_at":"2025-03-23T13:31:32.175Z","repository":{"id":238351428,"uuid":"779756319","full_name":"devrimcavusoglu/dmd","owner":"devrimcavusoglu","description":"PyTorch implementation of One-step Diffusion with Distribution Matching Distillation","archived":false,"fork":false,"pushed_at":"2024-06-01T14:56:39.000Z","size":12345,"stargazers_count":27,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-18T20:40:48.324Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devrimcavusoglu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2024-03-30T17:40:51.000Z","updated_at":"2025-03-12T10:33:58.000Z","dependencies_parsed_at":"2024-05-05T19:45:30.477Z","dependency_job_id":"639d2af4-c2e9-4735-a1aa-cfff4deba2c0","html_url":"https://github.com/devrimcavusoglu/dmd","commit_stats":null,"previous_names":["devrimcavusoglu/dmd"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devrimcavusoglu%2Fdmd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devrimcavusoglu%2Fdmd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devrimcavusoglu%2Fdmd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devrimcavusoglu%2Fdmd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devrimcavusoglu","download_url":"https://codeload.github.com/devrimcavusoglu/dmd/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245108164,"owners_count":20561998,"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":[],"created_at":"2024-10-11T14:15:27.283Z","updated_at":"2025-03-23T13:31:31.090Z","avatar_url":"https://github.com/devrimcavusoglu.png","language":"Jupyter Notebook","funding_links":[],"categories":["Accelerate"],"sub_categories":[],"readme":"# One-step Diffusion with Distribution Matching Distillation\n\u003ca href=\"https://paperswithcode.com/paper/one-step-diffusion-with-distribution-matching\"\u003e\u003cimg src=\"https://img.shields.io/badge/DMD-temp?style=square\u0026logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJMYXllcl8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDUxMiA1MTIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDUxMiA1MTI7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4gPHN0eWxlIHR5cGU9InRleHQvY3NzIj4gLnN0MHtmaWxsOiMyMUYwRjM7fSA8L3N0eWxlPiA8cGF0aCBjbGFzcz0ic3QwIiBkPSJNODgsMTI4aDQ4djI1Nkg4OFYxMjh6IE0yMzIsMTI4aDQ4djI1NmgtNDhWMTI4eiBNMTYwLDE0NGg0OHYyMjRoLTQ4VjE0NHogTTMwNCwxNDRoNDh2MjI0aC00OFYxNDR6IE0zNzYsMTI4IGg0OHYyNTZoLTQ4VjEyOHoiLz4gPHBhdGggY2xhc3M9InN0MCIgZD0iTTEwNCwxMDRWNTZIMTZ2NDAwaDg4di00OEg2NFYxMDRIMTA0eiBNNDA4LDU2djQ4aDQwdjMwNGgtNDB2NDhoODhWNTZINDA4eiIvPjwvc3ZnPg%3D%3D\u0026label=paperswithcode\u0026labelColor=%23555\u0026color=%2321b3b6\u0026link=https%3A%2F%2Fpaperswithcode.com%2Fpaper%2Fone-step-diffusion-with-distribution-matching\" alt=\"DMD Implementation\"\u003e\u003c/a\u003e\n\u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/devrimcavusoglu/dmd/blob/main/main.ipynb\"\u003e\n  \u003cimg src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/\u003e\n\u003c/a\u003e\n\n![Methodology](assets/methodology.png)\n\nA PyTorch implementation of the paper [One-step Diffusion with Distribution Matching Distillation](https://arxiv.org/abs/2311.18828). This \nproject codebase is mostly based on the codebase of [EDM from NVLabs](https://github.com/NVlabs/edm) and built on top of it with according \nmodifications.\n\nNote that this is an unofficial reimplementation study for the paper, and in this codebase we focused on experimenting \nwith CIFAR-10 dataset reproduce the results. However, the technique may be applicable to other datasets with minor \nadjustments.\n\n## Pretrained Models\n\nYou can access to the experimentation/training logs on [neptune](https://app.neptune.ai/o/metu-ms/org/DMD).\n\n|                     | Model                                                                                                                                  |\n|---------------------|----------------------------------------------------------------------------------------------------------------------------------------|\n| CIFAR-10-32x32-cond | [https://huggingface.co/Devrim/dmd-cifar-10-cond](https://huggingface.co/Devrim/dmd-cifar-10-cond/resolve/main/model.pt?download=true) |\n\n\n## Setup\n\nCreate a conda environment with the configuration file, and activate the environment when necessary.\n\n```shell\nconda env create -f environment.yml\n```\n\nYou can access the CLI by, \n\n```shell\npython -m dmd --help\n```\n\n### Models\n\nDMD method is an application of distillation, and thus requires a teacher model. The teacher diffusion model \nused in the paper was [EDM models](https://github.com/NVlabs/edm). Specifically, for CIFAR-10 we will focus on \na conditioned model. You can see pretrained EDM Models [here](https://nvlabs-fi-cdn.nvidia.com/edm/pretrained/).\n\n### Dataset\n\nDownload the distillation dataset by,\n\n```shell\nbash scripts/download_data.sh\n```\n\nFor reference, sample images from both CIFAR-10 datasets and from the base conditioned pretrained EDM model (CIFAR-10) are shown below:\n\n![Methodology](assets/dataset_samples.png)\n\n## Training\n\nStart training by running\n\n```shell\npython -m dmd train --model-path https://nvlabs-fi-cdn.nvidia.com/edm/pretrained/edm-cifar10-32x32-cond-vp.pkl --data-path /path/to/hdf5_data --output-dir /path/to/output-dir --epochs 2 --batch-size 32\n```\n\nTo see all training arguments run\n\n```shell\npython -m dmd train --help\n```\n\n### Output Images\n\nThe `output_dir` used for saving checkpoints of the model, also used for saving images sampled from the model during training. The images saved are a grid of size `(5, batch_size)` where the rows correspond to `(x, x_real, x_pred, x_ref, y_ref)` respectively. We respect to the paper naming convention for these:\n\n    z: Random sample from N(0,1).\n    x: G(z). (row=1)\n    s: edm_sigma(t) # t ~ U(0,1)\n    noisy_x: forward_diffusion(x, s)  \n    x_real: mu_real(noisy_x, t)  (row=2) # 'pred_real_image' in the paper\n    x_fake: mu_fake(noisy_x, t)  (row=3) # 'pred_fake_image' in the paper\n    z_ref: Paired latent from the synthetic dataset.\n    x_ref: G(z_ref). (row=4)\n    y_ref: Paired image sampled from the base pretrained model. (row=5)\n    \n\n### Logging to Neptune\n\nCreate a `neptune.cfg` file in the project root. The file content should look like this:\n\n```ini\n[credentials]\nproject=\u003cproject-name\u003e\ntoken=\u003creplace-with-your-token\u003e\n```\n\nThen, you can use `--log-neptune` flag to automatically log metrics to your neptune project.\n\n## Generation\nOnce you trained the one-step generator. You can generate samples from it as follows:\n\n```python\nfrom dmd.generate import DMDGenerator\nfrom dmd.utils.common import display_samples\n\ngen = DMDGenerator(network_path=\"/path/to/model_checkpoint.pt\")\nsamples = gen.generate_batch(seeds=list(range(25)), class_ids=0)\ndisplay_samples(samples).show()\n```\n\n## Assumptions\n\n- Hyperparameters are explicitly stated, but there's no information for which model they are used. We assumed for both model when there is no additional information. (optimizer, lr)\n\n## Development\n\nFor convenience add the project root to PYTHONPATH, earlier conda versions support this by `develop` command, run\n\n```shell\nconda develop /path/to/project_root\n```\n\nHowever, `conda develop` is deprecated for recent versions, you can manually add the project root to PYTHONPATH by\n\n```shell\nexport PYTHONPATH=\"${PYTHONPATH}:/path/to/project_root\"\n```\n\n### Code Formatting\n\nTo format the codebase, run\n\n```shell\npython -m scripts.run_code_style format\n```\n\nTo check whether the codebase is well-formatted, run\n\n```shell\npython -m scripts.run_code_style check\n```\n\n## License\n\nCopyright © 2022, NVIDIA CORPORATION \u0026 AFFILIATES. All rights reserved.\\\nCopyright © 2024, Devrim Cavusoglu \u0026 Ahmet Burak Yıldırım\n\nThis work contains the implementation of the methodology and study presented in the *One-step Diffusion with \nDistribution Matching Distillation* paper. Also as the building block of the codebase, [NVLabs/edm](https://github.com/NVlabs/edm) is \nused, modified and adapted accordingly when necessary. As the original license of the underlying framework (edm) \ndictates (ShareAlike), this derived work and all the source are licensed under the same license \nof [Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevrimcavusoglu%2Fdmd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevrimcavusoglu%2Fdmd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevrimcavusoglu%2Fdmd/lists"}