class_docstr: Model wrapper around HuggingFace AutoModel models.
  
  Args:
      path: The path to a HuggingFace model.
      model_max_length: The maximum sequence length of the model.
      tokenizer_path: The path to the tokenizer.
      tokenizer_kwargs: Keyword arguments for the tokenizer.
      peft_path: The name or path to the HuggingFace's PEFT model.
      model_kwargs: Keyword arguments for the model.
      prompt_template: The model's prompt template.
      batch_size: Batch size for inference.
      logger: Logger for the model.
      shard_config: Shard config for tensor parallel.
class_docstr_tok: ["Model","wrapper","around","HuggingFace","AutoModel","models",".","Args",":","path",":","The","path","to","a","HuggingFace","model",".","model_max_length",":","The","maximum","sequence","length","of","the","model",".","tokenizer_path",":","The","path","to","the","tokenizer",".","tokenizer_kwargs",":","Keyword","arguments","for","the","tokenizer",".","peft_path",":","The","name","or","path","to","the","HuggingFace","'s","PEFT","model",".","model_kwargs",":","Keyword","arguments","for","the","model",".","prompt_template",":","The","model","'s","prompt","template",".","batch_size",":","Batch","size","for","inference",".","logger",":","Logger","for","the","model",".","shard_config",":","Shard","config","for","tensor","parallel","."]
docstr: Get input_ids and labels for the given data.
  
  Args:
      batch_prompt: A batch of prompt.
      batch_target: A batch of target.
  
  Returns:
      Input_ids and labels for the given batch.
docstr_tok: ["Get","input_ids","and","labels","for","the","given","data",".","Args",":","batch_prompt",":","A","batch","of","prompt",".","batch_target",":","A","batch","of","target",".","Returns",":","Input_ids","and","labels","for","the","given","batch","."]
code: def _get_input_ids_and_labels(
      self,
      batch_prompt: List[str],
      batch_target: List[List[str]],
      pretrain: bool,
  ) -> Tuple[List[torch.LongTensor]]:
      """
      Get input_ids and labels for the given data.
  
      Args:
          batch_prompt: A batch of prompt.
          batch_target: A batch of target.
  
      Returns:
          Input_ids and labels for the given batch.
  
      """
      if pretrain:
          batch = []
          # Concatenate prompt and target answers.
          # You should decide the concatenation character in the corresponding dataset script in dataset folder. For example, in line 119 dataset/gsm.py, the concatenation character is space.
          for p, b in zip(batch_prompt, batch_target):
              batch.append(p + b[0])
  
          return self._get_input_ids_and_labels_pretrain(batch)
  
      input_ids_list = []
      labels_list = []
  
      for input, targets in zip(batch_prompt, batch_target):
          for target in targets:
              # TODO: Improve the labeling process. Should annotate the border by adding special tokens.
              target_tokenized = self.tokenizer(
                  [target],
                  truncation=True,
                  max_length=self.model_max_length,
                  return_tensors="pt",
              )
  
              # Get prompt with length model_max_length - len(target_tokenized).
              # Reserve some space for target answer tokens using max_new_tokens.
              # This will generate the correct start_idx and end_idx.
              max_new_tokens = target_tokenized["input_ids"][0].size(0)
              prompt_with_correct_length = self._get_truncated_prompts(
                  [input], max_new_tokens
              )[0]
              input_tokenized = self.tokenizer(
                  [prompt_with_correct_length],
                  truncation=True,
                  max_length=self.model_max_length - max_new_tokens,
                  return_tensors="pt",
              )
  
              target_tokenized = self.tokenizer(
                  [prompt_with_correct_length + target],
                  truncation=True,
                  max_length=self.model_max_length,
                  return_tensors="pt",
              )
  
              start_idx = input_tokenized["input_ids"][0].size(0)
              end_idx = target_tokenized["input_ids"][0].size(0)
  
              # Sometimes if the target is only an option such as A, B, C and D, the length of input_tokenized is equal to the length of target_tokenized, so we need -1.
              # This is caused by the different behavior of tokenizers.
              # For example, the tokenizer for Baichuan and Llama will cause such problem in a plain prompt setting.
              # The length of the tokenized sequences for prompt "Answer: " and "Answer: A" is the same.
              # Baichuan: [29394, 31143, 31106] [29394, 31143, 703]
              # Llama: [673, 29901, 29871] [673, 29901, 319]
              # The length for sequence "prompt" and "prompt + A" is equal.
              # For ChatGLM, the length of the tokenized sequences is different.
              # ChatGLM: [16583, 12] [16583, 12, 167]
  
              if start_idx == end_idx:
                  start_idx -= 1
  
              input_ids = copy.deepcopy(target_tokenized["input_ids"])[
                  0
              ]
              target_ids = copy.deepcopy(input_ids)
  
              mask = torch.zeros_like(target_ids, dtype=torch.bool)
              mask[start_idx:end_idx] = True
  
              target_ids[~mask] = IGNORE_INDEX
  
              input_ids_list.append(input_ids)
              labels_list.append(target_ids)
  
      return input_ids_list, labels_list, None
  
imports: import copy
  import math
  from typing import Any, Dict, List, Optional, Tuple
  import numpy
  import torch
  from colossal_eval.utils import Conversation, get_batch_prompt, is_rank_0
  from peft import PeftModel
  from tqdm import tqdm
  from transformers import AutoConfig, AutoModel, AutoModelForCausalLM, AutoTokenizer
  from colossalai.logging import DistributedLogger
  from colossalai.shardformer import ShardConfig, ShardFormer
  from .base import BaseModel
label_desc: Use image node_id 8 for calling the HuggingFaceModel obj's underlying member method code with example usage: obj._get_input_ids_and_labels(batch_prompt, batch_target, pretrain) and returns: input_ids_list,  labels_list,  None, self