code: def test_strict_resume_from_iter():
      def _test(epoch_length=None):
          max_epochs = 5
          num_iters = 21
          torch.manual_seed(0)
          data = torch.randint(0, 1000, size=(num_iters,))
          if epoch_length is None:
              epoch_length = num_iters
  
          for resume_iteration in range(
              2,
              min(num_iters * max_epochs, epoch_length * max_epochs),
              4,
          ):
              batch_checker = BatchChecker(
                  data, init_counter=resume_iteration
              )
  
              def update_fn(_, batch):
                  assert batch_checker.check(
                      batch
                  ), f"{resume_iteration} | {batch_checker.counter}: {batch_checker.true_batch} vs {batch}"
  
              engine = DeterministicEngine(update_fn)
  
              @engine.on(Events.EPOCH_COMPLETED)
              def check_iteration(_):
                  assert engine.state.iteration == batch_checker.counter
  
              resume_state_dict = dict(
                  iteration=resume_iteration,
                  max_epochs=max_epochs,
                  epoch_length=epoch_length,
                  rng_states=None,
              )
              engine.load_state_dict(resume_state_dict)
              engine.run(data)
              assert engine.state.epoch == max_epochs
              assert engine.state.iteration == epoch_length * max_epochs
  
      _test()
      _test(60)
      _test(15)
  
imports: import os
  import random
  import sys
  from collections.abc import Mapping
  from unittest.mock import patch
  import numpy
  import pytest
  import torch
  import torch.nn
  from torch.optim import SGD
  from torch.utils.data import BatchSampler, DataLoader, RandomSampler
  import ignite.distributed
  from ignite.engine import Events
  from ignite.engine.deterministic import _set_rng_states, DeterministicEngine, keep_random_state, ReproducibleBatchSampler, update_dataloader
  from ignite.utils import manual_seed
  from tests.ignite.engine import BatchChecker, setup_sampler
label_desc: Use image node_id 8 for calling a global function with example usage: test_strict_resume_from_iter() without return types