docstr: Low memory version of LlamaForCausalLM : the model is splitted into layer shards to reduce GPU memory usage.
  During the forward pass, the inputs are processed layer by layer, and the GPU memory is freed after each layer.
  
  Parameters
  ----------
  model_path (`str`):
      The huggingface repo id or path to the huggingface checkpoint folder that including config.json and tokenizer.model.
  splitted_weights_path (`str`):
      The folder including int4 weights per layer. You can use `LowMemoryLlama.split_and_convert_to_cpu_int4_weights` to generate those weights.
  max_cache_num (`int`, *optional*):
      The maximum number of weights saved in the cache_dict. You can adjust this number based on your GPU memory.
      Default is 100.
docstr_tok: ["Low","memory","version","of","LlamaForCausalLM",":","the","model","is","splitted","into","layer","shards","to","reduce","GPU","memory","usage",".","During","the","forward","pass",",","the","inputs","are","processed","layer","by","layer",",","and","the","GPU","memory","is","freed","after","each","layer",".","Parameters","--","--","--","--","--","model_path","(","`","str","`",")",":","The","huggingface","repo","id","or","path","to","the","huggingface","checkpoint","folder","that","including","config.json","and","tokenizer.model",".","splitted_weights_path","(","`","str","`",")",":","The","folder","including","int4","weights","per","layer",".","You","can","use","`","LowMemoryLlama.split_and_convert_to_cpu_int4_weights","`","to","generate","those","weights",".","max_cache_num","(","`","int","`",",","*","optional","*",")",":","The","maximum","number","of","weights","saved","in","the","cache_dict",".","You","can","adjust","this","number","based","on","your","GPU","memory",".","Default","is","100","."]
code: def __init__(
      self,
      model_path: str,
      splitted_weights_path: str,
      max_cache_num: Optional[int] = 100,
  ):
      """
      Low memory version of LlamaForCausalLM : the model is splitted into layer shards to reduce GPU memory usage.
      During the forward pass, the inputs are processed layer by layer, and the GPU memory is freed after each layer.
  
      Parameters
      ----------
      model_path (`str`):
          The huggingface repo id or path to the huggingface checkpoint folder that including config.json and tokenizer.model.
      splitted_weights_path (`str`):
          The folder including int4 weights per layer. You can use `LowMemoryLlama.split_and_convert_to_cpu_int4_weights` to generate those weights.
      max_cache_num (`int`, *optional*):
          The maximum number of weights saved in the cache_dict. You can adjust this number based on your GPU memory.
          Default is 100.
      """
      super().__init__()
  
      # Save parameters
      self.model_path = model_path
      self.splitted_weights_path = splitted_weights_path
      self.device = torch.device("xpu:0")
      self.layer_weight_cache = {}  # initialize weight cache dict
      self.max_cache_num = max_cache_num
  
      # Create model
      self._create_model()
      # Check if `self.splitted_weights_path` exists
      self._check_split_weight_path()
  
      # Initialize attention mask and position ids to further improve the inference speed
      self._generate_att_mask_and_pos_id()
  
imports: import argparse
  import gc
  import os
  import time
  import warnings
  from typing import Dict, List, Optional, Union
  import torch
  import torch.nn
  from accelerate import init_empty_weights
  from safetensors.torch import load_file, save_file
  from tqdm.auto import tqdm
  from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
  from transformers.generation import GenerationMixin
  from transformers.modeling_outputs import CausalLMOutputWithPast
  from bigdl.llm import optimize_model
  from bigdl.llm.transformers.low_bit_linear import FP4Params, LowBitLinear
label_desc: Use image node_id 1 to create a new LowMemoryLlama object from inherited base classes: GenerationMixin with example: obj = LowMemoryLlama(model_path, splitted_weights_path, max_cache_num)