code: def _test_create_supervised_trainer(
      gradient_accumulation_steps: int = 1,
      model_device: Optional[str] = None,
      trainer_device: Optional[str] = None,
      trace: bool = False,
      amp_mode: str = None,
      scaler: Union[bool, "torch.cuda.amp.GradScaler"] = False,
      with_model_transform: bool = False,
      with_model_fn: bool = False,
  ):
      trainer, model = _default_create_supervised_trainer(
          gradient_accumulation_steps=gradient_accumulation_steps,
          model_device=model_device,
          trainer_device=trainer_device,
          trace=trace,
          amp_mode=amp_mode,
          scaler=scaler,
          with_model_transform=with_model_transform,
          with_model_fn=with_model_fn,
      )
  
      x = torch.tensor([[0.01], [0.02], [0.03], [0.04], [0.05]])
      y = torch.tensor([[0.015], [0.025], [0.035], [0.045], [0.055]])
      if with_model_fn:
          y += 0.01
      data = [(_x, _y) for _x, _y in zip(x, y)]
  
      theta = [0.0]
      accumulation = [0.0]
      loss = [0.0]
  
      @trainer.on(Events.ITERATION_COMPLETED)
      def _():
          assert model.fc.weight.grad != 0
          _x, _y = trainer.state.batch
          _x, _y = _x.to(model_device), _y.to(model_device)
          bias = 0.01 if with_model_fn else 0.0
          accumulation[0] += (
              0.2
              * _x.item()
              * (theta[0] * _x.item() - (_y.item() - bias))
          )
          # value of loss should not be accumulated
          _y_pred = (
              model(_x, torch.tensor([bias], device=model_device))
              if with_model_fn
              else model(_x)
          )
          if with_model_transform:
              _y_pred = _y_pred[0]
  
          loss[0] = mse_loss(_y_pred, _y).item()
  
      @trainer.on(
          Events.ITERATION_COMPLETED(every=gradient_accumulation_steps)
      )
      def _():
          theta[0] -= accumulation[0] / gradient_accumulation_steps
          assert (
              pytest.approx(
                  model.fc.weight.data[0, 0].item(), abs=1.0e-5
              )
              == theta[0]
          )
          assert (
              pytest.approx(trainer.state.output[-1], abs=1e-5)
              == loss[0]
          )
          accumulation[0] = loss[0] = 0.0
  
      if model_device == trainer_device or (
          (model_device == "cpu") ^ (trainer_device == "cpu")
      ):
          state = trainer.run(data)
  
          if amp_mode == "amp":
              assert state.output[0].dtype is torch.half
              if scaler and isinstance(scaler, bool):
                  assert hasattr(state, "scaler")
              else:
                  assert not hasattr(state, "scaler")
  
      else:
          if Version(torch.__version__) >= Version("1.7.0"):
              # This is broken in 1.6.0 but will be probably fixed with 1.7.0
              with pytest.raises(
                  RuntimeError,
                  match=r"Expected all tensors to be on the same device",
              ):
                  trainer.run(data)
  
imports: import os
  from importlib.util import find_spec
  from typing import Optional, Union
  from unittest import mock
  from unittest.mock import MagicMock, patch
  import pytest
  import torch
  from packaging.version import Version
  from pytest import approx
  from torch.nn.functional import mse_loss
  from torch.optim import SGD
  import ignite.distributed
  from ignite.distributed.comp_models.base import _torch_version_le_112
  from ignite.engine import _check_arg, create_supervised_evaluator, create_supervised_trainer, Engine, Events, supervised_evaluation_step, supervised_evaluation_step_amp, supervised_training_step_tpu
  from ignite.metrics import MeanSquaredError
label_desc: Use image node_id 2 for calling a global function with example usage: _test_create_supervised_trainer(gradient_accumulation_steps, model_device, trainer_device, trace, amp_mode, scaler, with_model_transform, with_model_fn) without return types