code: def compute_hf_ppl(model, inputs):
      max_length = 512
      stride = 512
      end_loc = 0
  
      nlls = []
      for i in range(0, inputs.size(1), stride):
          begin_loc = max(i + stride - max_length, 0)
          end_loc = min(i + stride, inputs.size(1))
          trg_len = end_loc - i
          input_ids = inputs[:, begin_loc:end_loc].to("cuda:0")
          target_ids = input_ids.clone()
          target_ids[:, :-trg_len] = -100
  
          with torch.no_grad():
              outputs = model(input_ids, labels=target_ids)
              neg_log_likelihood = outputs[0] * trg_len
  
          nlls.append(neg_log_likelihood)
  
      ppl = torch.stack(nlls).sum() / end_loc
      return ppl.cpu().numpy()
  
file_path: lightseq/examples/inference/python/test/ls_gpt2_bench.py
imports: import time
  import argparse
  import torch
  import lightseq.inference
  from transformers import GPT2Tokenizer, GPT2LMHeadModel
label_desc: Use image node_id 2 for calling a global function with example usage: compute_hf_ppl(model, inputs) and returns: ppl