code: def model_quantize(
      self, model, quantize_policy, quantize_bits, groups
  ):
      all_scales = []
  
      def quantize_fn(layer, policy_cls):
          policy = policy_cls(layer)
  
          _, qkvw, _, dense_w, _, _ = policy.attention()
          _, _h4h_w, _, _4hh_w, _ = policy.mlp()
          keys = [qkvw, dense_w, _h4h_w, _4hh_w]
          layer_scales = []
  
          for key in range(len(keys)):
              if self.mlp_extra_grouping and self.is_mlp(keys[key]):
                  data_quantized, data_scale = self.quantize_data(
                      keys[key], quantize_bits, groups * 2
                  )
              elif policy_cls is HFBertLayerPolicy and self.is_qkv(
                  keys[key]
              ):
                  data_quantized, data_scale = self.quantize_data(
                      keys[key], quantize_bits, groups * 3
                  )
              else:
                  data_quantized, data_scale = self.quantize_data(
                      keys[key], quantize_bits, groups
                  )
              keys[key].copy_(data_quantized)
              layer_scales.append(
                  (
                      1
                      / data_scale.to(torch.cuda.current_device())
                      .view(-1)
                      .unsqueeze(0)
                  )
              )
          all_scales.append(self.merge_layer_scales(layer_scales))
          return layer
  
      def _quantize_module(model, policies):
          for name, child in model.named_children():
              if child.__class__ in policies:
                  quantize_fn, replace_policy = policies[
                      child.__class__
                  ]
                  setattr(
                      model, name, quantize_fn(child, replace_policy)
                  )
              else:
                  _quantize_module(child, policies)
  
          return model
  
      policy = {}
      if quantize_policy is not None:
          for layer_name, replace_policy in quantize_policy.items():
              policy.update({layer_name: (quantize_fn, replace_policy)})
      else:
          for plcy in replace_policies:
              policy.update(
                  {plcy._orig_layer_class: (quantize_fn, plcy)}
              )
  
      quantized_module = _quantize_module(model, policy)
  
      return quantized_module, torch.cat(all_scales)
  
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 10 for calling the WeightQuantization obj's underlying member method code with example usage: obj.model_quantize(model, quantize_policy, quantize_bits, groups) and returns: quantized_module,  torch, layer, model