code: def calculate_shard_sizes_and_offsets(
      tensor: torch.Tensor,
      world_size: int,
      local_world_size: int,
      sharding_type: str,
      col_wise_shard_dim: Optional[int] = None,
  ) -> Tuple[List[List[int]], List[List[int]]]:
      """
      Calculates sizes and offsets for tensor sharded according to provided sharding type.
  
      Args:
          tensor (torch.Tensor): tensor to be sharded.
          world_size (int): total number of devices in topology.
          local_world_size (int): total number of devices in host group topology.
          sharding_type (str): provided ShardingType value.
          col_wise_shard_dim (Optional[int]): dimension for column wise sharding split.
  
      Returns:
          Tuple[List[List[int]], List[List[int]]]: shard sizes, represented as a list of the dimensions of the sharded tensor on each device, and shard offsets, represented as a list of coordinates of placement on each device.
  
      Raises:
          ValueError: If `sharding_type` is not a valid ShardingType.
      """
  
      (rows, columns) = tensor.shape
  
      if sharding_type == ShardingType.DATA_PARALLEL.value:
          return [[rows, columns]] * world_size, [[0, 0]] * world_size
      elif sharding_type == ShardingType.TABLE_WISE.value:
          return [[rows, columns]], [[0, 0]]
      elif sharding_type == ShardingType.ROW_WISE.value:
          return _calculate_rw_shard_sizes_and_offsets(
              rows, world_size, columns
          )
      elif sharding_type == ShardingType.TABLE_ROW_WISE.value:
          return _calculate_rw_shard_sizes_and_offsets(
              rows, local_world_size, columns
          )
      elif (
          sharding_type == ShardingType.COLUMN_WISE.value
          or sharding_type == ShardingType.TABLE_COLUMN_WISE.value
      ):
          return _calculate_cw_shard_sizes_and_offsets(
              columns, rows, col_wise_shard_dim
          )
  
      raise ValueError(
          f"Unrecognized or unsupported sharding type provided: {sharding_type}"
      )
  
imports: import math
  import warnings
  from typing import Callable, cast, Dict, List, Optional, Tuple, Type
  import torch
  from torch import distributed, nn
  from torchrec.distributed.comm import get_local_size
  from torchrec.distributed.embedding import EmbeddingCollectionSharder
  from torchrec.distributed.embedding_types import EmbeddingComputeKernel
  from torchrec.distributed.embeddingbag import EmbeddingBagCollectionSharder
  from torchrec.distributed.fp_embeddingbag import FeatureProcessedEmbeddingBagCollectionSharder
  from torchrec.distributed.fused_embeddingbag import FusedEmbeddingBagCollectionSharder
  from torchrec.distributed.mc_embedding import ManagedCollisionEmbeddingCollectionSharder
  from torchrec.distributed.mc_embeddingbag import ManagedCollisionEmbeddingBagCollectionSharder
  from torchrec.distributed.planner.constants import MIN_CW_DIM
  from torchrec.distributed.quant_embedding import QuantEmbeddingCollectionSharder
  from torchrec.distributed.quant_embeddingbag import QuantEmbeddingBagCollectionSharder
  from torchrec.distributed.types import EmbeddingModuleShardingPlan, EnumerableShardingSpec, ModuleSharder, ParameterSharding, ShardingType, ShardMetadata
  from torchrec.distributed.utils import none_throws
label_desc: Use image node_id 4 for calling a global function with example usage: calculate_shard_sizes_and_offsets(tensor, world_size, local_world_size, sharding_type, col_wise_shard_dim) and returns: unknown,  unknown, list,  list, _calculate_rw_shard_sizes_and_offsets, _calculate_rw_shard_sizes_and_offsets, _calculate_cw_shard_sizes_and_offsets