2 optimizers : skip updates for the second optim
❓ Questions and Help
What is your question?
I have a model with 2 optimizers : one for the backbone weight and second for "backbone support" weights. However, 2nd optimizer should only accumulate grads through the whole epoch and perform one update at the epoch end.
Lightning keeps asking for an output for the 2nd optimizer, but there is nothing to output in addition to the first optimizer results. How can I bypass this ?
Code
Here are defined the training_step and optimizer_step functions to illustrate my issue.
def training_step(self, batch, batch_idx, optimizer_idx):
        if optimizer_idx == 0:
            images, target = batch
            output = self(images)
            loss_val = F.cross_entropy(output, target)
            acc1, acc5 = self.__accuracy(output, target, topk=(1, 5))
            weight_cons, act_cons, weight_p_c_cons = self.normalized_consumption()

            tqdm_dict = {'Loss/train_loss': loss_val, 
                        'Acc/acc1': acc1,
                        'Acc/acc5': acc5,}
            output = OrderedDict({
                'loss': loss_val,
                'Loss/loss': loss_val,
                'Acc/acc1': acc1,
                'Acc/acc5': acc5,
                'progress_bar': tqdm_dict,
                'log': tqdm_dict
            })
            return output
     if optimizer_idx == 1:
         # Do nothing ?

def optimizer_step(self, current_epoch, batch_nb, optimizer, optimizer_i, second_order_closure=None):
        if optimizer_i == 0:
            optimizer.step()
            optimizer.zero_grad()

        # update 2nd optimizer at the end of the epoch
        if optimizer_i == 1 and self.__nbbatch -1 <= batch_nb:
            optimizer.step()
            optimizer.zero_grad()

   
What have you tried?
I tried to pass an empty output dict in training_step if the optimizer_idx == 1. However, Lightning complains that the dict is empty (trainer/logging.py:106 -> Nonetype has no attribute 'items')
What's your environment?

OS: Linux
Packaging pip
Version 0.7.5