class_docstr: Redistributes pooled embedding tensor in TWRW fashion by performing a reduce-scatter
  operation row wise on the host level and then an AlltoAll operation table wise on
  the global level.
  
  Args:
      cross_pg (dist.ProcessGroup): global level ProcessGroup for AlltoAll
          communication.
      intra_pg (dist.ProcessGroup): host level ProcessGroup for reduce-scatter
          communication.
      dim_sum_per_node (List[int]): number of features (sum of dimensions) of the
          embedding for each host.
      emb_dim_per_node_per_feature (List[List[int]]):
      device (Optional[torch.device]): device on which buffers will be allocated.
      qcomm_codecs_registry (Optional[Dict[str, QuantizedCommCodecs]]):
class_docstr_tok: ["Redistributes","pooled","embedding","tensor","in","TWRW","fashion","by","performing","a","reduce-scatter","operation","row","wise","on","the","host","level","and","then","an","AlltoAll","operation","table","wise","on","the","global","level",".","Args",":","cross_pg","(","dist.ProcessGroup",")",":","global","level","ProcessGroup","for","AlltoAll","communication",".","intra_pg","(","dist.ProcessGroup",")",":","host","level","ProcessGroup","for","reduce-scatter","communication",".","dim_sum_per_node","(","List","[","int","]",")",":","number","of","features","(","sum","of","dimensions",")","of","the","embedding","for","each","host",".","emb_dim_per_node_per_feature","(","List","[","List","[","int","]","]",")",":","device","(","Optional","[","torch.device","]",")",":","device","on","which","buffers","will","be","allocated",".","qcomm_codecs_registry","(","Optional","[","Dict","[","str",",","QuantizedCommCodecs","]","]",")",":"]
docstr: Reorders `batch_size_per_rank_per_feature_stagger` so it's aligned with
  reordered features after AlltoAll.
code: def _preprocess_batch_size_per_rank_per_feature(
      self,
      local_size: int,
      nodes: int,
      batch_size_per_rank_per_feature_stagger: List[List[int]],
  ) -> Tuple[List[List[List[int]]], List[List[int]]]:
      """
      Reorders `batch_size_per_rank_per_feature_stagger` so it's aligned with
      reordered features after AlltoAll.
      """
      if not batch_size_per_rank_per_feature_stagger:
          return [[]] * local_size, []
      batch_size_per_rank_per_feature_by_cross_group: List[
          List[List[int]]
      ] = []
      batch_size_per_feature_sum_by_cross_group: List[List[int]] = []
      for local_rank in range(local_size):
          batch_size_by_node_per_rank_per_feature: List[List[int]] = []
          batch_size_per_feature_sum = [0] * len(
              batch_size_per_rank_per_feature_stagger[0]
          )
          for node in range(nodes):
              batch_size = batch_size_per_rank_per_feature_stagger[
                  local_rank * nodes + node
              ]
              batch_size_by_node_per_rank_per_feature.append(batch_size)
              batch_size_per_feature_sum = [
                  sum(x)
                  for x in zip(batch_size_per_feature_sum, batch_size)
              ]
          batch_size_per_rank_per_feature_by_cross_group.append(
              batch_size_by_node_per_rank_per_feature
          )
          batch_size_per_feature_sum_by_cross_group.append(
              batch_size_per_feature_sum
          )
  
      return (
          batch_size_per_rank_per_feature_by_cross_group,
          batch_size_per_feature_sum_by_cross_group,
      )
  
imports: import itertools
  import math
  from typing import Any, cast, Dict, List, Optional, Tuple, TypeVar, Union
  import torch
  import torch.distributed
  from torchrec.distributed.comm import get_local_size, intra_and_cross_node_pg
  from torchrec.distributed.dist_data import KJTAllToAll, PooledEmbeddingsAllToAll, PooledEmbeddingsReduceScatter, VariableBatchPooledEmbeddingsAllToAll, VariableBatchPooledEmbeddingsReduceScatter
  from torchrec.distributed.embedding_lookup import GroupedPooledEmbeddingsLookup
  from torchrec.distributed.embedding_sharding import BaseEmbeddingDist, BaseEmbeddingLookup, BaseSparseFeaturesDist, bucketize_kjt_before_all2all, EmbeddingSharding, EmbeddingShardingContext, EmbeddingShardingInfo, group_tables
  from torchrec.distributed.embedding_types import BaseGroupedFeatureProcessor, EmbeddingComputeKernel, GroupedEmbeddingConfig, ShardedEmbeddingTable
  from torchrec.distributed.types import Awaitable, CommOp, QuantizedCommCodecs, ShardedTensorMetadata, ShardingEnv, ShardMetadata
  from torchrec.sparse.jagged_tensor import KeyedJaggedTensor
  from torchrec.streamable import Multistreamable
label_desc: Use image node_id 4 for calling the TwRwPooledEmbeddingDist obj's underlying member method code with example usage: obj._preprocess_batch_size_per_rank_per_feature(local_size, nodes, batch_size_per_rank_per_feature_stagger) and returns: batch_size_per_rank_per_feature_by_cross_group,  batch_size_per_feature_sum_by_cross_group, unknown,  list