class_docstr: Manage tensors stored in a compressed format.
class_docstr_tok: ["Manage","tensors","stored","in","a","compressed","format","."]
code: def decompress(self, tensor):
      data, scale, comp_config = tensor.data
      group_size, num_bits, group_dim, symmetric = (
          comp_config.group_size,
          comp_config.num_bits,
          comp_config.group_dim,
          comp_config.symmetric,
      )
  
      group_size_c = group_size // 2
      shape = data.shape
      num_groups = (shape[group_dim] + group_size_c - 1) // group_size_c
  
      # Pad
      new_shape = (
          shape[:group_dim]
          + (num_groups, group_size_c)
          + shape[group_dim + 1 :]
      )
      pad_len = (
          group_size_c - shape[group_dim] % group_size_c
      ) % group_size_c
      if pad_len != 0:
          pad_shape = (
              shape[:group_dim] + (pad_len,) + shape[group_dim + 1 :]
          )
          data = torch.cat(
              [
                  data,
                  torch.zeros(
                      pad_shape, dtype=data.dtype, device=data.device
                  ),
              ],
              dim=group_dim,
          )
      packed = data.data.view(new_shape)
  
      # Unpack
      if self.base_device.device_type == DeviceType.CPU:
          self.workspace_pt = (self.workspace_pt + 1) % len(
              self.data_decompress_workspace
          )
          data = self.data_decompress_workspace[self.workspace_pt][
              : shape[0]
          ]
      else:
          new_shape = (
              shape[:group_dim]
              + (
                  num_groups,
                  group_size,
              )
              + shape[group_dim + 1 :]
          )
          data = torch.empty(
              new_shape, dtype=torch.float16, device=packed.device
          )
      left_indices = tuple(
          slice(0, x) for x in data.shape[: group_dim + 1]
      ) + (
          slice(0, data.shape[group_dim + 1], 2),
      )
      right_indices = tuple(
          slice(0, x) for x in data.shape[: group_dim + 1]
      ) + (
          slice(1, data.shape[group_dim + 1], 2),
      )
      data[left_indices] = packed.bitwise_right_shift(4)
      data[right_indices] = packed.bitwise_and(0xF)
  
      # Dequantize
      scale, mn = scale.data.split(1, dim=group_dim + 1)
      data.div_(scale)
      data.add_(mn)
  
      # Reshape
      unpad_len = (
          group_size - tensor.shape[group_dim] % group_size
      ) % group_size
      if unpad_len != 0:
          flatten_shape = (
              shape[:group_dim]
              + (num_groups * group_size,)
              + shape[group_dim + 1 :]
          )
          indices = [slice(0, x) for x in flatten_shape]
          indices[group_dim] = slice(
              0, flatten_shape[group_dim] - unpad_len
          )
          data = data.view(flatten_shape)[indices].contiguous()
  
      return data.view(tensor.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 6 for calling the TorchCompressedDevice obj's underlying member method code with example usage: obj.decompress(tensor) and returns: data