code: def test_amp_skip_optimizer(tmpdir):
      """Test that optimizers can be skipped when using amp."""
  
      class CustomBoringModel(BoringModel):
          def __init__(self):
              super().__init__()
              self.automatic_optimization = False
              self.layer1 = torch.nn.Linear(32, 32)
              self.layer2 = torch.nn.Linear(32, 2)
  
          def forward(self, x: Tensor):
              x = self.layer1(x)
              x = self.layer2(x)
              return x
  
          def training_step(self, batch, batch_idx):
              _, opt2 = self.optimizers()
              output = self(batch)
              loss = self.loss(output)
              opt2.zero_grad()
              self.manual_backward(loss)
              # only optimizer 2 steps
              opt2.step()
  
          def configure_optimizers(self):
              return [
                  torch.optim.SGD(self.layer1.parameters(), lr=0.1),
                  torch.optim.SGD(self.layer2.parameters(), lr=0.1),
              ]
  
      trainer = Trainer(
          default_root_dir=tmpdir,
          accelerator="gpu",
          devices=1,
          fast_dev_run=1,
          precision="16-mixed",
      )
      model = CustomBoringModel()
      trainer.fit(model)
  
imports: import os
  import re
  from unittest import mock
  import pytest
  import torch
  from lightning.pytorch import Trainer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.plugins import MixedPrecision
  from torch import Tensor
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 3 for calling a global function with example usage: test_amp_skip_optimizer(tmpdir) and returns: x, list