code: def compress(tensor, config):
      """Simulate group-wise quantization."""
      if not config.enabled:
          return tensor
  
      group_size, num_bits, group_dim, symmetric = (
          config.group_size,
          config.num_bits,
          config.group_dim,
          config.symmetric,
      )
      assert num_bits <= 8
  
      original_shape = tensor.shape
      num_groups = (
          original_shape[group_dim] + group_size - 1
      ) // group_size
      new_shape = (
          original_shape[:group_dim]
          + (num_groups, group_size)
          + original_shape[group_dim + 1 :]
      )
  
      # Pad
      pad_len = (
          group_size - original_shape[group_dim] % group_size
      ) % group_size
      if pad_len != 0:
          pad_shape = (
              original_shape[:group_dim]
              + (pad_len,)
              + original_shape[group_dim + 1 :]
          )
          tensor = torch.cat(
              [
                  tensor,
                  torch.zeros(
                      pad_shape,
                      dtype=tensor.dtype,
                      device=tensor.device,
                  ),
              ],
              dim=group_dim,
          )
      data = tensor.view(new_shape)
  
      # Quantize
      if symmetric:
          B = 2 ** (num_bits - 1) - 1
          scale = (
              B
              / torch.max(data.abs(), dim=group_dim + 1, keepdim=True)[
                  0
              ]
          )
          data = data * scale
          data = data.clamp_(-B, B).round_().to(torch.int8)
          return data, scale, original_shape
      else:
          B = 2**num_bits - 1
          mn = torch.min(data, dim=group_dim + 1, keepdim=True)[0]
          mx = torch.max(data, dim=group_dim + 1, keepdim=True)[0]
  
          scale = B / (mx - mn)
          data = data - mn
          data.mul_(scale)
  
          data = data.clamp_(0, B).round_().to(torch.uint8)
          return data, mn, scale, original_shape
  
imports: import dataclasses
  import torch
  import numpy
  from flexgen.pytorch_backend import TorchTensor, TorchDevice, DeviceType, general_copy, fix_recursive_import
  from flexgen.utils import np_dtype_to_torch_dtype
label_desc: Use image node_id 5 for calling a global function with example usage: compress(tensor, config) and returns: tensor, data,  scale,  original_shape, data,  mn,  scale,  original_shape