class_docstr: Testing hierarchical sharding types.
  
  NOTE:
      Requires at least 4 GPUs to test.
class_docstr_tok: ["Testing","hierarchical","sharding","types",".","NOTE",":","Requires","at","least","4","GPUs","to","test","."]
code: def test_sharding_nccl_twrw(
      self,
      sharder_type: str,
      sharding_type: str,
      kernel_type: str,
      local_size: int,
      qcomms_config: Optional[QCommsConfig],
      apply_optimizer_in_backward_config: Optional[
          Dict[str, Tuple[Type[torch.optim.Optimizer], Dict[str, Any]]]
      ],
      variable_batch_size: bool,
  ) -> None:
      # Dense kernels do not have overlapped optimizer behavior yet
      assume(
          apply_optimizer_in_backward_config is None
          or kernel_type != EmbeddingComputeKernel.DENSE.value
      )
      assume(
          sharder_type == SharderType.EMBEDDING_BAG_COLLECTION.value
          or not variable_batch_size
      )
      # Make sure detail debug will work with non-even collective
      os.environ["TORCH_DISTRIBUTED_DEBUG"] = "DETAIL"
  
      self._test_sharding(
          # pyre-ignore[6]
          sharders=[
              create_test_sharder(
                  sharder_type,
                  sharding_type,
                  kernel_type,
                  qcomms_config=qcomms_config,
                  device=torch.device("cuda"),
              ),
          ],
          backend="nccl",
          world_size=4,
          local_size=local_size,
          qcomms_config=qcomms_config,
          apply_optimizer_in_backward_config=apply_optimizer_in_backward_config,
          variable_batch_size=variable_batch_size,
      )
  
imports: import os
  import unittest
  from typing import Any, Dict, Optional, Tuple, Type
  import torch
  from fbgemm_gpu.split_embedding_configs import EmbOptimType
  from hypothesis import assume, given, settings, strategies, Verbosity
  from torchrec.distributed.embedding_types import EmbeddingComputeKernel
  from torchrec.distributed.fbgemm_qcomm_codec import CommType, QCommsConfig
  from torchrec.distributed.planner import ParameterConstraints
  from torchrec.distributed.test_utils.test_model import TestSparseNN, TestTowerCollectionSparseNN, TestTowerSparseNN
  from torchrec.distributed.test_utils.test_model_parallel import ModelParallelTestShared
  from torchrec.distributed.test_utils.test_sharding import create_test_sharder, SharderType, sharding_single_rank_test
  from torchrec.distributed.types import ShardingType
  from torchrec.test_utils import skip_if_asan_class
label_desc: Use image node_id 1 for calling the ModelParallelHierarchicalTest obj's underlying member method code with example usage: obj.test_sharding_nccl_twrw(sharder_type, sharding_type, kernel_type, local_size, qcomms_config, apply_optimizer_in_backward_config, variable_batch_size) without return types