docstr: Load a low bit optimized model (including INT4, INT5 and INT8) from a saved ckpt.
  
  :param pretrained_model_name_or_path: str value, Path to load the optimized model ckpt.
  :param optimize_model: boolean value, Whether to further optimize the low_bit llm model.
                         Default to be True.
  
  :return: a model instance
docstr_tok: ["Load","a","low","bit","optimized","model","(","including","INT4",",","INT5","and","INT8",")","from","a","saved","ckpt",".",":","param","pretrained_model_name_or_path",":","str","value",",","Path","to","load","the","optimized","model","ckpt",".",":","param","optimize_model",":","boolean","value",",","Whether","to","further","optimize","the","low_bit","llm","model",".","Default","to","be","True",".",":","return",":","a","model","instance"]
code: def load_low_bit(
      cls, pretrained_model_name_or_path, *model_args, **kwargs
  ):
      """
      Load a low bit optimized model (including INT4, INT5 and INT8) from a saved ckpt.
  
      :param pretrained_model_name_or_path: str value, Path to load the optimized model ckpt.
      :param optimize_model: boolean value, Whether to further optimize the low_bit llm model.
                             Default to be True.
  
      :return: a model instance
      """
      from transformers.modeling_utils import (
          no_init_weights,
          get_state_dict_dtype,
      )
      from transformers.dynamic_module_utils import (
          resolve_trust_remote_code,
          get_class_from_dynamic_module,
      )
      from transformers.models.auto.configuration_auto import AutoConfig
      from transformers.utils.generic import ContextManagers
      from transformers.generation.configuration_utils import (
          GenerationConfig,
      )
      from transformers.models.auto.auto_factory import _get_model_class
      from accelerate.big_modeling import init_empty_weights
      from .convert import ggml_convert_low_bit
      import copy
      import os
  
      modules_to_not_convert = kwargs.pop(
          "modules_to_not_convert", None
      )
      cpu_embedding = kwargs.pop("cpu_embedding", False)
      if kwargs.pop("replace_embedding", False):
          warnings.warn(
              "replace_embedding is deprecated and will be removed in a future version,"
              " please use cpu_embedding instead.",
              FutureWarning,
          )
          cpu_embedding = True
      lightweight_bmm = kwargs.pop("lightweight_bmm", False)
      # Autofactory
      trust_remote_code = kwargs.pop("trust_remote_code", None)
      kwargs_orig = copy.deepcopy(kwargs)
  
      config, kwargs = AutoConfig.from_pretrained(
          pretrained_model_name_or_path,
          return_unused_kwargs=True,
          trust_remote_code=trust_remote_code,
          **kwargs,
      )
  
      # if torch_dtype=auto was passed here, ensure to pass it on
      if kwargs_orig.get("torch_dtype", None) == "auto":
          kwargs["torch_dtype"] = "auto"
  
      # Maybe needed when extract_local_archive_file
      subfolder = kwargs.get("subfolder", "")
      variant = kwargs.get("variant", None)
      offload_folder = kwargs.pop("offload_folder", None)
      offload_state_dict = kwargs.pop("offload_state_dict", False)
      torch_dtype = kwargs.pop("torch_dtype", "auto")
      sharded_metadata = None
  
      config_dict, _ = PretrainedConfig.get_config_dict(
          pretrained_model_name_or_path
      )
      bigdl_transformers_low_bit = config_dict.pop(
          "bigdl_transformers_low_bit", False
      )
      bigdl_lcmu_enabled = config_dict.pop("bigdl_lcmu_enabled", True)
  
      invalidInputError(
          bigdl_transformers_low_bit,
          "Detect this model is not a low-bit model, Please use from_pretrained"
          " with load_in_4bit or load_in_low_bit to get a low-bit model , and "
          " serialize the model using save_low_bit first.",
      )
  
      invalidInputError(
          bigdl_transformers_low_bit in ggml_tensor_qtype,
          f"Unknown bigdl_transformers_low_bit value: {bigdl_transformers_low_bit},"
          f" expected: sym_int4, asym_int4, sym_int5, asym_int5 or sym_int8.",
      )
  
      # set default optimize_model=True
      optimize_model = kwargs.pop("optimize_model", True)
  
      qtype = ggml_tensor_qtype[bigdl_transformers_low_bit]
  
      has_remote_code = (
          hasattr(config, "auto_map")
          and cls.HF_Model.__name__ in config.auto_map
      )
      has_local_code = (
          type(config) in cls.HF_Model._model_mapping.keys()
      )
      trust_remote_code = resolve_trust_remote_code(
          trust_remote_code,
          pretrained_model_name_or_path,
          has_local_code,
          has_remote_code,
      )
      if has_remote_code and trust_remote_code:
          class_ref = config.auto_map[cls.HF_Model.__name__]
          model_class = get_class_from_dynamic_module(
              class_ref, pretrained_model_name_or_path, **kwargs
          )
          if os.path.isdir(pretrained_model_name_or_path):
              model_class.register_for_auto_class(cls.HF_Model.__name__)
          else:
              cls.HF_Model.register(
                  config.__class__, model_class, exist_ok=True
              )
      elif type(config) in cls.HF_Model._model_mapping.keys():
          model_class = _get_model_class(
              config, cls.HF_Model._model_mapping
          )
  
      resolved_archive_file, is_sharded = extract_local_archive_file(
          pretrained_model_name_or_path, subfolder, variant
      )
  
      if is_sharded:
          (
              resolved_archive_file,
              sharded_metadata,
          ) = get_local_shard_files(
              pretrained_model_name_or_path,
              resolved_archive_file,
              subfolder=subfolder,
          )
  
      # set dtype to instantiate the model under:
      # 1. If torch_dtype is not None, we use that dtype
      # 2. If torch_dtype is "auto", we auto-detect dtype from the loaded state_dict,
      #    by checking its first weights entry that is of a floating type
      #    - we assume all floating dtype weights are of the same dtype
      # we also may have config.torch_dtype available, but we won't rely on it till v5
      dtype_orig = None
  
      if torch_dtype is not None:
          if isinstance(torch_dtype, str):
              if torch_dtype == "auto":
                  if (
                      hasattr(config, "torch_dtype")
                      and config.torch_dtype is not None
                  ):
                      torch_dtype = config.torch_dtype
  
                  else:
                      if is_sharded and "dtype" in sharded_metadata:
                          torch_dtype = sharded_metadata["dtype"]
                      else:
                          one_state_dict = load_state_dict(
                              resolved_archive_file[0]
                          )
                          torch_dtype = get_state_dict_dtype(
                              one_state_dict
                          )
                          del one_state_dict  # free CPU memory
              else:
                  invalidInputError(
                      False,
                      f'`torch_dtype` can be either `torch.dtype` or `"auto"`,'
                      "but received {torch_dtype}",
                  )
          dtype_orig = model_class._set_default_torch_dtype(torch_dtype)
  
      # Pretrained Model
      _fast_init = kwargs.pop("_fast_init", True)
      init_contexts = [no_init_weights(_enable=_fast_init)]
      init_contexts.append(init_empty_weights())
  
      if bigdl_lcmu_enabled:
          with ContextManagers(init_contexts):
              model = model_class(config, *model_args, **kwargs)
      else:
          model = model_class(config, *model_args, **kwargs)
  
      # Loading args may differ based on their usage
      quant_device = "meta" if bigdl_lcmu_enabled else "cpu"
      model = ggml_convert_low_bit(
          model,
          qtype,
          optimize_model,
          device=quant_device,
          modules_to_not_convert=modules_to_not_convert,
          cpu_embedding=cpu_embedding,
          lightweight_bmm=lightweight_bmm,
      )
  
      if is_sharded:
          loaded_state_dict_keys = sharded_metadata[
              "all_checkpoint_keys"
          ]
      else:
          import os
          import json
  
          with open(
              os.path.join(
                  pretrained_model_name_or_path, "load_keys.json"
              ),
              "r",
          ) as json_file:
              loaded_data = json.load(json_file)
          loaded_state_dict_keys = loaded_data["all_checkpoint_keys"]
  
      # restore default dtype
      if dtype_orig is not None:
          torch.set_default_dtype(dtype_orig)
  
      (
          model,
          missing_keys,
          unexpected_keys,
          mismatched_keys,
          offload_index,
          error_msgs,
      ) = model_class._load_pretrained_model(
          model,
          None,
          loaded_state_dict_keys,  # XXX: rename?
          resolved_archive_file,
          pretrained_model_name_or_path,
          sharded_metadata=sharded_metadata,
          _fast_init=_fast_init,
          low_cpu_mem_usage=bigdl_lcmu_enabled,
          offload_folder=offload_folder,
          offload_state_dict=offload_state_dict,
          dtype=torch_dtype,
          keep_in_fp32_modules=[],
      )
  
      # make sure token embedding weights are still tied if needed
      model.tie_weights()
  
      # Set model in evaluation mode to deactivate DropOut modules by default
      model.eval()
  
      # If it is a model with generation capabilities, attempt to load the generation config
      if model.can_generate():
          try:
              model.generation_config = (
                  GenerationConfig.from_pretrained(
                      pretrained_model_name_or_path,
                      subfolder=subfolder,
                      **kwargs,
                  )
              )
          except (OSError, TypeError):
              pass
      for param in model.parameters():
          param.requires_grad_(False)
      return model
  
imports: import transformers
  from transformers.configuration_utils import PretrainedConfig
  from .utils import extract_local_archive_file, load_state_dict, get_local_shard_files
  from bigdl.llm.ggml.quantize import ggml_tensor_qtype
  from bigdl.llm.utils.common import invalidInputError
  from bigdl.llm.transformers.gguf.api import load_gguf_model
  import torch
  import warnings
  import copy
  from .utils import logger
label_desc: Use image node_id 4 for calling the _BaseAutoModelClass obj's underlying member method code with example usage: obj.load_low_bit(cls, pretrained_model_name_or_path) and returns: model