code: def run_max_memory_used_localsgd_slowmo_memory_efficient(
      rank, world_size, tempfile_1, tempfile_2
  ) -> None:
      int_devices = get_gpus_for_rank(world_size)[rank][:1]
      devices = [torch.device("cuda:" + str(i)) for i in int_devices]
  
      # Memory usage when running optimization locally on a single GPU
      max_memory_local = run_test_memory_usage_localsgd_with_slowmo(
          rank,
          world_size,
          tempfile_1,
          {"localsgd_frequency": 1},
          use_gossip_data_parallel=False,
      )
  
      # Memory usage when running optimization using LocalSGD-SlowMo
      max_memory_localsgd_slowmo = run_test_memory_usage_localsgd_with_slowmo(
          rank,
          world_size,
          tempfile_2,
          {
              "slowmo_base_algorithm": gossip.SlowMoBaseAlgorithm.LOCALSGD,
              "localsgd_frequency": 1,
              "nprocs_per_node": 1,
              "slowmo_momentum": 0.5,
              "slowmo_frequency": 1,
              "slowmo_memory_efficient": True,
          },
          use_gossip_data_parallel=True,
      )
  
      model_memory_usage = find_memory_used_by_model(
          LargeNet, devices[0]
      )
  
      extra_memory_used_by_localsgd_slowmo = (
          max_memory_localsgd_slowmo - max_memory_local
      )
  
      extra_memory_used_by_slowmo = model_memory_usage  # This is expected on 2 GPU experiments and confirmed in below test
      extra_memory_used_by_localsgd = (
          extra_memory_used_by_localsgd_slowmo
          - extra_memory_used_by_slowmo
      )
  
      # Extra memory used by localsgd should be close to 0 for large models, because we discard the gradients before the localsgd step
      # which should allow us some extra memory for the averaging itself
      # TODO: Above is a hypothesis. Need to test it out for those later, once we know how much memory is typically used by activations
  
      # This try-catch block is to prevent a flaky test failure in which model_memory_usage is 0
      try:
          # Just setting a number below to match what I found here. This test needs to be revised
          assert (
              extra_memory_used_by_localsgd / model_memory_usage < 0.3
          )
      except ZeroDivisionError:
          if rank == 0:
              print("Skipping flaky test due to 0 memory error")
  
imports: import copy
  import os
  import tempfile
  from typing import Any, Dict, List, Tuple, Type
  import unittest
  import pytest
  import torch
  from torch import nn
  import torch.distributed
  import torch.nn.functional
  import fairscale.experimental.nn.data_parallel.gossip
  from fairscale.fair_dev.testing.testing import skip_if_single_gpu, spawn_for_all_world_sizes
label_desc: Use image node_id 11 for calling a global function with example usage: run_max_memory_used_localsgd_slowmo_memory_efficient(rank, world_size, tempfile_1, tempfile_2) without return types