code: def main():
      args = parse_args()
      if args.generation_method not in ["topk", "topp", "ppl"]:
          args.generation_method = "topk"
      model_name = ".".join(args.model.split(".")[:-1])
      ckpt_path = f"{model_name}.bin"
  
      print("initializing gpt2 config...")
      config = GPT2Config.from_pretrained("gpt2")
  
      print("initializing gpt2 tokenizer...")
      ls_tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
      # lightseq use len(tokenizer) as pad_token in default
      ls_tokenizer.add_special_tokens({"pad_token": "[PAD]"})
      print(
          f"lightseq tokenizer pad token id: {ls_tokenizer.pad_token_id}"
      )
  
      hf_tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
      # use EOS as PAD for huggingface to avoid warning according to https://huggingface.co/blog/how-to-generate while avoid reshaping the model embedding
      hf_tokenizer.pad_token = hf_tokenizer.eos_token
      print(
          f"huggingface tokenizer pad token id: {hf_tokenizer.pad_token_id}"
      )
  
      print("creating huggingface model...")
      hf_model = GPT2LMHeadModel.from_pretrained("gpt2", config=config)
      inject_ls_layer(hf_model, config)
      state_dict = torch.load(ckpt_path, map_location="cpu")
      hf_model.load_state_dict(state_dict, strict=False)
      hf_model.to("cuda:0")
      hf_model.eval()
  
      print("creating lightseq model...")
      ls_model = lsi.QuantGpt(args.model, max_batch_size=16)
  
      # lightseq gpt perplexity supports batch infer with different lengths,
      # but sampling doesn't support
      sentences = [
          "I love you, but you say that",
          "I love you, but you say that",
          "I love you, but you say that",
          "I love you, but you say that",
      ]
  
      print("====================START warmup====================")
      warmup(
          ls_tokenizer,
          hf_tokenizer,
          ls_model,
          hf_model,
          sentences,
          args.generation_method,
      )
      print("====================END warmup====================")
  
      print("tokenizing the sentences...")
      ls_inputs = ls_tokenizer(
          sentences, return_tensors="pt", padding=True
      )["input_ids"]
      hf_inputs = hf_tokenizer(
          sentences, return_tensors="pt", padding=True
      )["input_ids"]
  
      if (
          args.generation_method == "topk"
          or args.generation_method == "topp"
      ):
          ls_generate(ls_model, ls_tokenizer, ls_inputs)
          # hf_generate(hf_model, hf_tokenizer, hf_inputs)
      elif args.generation_method == "ppl":
          ls_ppl(ls_model, ls_tokenizer, ls_inputs)
          hf_ppl(hf_model, hf_tokenizer, hf_inputs)
  
imports: import time
  import torch
  from torch import nn
  from transformers import GPT2Tokenizer, GPT2LMHeadModel, GPT2Config
  import lightseq.inference
  from lightseq.training.ops.pytorch.quantization import qat_mode, QuantLinear, TensorQuantizer, weight_quant_config, emb_quant_config
  from lightseq.training.ops.pytorch.torch_transformer_layers import TransformerDecoderLayer
  from export.util import parse_args
label_desc: Use image node_id 11 for calling a global function with example usage: main() without return types