class_docstr: High-level Python wrapper for a llama.cpp model.
docstr: Load a llama.cpp model from `model_path`.
  
  Args:
      model_path: Path to the model.
      n_ctx: Maximum context size.
      n_parts: Number of parts to split the model into. If -1, the number of parts
      is automatically determined.
      seed: Random seed. For default value -1, current timestamp is used as seed.
      f16_kv: Use half-precision for key/value cache.
      logits_all: Return logits for all tokens, not just the last token.
      vocab_only: Only load the vocabulary no weights.
      use_mmap: Use mmap if possible.
      use_mlock: Force the system to keep the model in RAM.
      embedding: Embedding mode only.
      n_threads: Number of threads to use. Default to be -1, means auto.
      n_batch: Maximum number of prompt tokens to batch together when calling llama_eval.
      last_n_tokens_size: Maximum number of tokens to keep in the last_n_tokens deque.
      lora_base: Optional path to base model, useful if using a quantized base model and
      you want to apply LoRA to an f16 model.
      lora_path: Path to a LoRA file to apply to the model.
      verbose: Print verbose output to stderr.
  
  Raises:
      ValueError: If the model path does not exist.
  
  Returns:
      A Llama instance.
docstr_tok: ["Load","a","llama.cpp","model","from","`","model_path","`",".","Args",":","model_path",":","Path","to","the","model",".","n_ctx",":","Maximum","context","size",".","n_parts",":","Number","of","parts","to","split","the","model","into",".","If","-1",",","the","number","of","parts","is","automatically","determined",".","seed",":","Random","seed",".","For","default","value","-1",",","current","timestamp","is","used","as","seed",".","f16_kv",":","Use","half-precision","for","key\/value","cache",".","logits_all",":","Return","logits","for","all","tokens",",","not","just","the","last","token",".","vocab_only",":","Only","load","the","vocabulary","no","weights",".","use_mmap",":","Use","mmap","if","possible",".","use_mlock",":","Force","the","system","to","keep","the","model","in","RAM",".","embedding",":","Embedding","mode","only",".","n_threads",":","Number","of","threads","to","use",".","Default","to","be","-1",",","means","auto",".","n_batch",":","Maximum","number","of","prompt","tokens","to","batch","together","when","calling","llama_eval",".","last_n_tokens_size",":","Maximum","number","of","tokens","to","keep","in","the","last_n_tokens","deque",".","lora_base",":","Optional","path","to","base","model",",","useful","if","using","a","quantized","base","model","and","you","want","to","apply","LoRA","to","an","f16","model",".","lora_path",":","Path","to","a","LoRA","file","to","apply","to","the","model",".","verbose",":","Print","verbose","output","to","stderr",".","Raises",":","ValueError",":","If","the","model","path","does","not","exist",".","Returns",":","A","Llama","instance","."]
code: def __init__(
      self,
      model_path: str,
      # NOTE: These parameters are likely to change in the future.
      n_ctx: int = 512,
      n_parts: int = -1,
      n_gpu_layers: int = 0,
      seed: int = -1,
      f16_kv: bool = True,
      logits_all: bool = False,
      vocab_only: bool = False,
      use_mmap: bool = False,
      use_mlock: bool = False,
      embedding: bool = False,
      n_threads: Optional[int] = -1,
      n_batch: int = 512,
      last_n_tokens_size: int = 64,
      lora_base: Optional[str] = None,
      lora_path: Optional[str] = None,
      verbose: bool = True,
  ):
      """Load a llama.cpp model from `model_path`.
  
      Args:
          model_path: Path to the model.
          n_ctx: Maximum context size.
          n_parts: Number of parts to split the model into. If -1, the number of parts
          is automatically determined.
          seed: Random seed. For default value -1, current timestamp is used as seed.
          f16_kv: Use half-precision for key/value cache.
          logits_all: Return logits for all tokens, not just the last token.
          vocab_only: Only load the vocabulary no weights.
          use_mmap: Use mmap if possible.
          use_mlock: Force the system to keep the model in RAM.
          embedding: Embedding mode only.
          n_threads: Number of threads to use. Default to be -1, means auto.
          n_batch: Maximum number of prompt tokens to batch together when calling llama_eval.
          last_n_tokens_size: Maximum number of tokens to keep in the last_n_tokens deque.
          lora_base: Optional path to base model, useful if using a quantized base model and
          you want to apply LoRA to an f16 model.
          lora_path: Path to a LoRA file to apply to the model.
          verbose: Print verbose output to stderr.
  
      Raises:
          ValueError: If the model path does not exist.
  
      Returns:
          A Llama instance.
      """
      self.verbose = verbose
      self.model_path = model_path
  
      self.params = llama_cpp.llama_context_default_params()
      self.params.n_ctx = n_ctx
      self.params.n_gpu_layers = n_gpu_layers
      self.params.seed = seed
      self.params.f16_kv = f16_kv
      self.params.logits_all = logits_all
      self.params.vocab_only = vocab_only
      self.params.use_mmap = use_mmap if lora_path is None else False
      self.params.use_mlock = use_mlock
      self.params.embedding = embedding
  
      self.last_n_tokens_size = last_n_tokens_size
      self.n_batch = min(n_ctx, n_batch)
      self.eval_tokens: Deque[int] = deque(maxlen=n_ctx)
      self.eval_logits: Deque[List[float]] = deque(
          maxlen=n_ctx if logits_all else 1
      )
  
      self.cache: Optional[LlamaCache] = None
  
      self.n_threads = n_threads
  
      self.lora_base = lora_base
      self.lora_path = lora_path
  
      # DEPRECATED
      self.n_parts = n_parts
      # DEPRECATED
  
      invalidInputError(
          os.path.exists(model_path),
          f"Model path does not exist: {model_path}.",
      )
  
      self.ctx = llama_cpp.llama_init_from_file(
          self.model_path.encode("utf-8"), self.params
      )
  
      invalidInputError(
          self.ctx is not None,
          "The attribute `ctx` of `Llama` object is None.",
      )
  
      if self.lora_path:
          if llama_cpp.llama_apply_lora_from_file(
              self.ctx,
              llama_cpp.c_char_p(self.lora_path.encode("utf-8")),
              llama_cpp.c_char_p(self.lora_base.encode("utf-8"))
              if self.lora_base is not None
              else llama_cpp.c_char_p(0),
              llama_cpp.c_int(self.n_threads),
          ):
              invalidInputError(
                  False,
                  "Failed to apply LoRA from lora path: "
                  f"{self.lora_path} to base path: {self.lora_base}",
              )
  
      if self.verbose:
          print(
              llama_cpp.llama_print_system_info().decode("utf-8"),
              file=sys.stderr,
          )
  
      n_vocab = self.n_vocab()
      n_ctx = self.n_ctx()
      data = (llama_cpp.llama_token_data * n_vocab)(
          *[
              llama_cpp.llama_token_data(
                  id=llama_cpp.llama_token(i),
                  logit=llama_cpp.c_float(0.0),
                  p=llama_cpp.c_float(0.0),
              )
              for i in range(n_vocab)
          ]
      )
      size = llama_cpp.c_size_t(n_vocab)
      sorted = False
      candidates = llama_cpp.llama_token_data_array(
          data=data,
          size=size,
          sorted=sorted,
      )
      self._candidates = candidates
      self._token_nl = Llama.token_nl()
      self._token_eos = Llama.token_eos()
  
imports: import os
  import sys
  import uuid
  import time
  import math
  import multiprocessing
  from typing import List, Optional, Union, Generator, Sequence, Iterator, Deque, Tuple
  from collections import deque, OrderedDict
  from bigdl.llm.utils.common import invalidInputError
  from bigdl.llm.ggml.model.generation import GenerationMixin
  from .None import llama_cpp
  from .llama_types import *
label_desc: Use image node_id 1 to create a new Llama object from inherited base classes: GenerationMixin with example: obj = Llama(model_path, n_ctx, n_parts, n_gpu_layers, seed, f16_kv, logits_all, vocab_only, use_mmap, use_mlock, embedding, n_threads, n_batch, last_n_tokens_size, lora_base, lora_path, verbose)