def test_multiple_optimizers_logging(precision, tmp_path):
    """Tests that metrics are properly being logged."""

    class TestModel(BoringModel):
        def __init__(self):
            super().__init__()
            self.automatic_optimization = False

        def training_step(self, batch, batch_idx):
            optimizer1, optimizer2 = self.optimizers()
            # Discriminator.
            self.toggle_optimizer(optimizer1)

            loss_d = self.step(batch)
            self.log("loss_d", loss_d, prog_bar=True)

            optimizer1.zero_grad()
            self.manual_backward(loss_d)
            optimizer1.step()
            self.untoggle_optimizer(optimizer1)

            # Generator.
            self.toggle_optimizer(optimizer2)

            loss_g = self.step(batch)
            self.log("loss_g", loss_g, prog_bar=True)

            optimizer2.zero_grad()
            self.manual_backward(loss_g)
            optimizer2.step()
            self.untoggle_optimizer(optimizer2)

        def configure_optimizers(self):
            optimizer = torch.optim.SGD(self.layer.parameters(), lr=0.1)
            optimizer_2 = torch.optim.SGD(self.layer.parameters(), lr=0.1)
            return optimizer, optimizer_2

    model = TestModel()
    model.val_dataloader = None

    trainer = Trainer(
        default_root_dir=tmp_path,
        limit_train_batches=2,
        limit_val_batches=2,
        max_epochs=1,
        log_every_n_steps=1,
        enable_model_summary=False,
        accelerator="gpu",
        devices=1,
        precision=precision,
    )

    trainer.fit(model)

    assert set(trainer.logged_metrics) == {"loss_d", "loss_g"}
    assert set(trainer.progress_bar_metrics) == {"loss_d", "loss_g"}
Tests that metrics are properly being logged.
tests/tests_pytorch/trainer/optimization/test_manual_optimization.py