code: def test_quantized_comm_codec(
      self,
      comm_precisions_loss_scale: Tuple[CommType, Optional[float]],
      row_size: int,
      col_size: int,
      rand_seed: int,
      row_dim: int,
  ) -> None:
      (comm_precision, loss_scale) = comm_precisions_loss_scale
  
      if comm_precision == CommType.FP8:
          if row_dim > 0:
              assume((col_size * row_size) % row_dim == 0)
          assume(col_size % 4 == 0)
  
      torch.manual_seed(rand_seed)
      shape = (row_size, col_size)
      input_tensor = torch.rand(shape, requires_grad=True)
      cur_row_dim = None
  
      if (
          comm_precision == CommType.FP8
          and torch.cuda.device_count() != 0
          and row_dim > 0
      ):
          cur_row_dim = row_dim
          input_tensor = input_tensor.view(-1).cuda()
  
      quant_codec = get_qcomm_codecs(
          QCommsConfig(
              forward_precision=comm_precision,
              fp8_quantize_dim=cur_row_dim,
          )
      )
      ctx = quant_codec.forward.create_context()
      if comm_precision == CommType.INT8:
          assume(row_size * col_size % ctx.row_dim == 0)
          input_tensor = input_tensor.view(-1)
  
      quant_tensor = quant_codec.forward.encode(input_tensor, ctx)
      output_tensor = quant_codec.forward.decode(quant_tensor, ctx)
  
      rtol = 0.005
      atol = 0.005
      if comm_precision == CommType.FP8:
          rtol = 0.05
          atol = 0.05
  
      torch.testing.assert_close(
          input_tensor.detach().cpu(),
          output_tensor.detach().cpu(),
          rtol=rtol,
          atol=atol,
      )
  
file_path: torchrec/torchrec/distributed/tests/test_fbgemm_qcomm_codec.py
imports: import unittest
  from typing import Optional, Tuple
  import hypothesis.strategies
  import torch
  from hypothesis import assume, given, settings
  from torchrec.distributed.fbgemm_qcomm_codec import CommType, get_qcomm_codecs, QCommsConfig
label_desc: Use image node_id 1 for calling the QuantizationCommCodecTest obj's underlying member method code with example usage: obj.test_quantized_comm_codec(comm_precisions_loss_scale, row_size, col_size, rand_seed, row_dim) without return types