code: def split_module(
      module: nn.Sequential,
      balance: Iterable[int],
      devices: List[torch.device],
  ) -> Tuple[List[nn.Sequential], List[int], List[torch.device]]:
      """Splits a module into multiple partitions.
  
      Returns:
          A tuple of (partitions, balance, devices).
  
          Partitions are represented as a :class:`~torch.nn.ModuleList` whose
          item is a partition. All layers in a partition are placed in the
          same device.
  
      Raises:
          BalanceError:
              wrong balance
          IndexError:
              the number of devices is fewer than the number of partitions.
  
      """
      balance = list(balance)
  
      if len(module) != sum(balance):
          raise BalanceError(
              "module and sum of balance have different length "
              f"(module: {len(module)}, sum of balance: {sum(balance)})"
          )
  
      if any(x <= 0 for x in balance):
          raise BalanceError(
              f"all balance numbers must be positive integer (balance: {balance})"
          )
  
      if len(balance) > len(devices):
          raise IndexError(
              "too few devices to hold given partitions "
              f"(devices: {len(devices)}, partitions: {len(balance)})"
          )
  
      j = 0
      partitions = []
      layers: NamedModules = OrderedDict()
  
      for name, layer in module.named_children():
          layers[name] = layer
  
          if len(layers) == balance[j]:
              # Group buffered layers as a partition.
              partition = nn.Sequential(layers)
  
              device = devices[j]
              partition.to(device)
  
              partitions.append(partition)
  
              # Prepare for the next partition.
              layers.clear()
              j += 1
  
      partitions = cast(List[nn.Sequential], nn.ModuleList(partitions))
      del devices[j:]
  
      return partitions, balance, devices
  
imports: from collections import OrderedDict
  from typing import TYPE_CHECKING, Any, Iterable, List, Optional, Tuple, Union, cast
  import warnings
  import torch
  from torch import Tensor, nn
  import torch.autograd
  import torch.cuda
  from fairscale.internal import torch_version
  from .None import microbatch
  from .batchnorm import DeferredBatchNorm
  from .pipeline import Pipeline
  from .skip.layout import inspect_skip_layout
  from .skip.skippable import verify_skippables
  from .stream import AbstractStream, new_stream
label_desc: Use image node_id 4 for calling a global function with example usage: split_module(module, balance, devices) and returns: partitions,  balance,  devices