code: def peak_cpu_memory() -> Dict[int, int]:
      """
      Get peak memory usage for each worker, as measured by max-resident-set size:
  
      https://unix.stackexchange.com/questions/30940/getrusage-system-call-what-is-maximum-resident-set-size
  
      Only works on OSX and Linux, otherwise the result will be 0.0 for every worker.
      """
      if resource is None or sys.platform not in ("linux", "darwin"):
          peak_bytes = 0
      else:
          peak = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
          if sys.platform == "darwin":
              # On OSX the result is in bytes.
              peak_bytes = peak
          else:
              # On Linux the result is in kilobytes.
              peak_bytes = peak * 1_024
  
      if is_distributed():
          global_rank = dist.get_rank()
          world_size = dist.get_world_size()
  
          peak_bytes_tensor = torch.tensor([global_rank, peak_bytes])
          # All of these tensors will be gathered into this list.
          gather_results = [
              torch.tensor([0, 0]) for _ in range(world_size)
          ]
  
          # If the backend is 'nccl', this means we're training on GPUs, so these tensors
          # need to be on GPU.
          if dist.get_backend() == "nccl":
              peak_bytes_tensor = peak_bytes_tensor.cuda()
              gather_results = [x.cuda() for x in gather_results]
  
          dist.all_gather(gather_results, peak_bytes_tensor)
  
          results_dict: Dict[int, int] = {}
          for peak_bytes_tensor in gather_results:
              results_dict[int(peak_bytes_tensor[0])] = int(
                  peak_bytes_tensor[1]
              )
  
          return results_dict
      else:
          return {0: peak_bytes}
  
imports: import hashlib
  import io
  from datetime import timedelta
  import importlib
  import json
  import logging
  import os
  import pkgutil
  import random
  import sys
  import signal
  from contextlib import contextmanager
  from itertools import islice, zip_longest
  from pathlib import Path
  from typing import Any, Callable, Dict, Generator, Iterable, Iterator, List, Optional, Tuple, TypeVar, Union, Sequence, Set
  import dill
  import numpy
  import spacy
  import torch
  import torch.distributed
  from spacy.cli.download import download
  from spacy.language import Language
  import base58
  from allennlp.common.checks import log_pytorch_version_info
  from allennlp.common.params import Params
label_desc: Use image node_id 12 for calling a global function with example usage: peak_cpu_memory() and returns: results_dict, dict