code: def test_integer_quantize(num_elems, num_groups, q_bits):
      activations_ds = (
          torch.ones(
              (num_groups, num_elems),
              dtype=torch.float16,
              device="cuda",
          )
          * 0.35
      )
      activations_ref = activations_ds.clone().detach()
  
      ref_out_tensor, ref_params = run_integer_quantize(
          q_bits, activations_ref, num_groups
      )
  
      ds_out_tensor, ds_out_params = run_integer_quantize_ds(
          activations_ds, num_groups, q_bits
      )
  
      if q_bits == 4:
          ds_out_tensor = int4x2to2xint4(ds_out_tensor)
  
      # Allow a max difference of 1 to account for differences in rounding in pytorch implementation
      assert torch.all(
          torch.lt(
              torch.abs(
                  ds_out_tensor.flatten() - ref_out_tensor.flatten()
              ),
              2,
          )
      )
      assert torch.allclose(
          ds_out_params.flatten(), ref_params.flatten()
      )
  
file_path: H2O/h2o_flexgen/benchmark/third_party/DeepSpeed/tests/unit/ops/quantizer/test_quantize.py
imports: import pytest
  import torch
  from deepspeed.ops import op_builder
label_desc: Use image node_id 9 for calling a global function with example usage: test_integer_quantize(num_elems, num_groups, q_bits) without return types