code: def _get_cached_results(
      world_size,
      with_model2,
      with_sync_bn,
      with_fsdp,
      with_checkpoint,
      mixed_precision,
      flatten,
      wrap_bn,
      fp32_reduce_scatter,
      bucket_cap_mb,
  ):
      """Cache the training to save time. For DDP, flatten, wrap_bn etc. doesn't matter, so
      the results can be cached.
      """
      if not with_fsdp:
          flatten = None
          wrap_bn = None
          fp32_reduce_scatter = None
  
      key = (
          world_size,
          with_model2,
          with_sync_bn,
          with_fsdp,
          with_checkpoint,
          mixed_precision,
          flatten,
          wrap_bn,
          fp32_reduce_scatter,
          bucket_cap_mb,
      )
      global _result_cache
      if key not in _result_cache:
          # Get 4 files: 2 for dist_init and 2 for each rank to save the losses.
          with temp_files_ctx(num=2 + world_size) as temp_files:
              mp.spawn(
                  _distributed_worker,
                  (
                      world_size,
                      with_model2,
                      with_sync_bn,
                      with_fsdp,
                      with_checkpoint,
                      temp_files,
                      mixed_precision,
                      flatten,
                      wrap_bn,
                      fp32_reduce_scatter,
                      bucket_cap_mb,
                  ),
                  nprocs=world_size,
              )
              final_losses = {}
              for rank in range(world_size):
                  with open(temp_files[2 + rank], "rb") as f:
                      for iter_key, loss in pickle.load(f).items():
                          final_losses[f"rank_{rank}_{iter_key}"] = loss
              _result_cache[key] = final_losses
      return _result_cache[key]
  
imports: import contextlib
  import pickle
  import pytest
  import torch
  import torch.distributed
  import torch.multiprocessing
  import torch.nn
  from torch.nn.parallel import DistributedDataParallel
  import torch.optim
  from fairscale.fair_dev.testing.testing import dist_init, skip_if_single_gpu, teardown, temp_files_ctx
  from fairscale.internal import torch_version
  from fairscale.nn import checkpoint_wrapper
  from fairscale.nn.data_parallel import FullyShardedDataParallel
  from fairscale.nn.data_parallel import auto_wrap_bn
  from fairscale.nn.wrap import enable_wrap, wrap
label_desc: Use image node_id 3 for calling a global function with example usage: _get_cached_results(world_size, with_model2, with_sync_bn, with_fsdp, with_checkpoint, mixed_precision, flatten, wrap_bn, fp32_reduce_scatter, bucket_cap_mb) and returns: _result_cache