code: def get_qcomm_codecs_registry(
      qcomms_config: QCommsConfig,
      comm_ops: Optional[List[CommOp]] = None,
      device: Optional[torch.device] = None,
  ) -> Optional[Dict[str, QuantizedCommCodecs]]:
      """
       This method constructs QuantizedCommCodecs from a given QCommConfig. It assumes
       that you want to use the same QComm configs for all comm-types passed in.
  
       Some quantization schemes are not supported for some backends (such as BF16 for gloo/cpu, and FP8 for reduce scatter on nccl).
       This scheme will provide some fallback logic and print a warning.
  
      Args:
          qcomms_config (QCommsConfig): QCommsConfig to construct FBGEMMQuantizedCommCodecs from
          comm_ops (Optional[List[CommOp]]): List of CommOps to enter into the registry
          device (torch.device): Backend comms will run on.
  
      Example::
          qcomm_codces_registry = get_qcomm_codecs_registry(
              qcomms_config=QCommsConfig(forward_precision=FP16, backward_precision=BF16),
              device=torch.device("cuda"))
      """
  
      if (
          qcomms_config.forward_precision == CommType.FP32
          and qcomms_config.backward_precision == CommType.FP32
      ):
          return None
  
      if device is None:
          device = torch.device("cuda")
  
      qcomm_codecs_registry = {}
      if comm_ops is None:
          comm_ops = [
              CommOp.POOLED_EMBEDDINGS_ALL_TO_ALL,
              CommOp.POOLED_EMBEDDINGS_REDUCE_SCATTER,
              CommOp.SEQUENCE_EMBEDDINGS_ALL_TO_ALL,
          ]
      for comm_op in comm_ops:
          qcomm_config_copy = copy.deepcopy(qcomms_config)
          # TODO: On H100, FP8 types might be natively supported, in which case we should check for that arch type and not fallback.
          if comm_op == CommOp.POOLED_EMBEDDINGS_REDUCE_SCATTER:
              if qcomm_config_copy.forward_precision == CommType.FP8:
                  logger.warning(
                      "FP8 is not supported for reduce scatter's forward - falling back to FP16"
                  )
                  qcomm_config_copy.forward_precision = CommType.FP16
              if qcomm_config_copy.backward_precision == CommType.FP8:
                  logger.warning(
                      "FP8 is not supported for reduce scatter's backward - falling back to BF16"
                  )
                  qcomm_config_copy.backward_precision = CommType.BF16
  
          if device.type == "cpu":
              if qcomm_config_copy.forward_precision == CommType.BF16:
                  logger.warning(
                      "BF16 is not for forward_precision is not supported on GLOO - falling back to FP16."
                  )
                  qcomm_config_copy.forward_precision = CommType.FP16
  
              if qcomm_config_copy.backward_precision == CommType.BF16:
                  logger.warning(
                      "BF16 is not for backward_precision is not supported on GLOO - falling back to FP16."
                  )
                  qcomm_config_copy.backward_precision = CommType.FP16
  
          qcomm_codecs_registry[comm_op.name] = get_qcomm_codecs(
              qcomm_config_copy
          )
  
      return qcomm_codecs_registry
  
file_path: torchrec/torchrec/distributed/fbgemm_qcomm_codec.py
imports: import copy
  import logging
  from dataclasses import dataclass
  from enum import Enum, unique
  from typing import cast, Dict, List, Optional
  import torch
  from fbgemm_gpu.quantize_comm import QuantizationContext, QuantizedCommCodec
  from fbgemm_gpu.split_embedding_configs import SparseType
  from torchrec.distributed.types import CommOp, QuantizedCommCodec, QuantizedCommCodecs
label_desc: Use image node_id 3 for calling a global function with example usage: get_qcomm_codecs_registry(qcomms_config, comm_ops, device) and returns: qcomm_codecs_registry, None