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: Load model.
  
  Args:
      path: The path to the model.
      model_kwargs: Keyword arguments for the model.
      peft_path: The path to the peft model.
      shard_config: Shard config for tensor parallel.
docstr_tok: ["Load","model",".","Args",":","path",":","The","path","to","the","model",".","model_kwargs",":","Keyword","arguments","for","the","model",".","peft_path",":","The","path","to","the","peft","model",".","shard_config",":","Shard","config","for","tensor","parallel","."]
code: def _load_model(
      self,
      path: str,
      model_kwargs: dict,
      peft_path: Optional[str] = None,
      shard_config: ShardConfig = None,
  ):
      """
      Load model.
  
      Args:
          path: The path to the model.
          model_kwargs: Keyword arguments for the model.
          peft_path: The path to the peft model.
          shard_config: Shard config for tensor parallel.
  
      """
      if "torch_dtype" in model_kwargs:
          model_kwargs["torch_dtype"] = eval(
              model_kwargs["torch_dtype"]
          )
      else:
          model_kwargs.setdefault("torch_dtype", torch.float16)
  
      if "config" in model_kwargs:
          model_kwargs["config"] = AutoConfig.from_pretrained(
              model_kwargs["config"]
          )
  
      if shard_config is not None:
          self.model = AutoModel.from_pretrained(path, **model_kwargs)
          shard_former = ShardFormer(shard_config)
          self.model, sharded_parameters = shard_former.optimize(
              self.model
          )
          self.model.to(torch.cuda.current_device())
  
          if peft_path is not None:
              raise NotImplementedError(
                  "ShardFormer for PEFT models is not implemented."
              )
      else:
          self.model = AutoModel.from_pretrained(
              path, **model_kwargs
          ).to(torch.cuda.current_device())
          if peft_path is not None:
              self.model = PeftModel.from_pretrained(
                  self.model, peft_path, is_trainable=False
              )
      self.model.eval()
  
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 4 for calling the HuggingFaceModel obj's underlying member method code with example usage: obj._load_model(path, model_kwargs, peft_path, shard_config) without return types