code: def from_pretrained(
      cls,
      pretrained_model_name_or_path: str,
      max_memory: Optional[dict] = None,
      trust_remote_code: bool = False,
      torch_dtype: torch.dtype = torch.float16,
      **model_init_kwargs,
  ):
      if not torch.cuda.is_available():
          raise EnvironmentError(
              "Load pretrained model to do quantization requires CUDA available."
          )
  
      def skip(*args, **kwargs):
          pass
  
      torch.nn.init.kaiming_uniform_ = skip
      torch.nn.init.uniform_ = skip
      torch.nn.init.normal_ = skip
  
      # Parameters related to loading from Hugging Face Hub
      cache_dir = model_init_kwargs.pop("cache_dir", None)
      force_download = model_init_kwargs.pop("force_download", False)
      resume_download = model_init_kwargs.pop("resume_download", False)
      proxies = model_init_kwargs.pop("proxies", None)
      local_files_only = model_init_kwargs.pop(
          "local_files_only", False
      )
      use_auth_token = model_init_kwargs.pop("use_auth_token", None)
      revision = model_init_kwargs.pop("revision", None)
      subfolder = model_init_kwargs.pop("subfolder", "")
      model_init_kwargs.pop("_commit_hash", None)
  
      cached_file_kwargs = {
          "cache_dir": cache_dir,
          "force_download": force_download,
          "proxies": proxies,
          "resume_download": resume_download,
          "local_files_only": local_files_only,
          "use_auth_token": use_auth_token,
          "revision": revision,
          "subfolder": subfolder,
      }
  
      config = AutoConfig.from_pretrained(
          pretrained_model_name_or_path,
          trust_remote_code=True,
          **cached_file_kwargs,
      )
      if config.model_type not in SUPPORTED_MODELS:
          raise TypeError(f"{config.model_type} isn't supported yet.")
  
      # enforce some values despite user specified
      model_init_kwargs["torch_dtype"] = torch_dtype
      model_init_kwargs["trust_remote_code"] = trust_remote_code
      if max_memory:
          if "disk" in max_memory:
              raise NotImplementedError("disk offload not support yet.")
          with accelerate.init_empty_weights():
              model = AutoModelForCausalLM.from_config(
                  config, trust_remote_code=True
              )
          model.tie_weights()
  
          max_memory = accelerate.utils.get_balanced_memory(
              model,
              max_memory=max_memory,
              no_split_module_classes=[cls.layer_type],
              dtype=model_init_kwargs["torch_dtype"],
              low_zero=False,
          )
          model_init_kwargs[
              "device_map"
          ] = accelerate.infer_auto_device_map(
              model,
              max_memory=max_memory,
              no_split_module_classes=[cls.layer_type],
              dtype=model_init_kwargs["torch_dtype"],
          )
          model_init_kwargs["low_cpu_mem_usage"] = True
  
          del model
      else:
          model_init_kwargs["device_map"] = None
          model_init_kwargs["low_cpu_mem_usage"] = False
  
      torch.cuda.empty_cache()
  
      merged_kwargs = {**model_init_kwargs, **cached_file_kwargs}
      model = AutoModelForCausalLM.from_pretrained(
          pretrained_model_name_or_path, **merged_kwargs
      )
  
      model_config = model.config.to_dict()
      seq_len_keys = [
          "max_position_embeddings",
          "seq_length",
          "n_positions",
      ]
      if any([k in model_config for k in seq_len_keys]):
          for key in seq_len_keys:
              if key in model_config:
                  model.seqlen = model_config[key]
                  break
      else:
          warnings.warn(
              "can't get model's sequence length from model config, will set to 4096."
          )
          model.seqlen = 4096
      model.eval()
  
      return cls(model, False)
  
imports: import os
  import warnings
  from abc import abstractmethod
  from functools import partial
  from os.path import isdir, isfile, join
  from typing import Dict, List, Optional, Union
  import numpy
  import torch
  import torch.nn
  import transformers
  from safetensors.torch import save_file
  from tqdm import tqdm
  from transformers import AutoConfig, AutoModelForCausalLM, PreTrainedModel
  from transformers.modeling_utils import no_init_weights
  from transformers.utils.generic import ContextManagers
  from transformers.utils.hub import PushToHubMixin, cached_file
  from colossalai.inference.kv_cache.batch_infer_state import BatchInferState, MemoryManager
label_desc: Use image node_id 16 for calling the BaseSmoothForCausalLM obj's underlying member method code with example usage: obj.from_pretrained(cls, pretrained_model_name_or_path, max_memory, trust_remote_code, torch_dtype) and returns: cls