class_docstr: Linear layer implementation with per-group 4-bit quantization of the weights
code: def __init__(
      self, qweight, qzeros, scales, g_idx, bias, bits, groupsize
  ):
      super().__init__()
      global MAX_DQ, MAX_INNER, ACT_ORDER, DEVICE
      assert bits == 4
  
      self.device = qweight.device
      self.qweight = qweight
      self.qzeros = qzeros
      self.scales = scales
      self.g_idx = g_idx.cpu() if g_idx is not None else None
      self.bias = bias if bias is not None else None
  
      if self.g_idx is not None and (
          (self.g_idx == 0).all()
          or torch.equal(
              g_idx.cpu(),
              torch.tensor(
                  [i // groupsize for i in range(g_idx.shape[0])],
                  dtype=torch.int32,
              ),
          )
      ):
          self.empty_g_idx = True
          self.g_idx = None
  
      assert self.device.type == "cuda"
      assert self.device.index is not None
  
      self.q4 = ext_make_q4(
          self.qweight,
          self.qzeros,
          self.scales,
          self.g_idx,
          self.device.index,
      )
  
      self.height = qweight.shape[0] * 8
      self.width = qweight.shape[1]
  
      # Infer groupsize from height of qzeros
      self.groupsize = None
      if self.qzeros.shape[0] > 1:
          self.groupsize = (self.qweight.shape[0] * 8) // (
              self.qzeros.shape[0]
          )
  
      if self.groupsize is not None:
          assert groupsize == self.groupsize
  
      # Handle act-order matrix
      if self.g_idx is not None:
          if self.groupsize is None:
              raise ValueError(
                  "Found group index but no groupsize. What do?"
              )
          self.act_order = True
      else:
          self.act_order = False
  
      DEVICE = self.qweight.device
  
      MAX_DQ = max(MAX_DQ, self.qweight.numel() * 8)
  
      if self.act_order:
          MAX_INNER = max(MAX_INNER, self.height, self.width)
  
          ACT_ORDER = True
  
file_path: text-generation-inference/server/text_generation_server/utils/gptq/exllama.py
imports: import torch
  from exllama_kernels import make_q4, q4_matmul, prepare_buffers, set_tuning_params
label_desc: Use image node_id 1 to create a new Ex4bitLinear object from inherited base classes: torch.nn with example: obj = Ex4bitLinear(qweight, qzeros, scales, g_idx, bias, bits, groupsize)