(
self,
height: Optional[int] = 256,
width: Optional[int] = 256,
num_inference_steps: Optional[int] = 50,
generator: Optional[torch.Generator] = None,
batch_size: Optional[int] = 1,
output_type: Optional[str] = "pil",
return_dict: bool = True,
**kwargs,
)
| 227 | |
| 228 | @torch.no_grad() |
| 229 | def __call__( |
| 230 | self, |
| 231 | height: Optional[int] = 256, |
| 232 | width: Optional[int] = 256, |
| 233 | num_inference_steps: Optional[int] = 50, |
| 234 | generator: Optional[torch.Generator] = None, |
| 235 | batch_size: Optional[int] = 1, |
| 236 | output_type: Optional[str] = "pil", |
| 237 | return_dict: bool = True, |
| 238 | **kwargs, |
| 239 | ) -> Union[Tuple, ImagePipelineOutput]: |
| 240 | latents = torch.randn( |
| 241 | (batch_size, self.unet.config.in_channels, height, width), |
| 242 | generator=generator, |
| 243 | ) |
| 244 | latents = decimal_to_bits(latents) * self.bit_scale |
| 245 | latents = latents.to(self.device) |
| 246 | |
| 247 | self.scheduler.set_timesteps(num_inference_steps) |
| 248 | |
| 249 | for t in self.progress_bar(self.scheduler.timesteps): |
| 250 | # predict the noise residual |
| 251 | noise_pred = self.unet(latents, t).sample |
| 252 | |
| 253 | # compute the previous noisy sample x_t -> x_t-1 |
| 254 | latents = self.scheduler.step(noise_pred, t, latents).prev_sample |
| 255 | |
| 256 | image = bits_to_decimal(latents) |
| 257 | |
| 258 | if output_type == "pil": |
| 259 | image = self.numpy_to_pil(image) |
| 260 | |
| 261 | if not return_dict: |
| 262 | return (image,) |
| 263 | |
| 264 | return ImagePipelineOutput(images=image) |
nothing calls this directly
no test coverage detected