{"id":13477983,"url":"https://github.com/tonyduan/diffusion","last_synced_at":"2025-10-28T09:21:19.313Z","repository":{"id":84796206,"uuid":"594998396","full_name":"tonyduan/diffusion","owner":"tonyduan","description":"From-scratch diffusion model implemented in PyTorch.","archived":false,"fork":false,"pushed_at":"2024-02-06T09:26:42.000Z","size":2414,"stargazers_count":87,"open_issues_count":3,"forks_count":10,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T09:09:50.604Z","etag":null,"topics":["diffusion","generative-models","pytorch"],"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/tonyduan.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":"2023-01-30T07:13:44.000Z","updated_at":"2025-04-07T23:16:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"7dc30879-2059-4376-ab5f-934927f91d95","html_url":"https://github.com/tonyduan/diffusion","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyduan%2Fdiffusion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyduan%2Fdiffusion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyduan%2Fdiffusion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyduan%2Fdiffusion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tonyduan","download_url":"https://codeload.github.com/tonyduan/diffusion/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248231537,"owners_count":21069348,"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":["diffusion","generative-models","pytorch"],"created_at":"2024-07-31T16:01:50.861Z","updated_at":"2025-10-28T09:21:14.293Z","avatar_url":"https://github.com/tonyduan.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"### Diffusion Models From Scratch\n\nMarch 2023.\n\n---\n\nMy notes for this repository ended up longer than expected, too long to be rendered by GitHub.\n\nSo instead of putting notes here, they've been moved to my website.\n\n[[**This blog post**]](https://www.tonyduan.com/diffusion/index.html) explains the intuition and derivations behind diffusion.\n\n---\n\nThis codebase provides a *minimalist* re-production of the MNIST example below.\n\nIt clocks in at well under 500 LOC.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"examples/ex_mnist_crop.png\"/\u003e\n\u003c/p\u003e\n\n(Left: MNIST groundtruth. Right: MNIST sampling starting from random noise).\n\n---\n\n**Example Usage**\n\nCode below is copied from `examples/ex_mnist_simple.py`, omitting boilerplate training code.\n\n```python\n    # Initialization\n    nn_module = UNet(in_dim=1, embed_dim=128, dim_scales=(1, 2, 4, 8))\n    model = DiffusionModel(\n        nn_module=nn_module,\n        input_shape=(1, 32, 32,),\n        config=DiffusionModelConfig(\n            num_timesteps=500,\n            target_type=\"pred_x_0\",\n            gamma_type=\"ddim\",\n            noise_schedule_type=\"cosine\",\n        ),\n    )\n\n    # Training Loop\n    for i in range(args.iterations):\n        loss = model.loss(x_batch).mean()\n        loss.backward()\n\n    # Sampling, the number of timesteps can be less than T to accelerate\n    samples = model.sample(bsz=64, num_sampling_timesteps=None, device=\"cuda\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonyduan%2Fdiffusion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftonyduan%2Fdiffusion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonyduan%2Fdiffusion/lists"}