Download main/one_step_unet.py from diffusers/community-pipelines-mirror: direct link, hf CLI and curl.
- Browser
- Download file 721 Bytes
-
https://huggingface.co/datasets/diffusers/community-pipelines-mirror/resolve/ae21657e8dc2b00a659937b46ab4f92f80e8d9a7/main/one_step_unet.py
- Command line
-
hf download hf://datasets/diffusers/community-pipelines-mirror@ae21657e8dc2b00a659937b46ab4f92f80e8d9a7/main/one_step_unet.py
-
curl -L -o one_step_unet.py https://huggingface.co/datasets/diffusers/community-pipelines-mirror/resolve/ae21657e8dc2b00a659937b46ab4f92f80e8d9a7/main/one_step_unet.py
721 Bytes
| #!/usr/bin/env python3 | |
| import torch | |
| from diffusers import DiffusionPipeline | |
| class UnetSchedulerOneForwardPipeline(DiffusionPipeline): | |
| def __init__(self, unet, scheduler): | |
| super().__init__() | |
| self.register_modules(unet=unet, scheduler=scheduler) | |
| def __call__(self): | |
| image = torch.randn( | |
| (1, self.unet.config.in_channels, self.unet.config.sample_size, self.unet.config.sample_size), | |
| ) | |
| timestep = 1 | |
| model_output = self.unet(image, timestep).sample | |
| scheduler_output = self.scheduler.step(model_output, timestep, image).prev_sample | |
| result = scheduler_output - scheduler_output + torch.ones_like(scheduler_output) | |
| return result | |