docstr: Check that overlapping DDP with ZeRO using the given method determined
  by ``hook_constructor`` and ``shard_buckets`` and using the given ZeRO
  and DDP arguments achieves parity with DDP using a local optimizer.
docstr_tok: ["Check","that","overlapping","DDP","with","ZeRO","using","the","given","method","determined","by","``","hook_constructor","``","and","``","shard_buckets","``","and","using","the","given","ZeRO","and","DDP","arguments","achieves","parity","with","DDP","using","a","local","optimizer","."]
code: def test_ddp_zero_overlap(
      self,
      use_gpu: bool,
      use_interleaved_hook: bool,
      gradient_as_bucket_view: bool,
      static_graph: bool,
      shard_buckets: bool,
  ):
      """
      Check that overlapping DDP with ZeRO using the given method determined
      by ``hook_constructor`` and ``shard_buckets`` and using the given ZeRO
      and DDP arguments achieves parity with DDP using a local optimizer.
      """
      device = (
          torch.device(self.rank) if use_gpu else torch.device("cpu")
      )
      backend = _get_backend_for_tests()
      self.dist_init(self.rank, self.world_size, backend)
      hook_constructor = (
          hook_with_zero_step
          if not use_interleaved_hook
          else hook_with_zero_step_interleaved
      )
  
      self._test_ddp_zero_overlap(
          device,
          hook_constructor,
          gradient_as_bucket_view,
          static_graph,
          shard_buckets=shard_buckets,
      )
  
imports: import copy
  import os
  import sys
  import unittest
  from contextlib import nullcontext
  from typing import Any, cast, List
  import numpy
  import torch
  import torch.distributed
  from torch.distributed.algorithms.ddp_comm_hooks.ddp_zero_hook import hook_with_zero_step, hook_with_zero_step_interleaved
  from torch.distributed.algorithms.ddp_comm_hooks.default_hooks import allreduce_hook
  from torch.distributed.algorithms.join import Join, Joinable, JoinHook
  from torch.distributed.optim import ZeroRedundancyOptimizer
  from torch.distributed.optim.zero_redundancy_optimizer import _broadcast_object
  from torch.nn.parallel import DistributedDataParallel
  from torch.optim import AdamW, SGD
  from torch.testing._internal import common_distributed
  from torch.testing._internal.common_utils import instantiate_parametrized_tests, IS_WINDOWS, parametrize, run_tests, TEST_WITH_ASAN, TEST_WITH_DEV_DBG_ASAN
label_desc: Use image node_id 20 for calling the TestZeroRedundancyOptimizerDistributed obj's underlying member method code with example usage: obj.test_ddp_zero_overlap(use_gpu, use_interleaved_hook, gradient_as_bucket_view, static_graph, shard_buckets) without return types