code: def to_int8(
      self, sparse=False, ths_path="./lib/libth_transformer.so"
  ):
      if self._generated_weights:
          amax_tensor_1 = torch.Tensor(self.hidden_dim).fill_(127.0)
          amax_tensor_2 = torch.Tensor(self.hidden_dim * 4).fill_(127.0)
          for i in range(self.layer_num):
              pre = "encoder.layer." + str(i) + "."
              self.weights[
                  pre + "attention.self.query._input_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "attention.self.query._weight_quantizer._amax"
              ] = amax_tensor_1
              self.weights[
                  pre
                  + "attention.self.query._aftergemm_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "attention.self.key._input_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "attention.self.key._weight_quantizer._amax"
              ] = amax_tensor_1
              self.weights[
                  pre + "attention.self.key._aftergemm_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "attention.self.value._input_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "attention.self.value._weight_quantizer._amax"
              ] = amax_tensor_1
              self.weights[
                  pre
                  + "attention.self.value._aftergemm_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "attention.self.matmul_q_input_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "attention.self.matmul_k_input_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "attention.self.matmul_v_input_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "attention.self.matmul_a_input_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "attention.self.softmax_input_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "attention.output.dense._input_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "attention.output.dense._weight_quantizer._amax"
              ] = amax_tensor_1
              self.weights[
                  pre
                  + "attention.output.dense._aftergemm_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre
                  + "attention.output.add_local_input_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre
                  + "attention.output.add_residual_input_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "intermediate.dense._input_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "intermediate.dense._weight_quantizer._amax"
              ] = amax_tensor_2
              self.weights[
                  pre + "intermediate.dense._aftergemm_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "output.dense._input_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "output.dense._weight_quantizer._amax"
              ] = amax_tensor_1
              self.weights[
                  pre + "output.dense._aftergemm_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "output.add_local_input_quantizer._amax"
              ] = torch.tensor(127.0)
              self.weights[
                  pre + "output.add_residual_input_quantizer._amax"
              ] = torch.tensor(127.0)
      if (
          "encoder.layer.0.attention.self.query._input_quantizer._amax"
          not in self.weights
      ):
          raise RuntimeError(
              "There is no quantization node in the checkpoint, cannot be quantized to int8."  # noqa: E501
          )
      if self.int8:
          return
      self.int8 = True
      for k, v in self.weights.items():
          if k.endswith("bias") or k.endswith("LayerNorm.weight"):
              self.weights[k] = v.half()
          elif k.endswith("weight"):
              self.weights[k] = v.float().cuda()
          else:
              self.weights[k] = v.float().cpu()
      self.weights = checkpoint_quantization(
          self.weights, sparse, ths_path, verbose=False
      )
  
imports: from typing import List, Optional
  from loguru import logger
  from nebullvm.optional_modules.torch import torch, torch_distributed
  from nebullvm.optional_modules.huggingface import BertConfig, BertEmbeddings, BertEncoder, BertPooler, BertPreTrainedModel
  from .checkpoint_quantization import checkpoint_quantization
label_desc: Use image node_id 6 for calling the EncoderWeights obj's underlying member method code with example usage: obj.to_int8(sparse, ths_path) without return types