code: def test_combined_loader_modes_for_namedtuple():
      """Test `CombinedLoaderIterator` given a namedtuple of iterables."""
  
      class IterablesNamedTuple(NamedTuple):
          a: Any
          b: Any
  
      iterables = IterablesNamedTuple(
          a=torch.utils.data.DataLoader(range(10), batch_size=4),
          b=torch.utils.data.DataLoader(range(20), batch_size=5),
      )
      lengths = [len(v) for v in iterables]
  
      # min_size with namedtuple
      min_len = min(lengths)
      combined_loader = CombinedLoader(iterables, "min_size")
      iter(combined_loader)
      assert len(combined_loader) == min_len
      for item, idx, _ in combined_loader:
          assert isinstance(combined_loader._iterator, _MinSize)
          assert isinstance(item, IterablesNamedTuple)
      assert idx == min_len - 1
      assert idx == len(combined_loader) - 1
  
      # max_size_cycle with namedtuple
      max_len = max(lengths)
      combined_loader = CombinedLoader(iterables, "max_size_cycle")
      iter(combined_loader)
      assert len(combined_loader) == max_len
      for item, idx, _ in combined_loader:
          assert isinstance(combined_loader._iterator, _MaxSizeCycle)
          assert isinstance(item, IterablesNamedTuple)
      assert idx == max_len - 1
      assert idx == len(combined_loader) - 1
  
      # max_size with namedtuple
      combined_loader = CombinedLoader(iterables, "max_size")
      iter(combined_loader)
      assert len(combined_loader) == max_len
      for item, idx, _ in combined_loader:
          assert isinstance(combined_loader._iterator, _MaxSize)
          assert isinstance(item, IterablesNamedTuple)
          are_nones = [x is None for x in item]
          should_be_nones = [idx >= length for length in lengths]
          assert are_nones == should_be_nones
      assert idx == max_len - 1
      assert idx == len(combined_loader) - 1
  
      # sequential with namedtuple
      sum_len = sum(lengths)
      combined_loader = CombinedLoader(iterables, "sequential")
      iter(combined_loader)
      assert combined_loader._iterator is not None
      assert len(combined_loader) == sum_len
      for total_idx, (item, batch_idx, dataloader_idx) in enumerate(
          combined_loader
      ):
          assert isinstance(combined_loader._iterator, _Sequential)
          assert isinstance(batch_idx, int)
          assert isinstance(item, Tensor)
      assert idx == lengths[-1] - 1
      assert total_idx == sum_len - 1
      assert total_idx == len(combined_loader) - 1
      assert dataloader_idx == len(iterables) - 1
  
imports: import math
  import pickle
  from typing import Any, NamedTuple, Sequence, get_args
  import pytest
  import torch
  from lightning.pytorch import Trainer
  from lightning.pytorch.demos.boring_classes import BoringModel, RandomDataset
  from lightning.pytorch.utilities.combined_loader import _LITERAL_SUPPORTED_MODES, _SUPPORTED_MODES, CombinedLoader, _MaxSize, _MaxSizeCycle, _MinSize, _Sequential
  from torch import Tensor
  from torch.utils._pytree import tree_flatten
  from torch.utils.data import DataLoader, TensorDataset
  from torch.utils.data.dataset import Dataset, IterableDataset
  from torch.utils.data.distributed import DistributedSampler
  from torch.utils.data.sampler import RandomSampler, SequentialSampler
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 6 for calling a global function with example usage: test_combined_loader_modes_for_namedtuple() without return types