code: def quantize_dequantize_ref(inputs, bit, num_groups=1):
      # quantize
      q_range = 2**bit
      input_flat = inputs.float().reshape(num_groups, -1).contiguous()
      input_flat = torch.nan_to_num(input_flat, nan=0.0)
      input_min = input_flat.amin(-1, keepdim=True)
      input_max = input_flat.amax(-1, keepdim=True)
  
      scale = q_range / (
          2 * torch.max(input_min.abs(), input_max.abs() + 1e-5)
      )
      input_flat = (
          (input_flat * scale)
          .round()
          .clamp(-q_range // 2, q_range // 2 - 1)
      )
      # dequantize
      dequant_flat = torch.t(input_flat.to(torch.int8)) / scale.view(
          -1
      ).to(torch.float16)
      return torch.t(dequant_flat).reshape(inputs.shape)
  
file_path: deepspeed/tests/unit/ops/quantizer/test_fake_quantization.py
imports: import torch
  import pytest
  import deepspeed
  from deepspeed.accelerator import get_accelerator
  from deepspeed.ops.op_builder import QuantizerBuilder
label_desc: Use image node_id 2 for calling a global function with example usage: quantize_dequantize_ref(inputs, bit, num_groups) and returns: torch