class_docstr: Ternary quantization
docstr: Args:
      inputs (`torch.FloatTensor`)
          The input which needs to be quantized
      num_bits (int)
          Dummy variable
      min_value/max_vlue (torch.FloatTensor)
          Used for static activation quantization; for now they are dummy variable
      num_groups (int)
          How many groups to partition the quantization into
  Returns:
      quantized_input (`torch.FloatTensor`)
          Quantized input
docstr_tok: ["Args",":","inputs","(","`","torch.FloatTensor","`",")","The","input","which","needs","to","be","quantized","num_bits","(","int",")","Dummy","variable","min_value\/max_vlue","(","torch.FloatTensor",")","Used","for","static","activation","quantization",";","for","now","they","are","dummy","variable","num_groups","(","int",")","How","many","groups","to","partition","the","quantization","into","Returns",":","quantized_input","(","`","torch.FloatTensor","`",")","Quantized","input"]
code: def forward(
      ctx, input, num_bits, min_value=None, max_value=None, num_groups=1
  ):
      """
      Args:
          inputs (`torch.FloatTensor`)
              The input which needs to be quantized
          num_bits (int)
              Dummy variable
          min_value/max_vlue (torch.FloatTensor)
              Used for static activation quantization; for now they are dummy variable
          num_groups (int)
              How many groups to partition the quantization into
      Returns:
          quantized_input (`torch.FloatTensor`)
              Quantized input
      """
  
      assert min_value is None and max_value is None
      input_flat = input.reshape(num_groups, -1)
      n = input_flat.shape[1]
      m = input_flat.norm(p=1, dim=1).div(n)
      thres = (0.7 * m).view(-1, 1)
      pos = (input_flat > thres).type(input.type())
      neg = (input_flat < -thres).type(input.type())
      mask = (input_flat.abs() > thres).type(input.type())
      alpha = (
          (mask * input_flat).abs().sum(dim=1) / mask.sum(dim=1)
      ).view(-1, 1)
      output = alpha * pos - alpha * neg
      output = output.reshape(input.shape).contiguous()
      return output
  
imports: import torch
  from torch import autograd
  import math
label_desc: Use image node_id 1 for calling the TernaryQuantizer obj's underlying member method code with example usage: obj.forward(ctx, input, num_bits, min_value, max_value, num_groups) and returns: output