code: def _test_create_supervised_tbptt_trainer(device):
      # Defining dummy recurrent model with zero weights
      model = nn.RNN(1, 1, bias=False)
      model.to(device)  # Move model before creating optimizer
      for p in model.parameters():
          p.data.zero_()
  
      # Set some mock on forward to monitor
      forward_mock = mock.MagicMock()
      forward_mock.return_value = None
      model.register_forward_hook(forward_mock)
  
      # Defning optimizer and trainer
      optimizer = optim.SGD(model.parameters(), 1)
      trainer = create_supervised_tbptt_trainer(
          model, optimizer, F.mse_loss, tbtt_step=2, device=device
      )
  
      # Fake data
      X = torch.ones(6, 2, 1)
      y = torch.ones(6, 2, 1)
      data = [(X, y)]
  
      # Running trainer
      trainer.run(data)
  
      # If tbptt is not use (one gradient update), the hidden to hidden weight
      # should stay zero
      assert not model.weight_hh_l0.item() == pytest.approx(0)
  
      # Cheking forward calls
      assert forward_mock.call_count == 3
      for i in range(3):
          inputs = forward_mock.call_args_list[i][0][1]
          if i == 0:
              assert len(inputs) == 1
          else:
              assert len(inputs) == 2
              x, h = inputs
              assert h.is_leaf
  
file_path: ignite/tests/ignite/contrib/engines/test_tbptt.py
imports: import unittest.mock
  import pytest
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from ignite.contrib.engines import create_supervised_tbptt_trainer, Tbptt_Events
  from ignite.contrib.engines.tbptt import _detach_hidden
label_desc: Use image node_id 5 for calling a global function with example usage: _test_create_supervised_tbptt_trainer(device) without return types