code: def test_configure_model(monkeypatch):
      module = lightning.fabric.plugins.precision.transformer_engine
      if module._TRANSFORMER_ENGINE_AVAILABLE:
          pytest.skip("Assumes transformer_engine is unavailable")
      monkeypatch.setattr(
          module, "_TRANSFORMER_ENGINE_AVAILABLE", lambda: True
      )
      te_mock = Mock()
      te_mock.pytorch.fp8_autocast.return_value = nullcontext()
  
      class ModuleMock(torch.nn.Linear):
          def __init__(
              self, in_features, out_features, bias=True, *_, **__
          ):
              super().__init__(in_features, out_features, bias)
  
      te_mock.pytorch.Linear = ModuleMock
      monkeypatch.setitem(sys.modules, "transformer_engine", te_mock)
      monkeypatch.setitem(
          sys.modules, "transformer_engine.pytorch", te_mock
      )
      monkeypatch.setitem(
          sys.modules, "transformer_engine.common.recipe", te_mock
      )
  
      class MyModel(LightningModule):
          def configure_model(self):
              self.l = torch.nn.Linear(8, 16)
              assert self.l.weight.dtype == torch.float16
  
          def test_step(self, *_):
              ...
  
      model = MyModel()
      trainer = Trainer(
          barebones=True, precision="transformer-engine-float16"
      )
      trainer.test(model, [0])
      te_mock.pytorch.fp8_autocast.assert_called_once_with(
          enabled=True, fp8_recipe=ANY
      )
      # TODO: invert condition once this gets fixed
      assert not isinstance(model.l, ModuleMock)
      assert model.l.weight.dtype == torch.float16
  
file_path: pytorch-lightning/tests/tests_pytorch/plugins/precision/test_transformer_engine.py
imports: import sys
  from contextlib import nullcontext
  from unittest.mock import ANY, Mock
  import lightning.fabric
  import pytest
  import torch
  from lightning.pytorch import LightningModule, Trainer
  from lightning.pytorch.plugins import TransformerEnginePrecision
  from lightning.pytorch.trainer.connectors.accelerator_connector import _AcceleratorConnector
label_desc: Use image node_id 2 for calling a global function with example usage: test_configure_model(monkeypatch) without return types