code: def quantize_data(self, data, quantize_bits, groups, key=None):
      data_groups = torch.split(
          data.float().view(-1), data.numel() // groups
      )
      max_d = [max(g.max(), g.min().abs()) for g in data_groups]
      data_scale = [
          float(1 << quantize_bits) / (2 * mx + 1e-5) for mx in max_d
      ]
      data_int = [(g * s) for g, s in zip(data_groups, data_scale)]
      data_int = [
          di.round().clamp(
              -(1 << (quantize_bits - 1)),
              (((1 << (quantize_bits - 1)) - 1)),
          )
          for di in data_int
      ]
      data_int = torch.cat(data_int).reshape(data.shape)
      data_int = data_int.to(torch.int8)
      data_scale = torch.cat(
          [s.unsqueeze(0).unsqueeze(0) for s in data_scale]
      )
      return data_int, data_scale
  
file_path: H2O/h2o_flexgen/benchmark/third_party/DeepSpeed/deepspeed/runtime/weight_quantizer.py
imports: import torch
  from ..module_inject.replace_policy import HFBertLayerPolicy, replace_policies
label_desc: Use image node_id 2 for calling the WeightQuantization obj's underlying member method code with example usage: obj.quantize_data(data, quantize_bits, groups, key) and returns: data_int,  data_scale