(self)
| 282 | controller.num_att_layers = cross_att_count |
| 283 | |
| 284 | def configure_optimizers(self): |
| 285 | lr = self.learning_rate |
| 286 | params = [] |
| 287 | |
| 288 | if self.freeze_model == 'crossattn-k': |
| 289 | for x in self.model.diffusion_model.named_parameters(): |
| 290 | if 'transformer_blocks' in x[0]: |
| 291 | if 'attn2.to_k' in x[0]: |
| 292 | params += [x[1]] |
| 293 | print(x[0]) |
| 294 | elif self.freeze_model == 'crossattn-kv': |
| 295 | for x in self.model.diffusion_model.named_parameters(): |
| 296 | if 'transformer_blocks' in x[0]: |
| 297 | if 'attn2.to_k' in x[0] or 'attn2.to_v' in x[0]: |
| 298 | params += [x[1]] |
| 299 | print(x[0]) |
| 300 | elif self.freeze_model == 'crossattn-qkv': |
| 301 | for x in self.model.diffusion_model.named_parameters(): |
| 302 | if 'transformer_blocks' in x[0]: |
| 303 | if 'attn2.to_k' in x[0] or 'attn2.to_v' in x[0] or 'attn2.to_q' in x[0]: |
| 304 | params += [x[1]] |
| 305 | print(x[0]) |
| 306 | elif self.freeze_model == 'selfattn-crossattn-qkv': |
| 307 | for x in self.model.diffusion_model.named_parameters(): |
| 308 | if 'transformer_blocks' in x[0]: |
| 309 | if ('attn2.to_k' in x[0] or 'attn2.to_v' in x[0] or 'attn2.to_q' in x[0] or 'attn1.to_k' in x[0] or 'attn1.to_v' in x[0] or 'attn1.to_q' in x[0]): |
| 310 | params += [x[1]] |
| 311 | print(x[0]) |
| 312 | |
| 313 | elif self.freeze_model == 'crossattn': |
| 314 | for x in self.model.diffusion_model.named_parameters(): |
| 315 | if 'transformer_blocks' in x[0]: |
| 316 | if 'attn2' in x[0]: |
| 317 | params += [x[1]] |
| 318 | print(x[0]) |
| 319 | else: |
| 320 | params = list(self.model.parameters()) |
| 321 | |
| 322 | if self.cond_stage_trainable: |
| 323 | print(f"{self.__class__.__name__}: Also optimizing conditioner params!") |
| 324 | if self.add_token: |
| 325 | params = params + list(self.cond_stage_model.transformer.text_model.embeddings.token_embedding.parameters()) |
| 326 | else: |
| 327 | params = params + list(self.cond_stage_model.parameters()) |
| 328 | |
| 329 | if self.learn_logvar: |
| 330 | print('Diffusion model optimizing logvar') |
| 331 | params.append(self.logvar) |
| 332 | opt = torch.optim.AdamW(params, lr=lr) |
| 333 | if self.use_scheduler: |
| 334 | assert 'target' in self.scheduler_config |
| 335 | scheduler = instantiate_from_config(self.scheduler_config) |
| 336 | |
| 337 | print("Setting up LambdaLR scheduler...") |
| 338 | scheduler = [ |
| 339 | { |
| 340 | 'scheduler': LambdaLR(opt, lr_lambda=scheduler.schedule), |
| 341 | 'interval': 'step', |
nothing calls this directly
no outgoing calls
no test coverage detected