(self, x_noisy, t, cond, *args, **kwargs)
| 343 | return x, dict(c_crossattn=[c], c_concat_mask=[control_mask], c_concat_image=[control_image]) |
| 344 | |
| 345 | def apply_model(self, x_noisy, t, cond, *args, **kwargs): |
| 346 | assert isinstance(cond, dict) |
| 347 | diffusion_model = self.model.diffusion_model |
| 348 | |
| 349 | cond_txt = torch.cat(cond['c_crossattn'], 1) |
| 350 | |
| 351 | if cond['c_concat'] is None: |
| 352 | eps = diffusion_model(x=x_noisy, timesteps=t, context=cond_txt, control=None, only_mid_control=self.only_mid_control) |
| 353 | else: |
| 354 | if 'c_concat_image' in cond: |
| 355 | control_model_mask = copy.deepcopy(self.control_model).requires_grad_(False) |
| 356 | diffusion_model_image = copy.deepcopy(diffusion_model) |
| 357 | control_weights_mask = 1.0 |
| 358 | control_weights_image = 1.0 * self.global_step / self.trainer.max_steps |
| 359 | control_image = self.control_model(x=x_noisy, hint=torch.cat(cond['c_concat_image'], 1), timesteps=t, context=cond_txt) |
| 360 | control_image = [c * scale for c, scale in zip(control_image, self.control_scales)] |
| 361 | with torch.no_grad(): |
| 362 | control_mask = control_model_mask(x=x_noisy, hint=torch.cat(cond['c_concat'], 1), timesteps=t, context=cond_txt) |
| 363 | control_mask = [c * scale for c, scale in zip(control_mask, self.control_scales)] |
| 364 | control = [control_weights_mask * c_mask.detach() + control_weights_image * c_image for c_mask, c_image in zip(control_mask, control_image)] |
| 365 | eps = diffusion_model_image(x=x_noisy, timesteps=t, context=cond_txt, control=control, only_mid_control=self.only_mid_control) |
| 366 | else: |
| 367 | control = self.control_model(x=x_noisy, hint=torch.cat(cond['c_concat'], 1), timesteps=t, context=cond_txt) |
| 368 | control = [c * scale for c, scale in zip(control, self.control_scales)] |
| 369 | eps = diffusion_model(x=x_noisy, timesteps=t, context=cond_txt, control=control, only_mid_control=self.only_mid_control) |
| 370 | |
| 371 | return eps |
| 372 | |
| 373 | @torch.no_grad() |
| 374 | def get_unconditional_conditioning(self, N): |
no outgoing calls
no test coverage detected