code: def test_float_quantize(
      num_elems, num_groups, is_symmetric_quant, q_bits, directed_case
  ):
      if directed_case == "all_zeros":
          activations_ds = torch.zeros(
              (num_groups, num_elems),
              dtype=torch.float16,
              device="cuda",
          )
      else:
          activations_ds = torch.randn(
              (num_groups, num_elems),
              dtype=torch.float16,
              device="cuda",
          )
      activations_ref = activations_ds.clone().detach()
  
      ref_out_tensor, ref_params = run_float_quantize(
          q_bits, is_symmetric_quant, activations_ref, num_groups
      )
  
      ds_out_tensor, ds_out_params = run_quantize_ds(
          activations_ds, num_groups, q_bits, is_symmetric_quant
      )
  
      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,
          )
      )
      if is_symmetric_quant:
          assert torch.allclose(
              ds_out_params.flatten(), ref_params[:, 0].flatten()
          )
      else:
          assert torch.allclose(
              ds_out_params[:, 0].flatten(), ref_params[:, 0].flatten()
          )
          assert torch.allclose(
              ds_out_params[:, 1].flatten(),
              ref_params[:, 1].flatten(),
              atol=5e-5,
              rtol=5e-5,
          )
  
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 6 for calling a global function with example usage: test_float_quantize(num_elems, num_groups, is_symmetric_quant, q_bits, directed_case) without return types