Thanks for reaching out ! To be more precise, my models inherit from a BaseClass that itself is a combination of nn.Module and an Abstract Class.
The model is then fed in a pipeline that can quickly test different configurations of the underlying model. I wanted the optimizer to be defined here so that when a new architecture is implemented it could go into the pipeline independently of if it is a GAN or simple DCNN.
Here is an example:
def optimize(self, losses):                                                                                        
         gen_losses = ['G_Trick', 'L1_img', 'VGG_img', 'L1_probes']                                                     
         disc_losses = ['D_Fakes', 'D_Reals']                                                                           
         gen_loss = sum([losses[x] for x in gen_losses])                                                                
         self.optimizers['optimizer_G'].zero_grad()                                                                                 
         gen_loss.backward()                                                                                            
         self.optimizers['optimizer_G'].step()                                                                          
                                                                                                                        
         disc_loss = sum([losses[x] for x in disc_losses])  
         self.optimizers['optimizer_D'].zero_grad()                                                                                                                                 
         disc_loss.backward()                                                                                           
         self.optimizers['optimizer_D'].step()