class_docstr: TGI build logic for ModelBuilder()
class_docstr_tok: ["TGI","build","logic","for","ModelBuilder","(",")"]
docstr: Placeholder docstring
docstr_tok: ["Placeholder","docstring"]
code: def _tgi_model_builder_deploy_wrapper(
      self, *args, **kwargs
  ) -> Type[PredictorBase]:
      """Placeholder docstring"""
      timeout = kwargs.get("model_data_download_timeout")
      if timeout:
          self.pysdk_model.env.update(
              {"MODEL_LOADING_TIMEOUT": str(timeout)}
          )
  
      if "mode" in kwargs and kwargs.get("mode") != self.mode:
          overwrite_mode = kwargs.get("mode")
          # mode overwritten by customer during model.deploy()
          logger.warning(
              "Deploying in %s Mode, overriding existing configurations set for %s mode",
              overwrite_mode,
              self.mode,
          )
  
          if overwrite_mode == Mode.SAGEMAKER_ENDPOINT:
              self.mode = (
                  self.pysdk_model.mode
              ) = Mode.SAGEMAKER_ENDPOINT
          elif overwrite_mode == Mode.LOCAL_CONTAINER:
              self._prepare_for_mode()
              self.mode = self.pysdk_model.mode = Mode.LOCAL_CONTAINER
          else:
              raise ValueError(
                  "Mode %s is not supported!" % overwrite_mode
              )
  
      serializer = self.schema_builder.input_serializer
      deserializer = self.schema_builder._output_deserializer
      if self.mode == Mode.LOCAL_CONTAINER:
          timeout = kwargs.get("model_data_download_timeout")
  
          predictor = TgiLocalModePredictor(
              self.modes[str(Mode.LOCAL_CONTAINER)],
              serializer,
              deserializer,
          )
  
          ram_usage_before = _get_ram_usage_mb()
          self.modes[str(Mode.LOCAL_CONTAINER)].create_server(
              self.image_uri,
              timeout if timeout else 1800,
              None,
              predictor,
              self.pysdk_model.env,
              jumpstart=False,
          )
          ram_usage_after = _get_ram_usage_mb()
  
          self.ram_usage_model_load = max(
              ram_usage_after - ram_usage_before, 0
          )
  
          return predictor
  
      if "mode" in kwargs:
          del kwargs["mode"]
      if "role" in kwargs:
          self.pysdk_model.role = kwargs.get("role")
          del kwargs["role"]
  
      # set model_data to uncompressed s3 dict
      self.pysdk_model.model_data, env_vars = self._prepare_for_mode()
      self.env_vars.update(env_vars)
      self.pysdk_model.env.update(self.env_vars)
  
      # if the weights have been cached via local container mode -> set to offline
      if str(Mode.LOCAL_CONTAINER) in self.modes:
          self.pysdk_model.env.update({"TRANSFORMERS_OFFLINE": "1"})
      else:
          # if has not been built for local container we must use cache
          # that hosting has write access to.
          self.pysdk_model.env["TRANSFORMERS_CACHE"] = "/tmp"
          self.pysdk_model.env["HUGGINGFACE_HUB_CACHE"] = "/tmp"
  
      if "endpoint_logging" not in kwargs:
          kwargs["endpoint_logging"] = True
  
      if self.nb_instance_type and "instance_type" not in kwargs:
          kwargs.update({"instance_type": self.nb_instance_type})
      elif not self.nb_instance_type and "instance_type" not in kwargs:
          raise ValueError(
              "Instance type must be provided when deploying "
              "to SageMaker Endpoint mode."
          )
      else:
          try:
              tot_gpus = _get_gpu_info(
                  kwargs.get("instance_type"), self.sagemaker_session
              )
          except Exception:  # pylint: disable=W0703
              tot_gpus = _get_gpu_info_fallback(
                  kwargs.get("instance_type")
              )
          default_num_shard = _get_default_tensor_parallel_degree(
              self.hf_model_config, tot_gpus
          )
          self.pysdk_model.env.update(
              {
                  "NUM_SHARD": str(default_num_shard),
                  "SHARDED": "true"
                  if default_num_shard > 1
                  else "false",
              }
          )
  
      if "initial_instance_count" not in kwargs:
          kwargs.update({"initial_instance_count": 1})
  
      predictor = self._original_deploy(*args, **kwargs)
  
      self.pysdk_model.env.update({"TRANSFORMERS_OFFLINE": "0"})
  
      predictor.serializer = serializer
      predictor.deserializer = deserializer
      return predictor
  
imports: from __future__ import absolute_import
  import logging
  from typing import Type
  from abc import ABC, abstractmethod
  from datetime import datetime, timedelta
  from sagemaker.model import Model
  from sagemaker.serve.utils.exceptions import LocalDeepPingException, LocalModelLoadException, LocalModelOutOfMemoryException, LocalModelInvocationException, SkipTuningComboException
  from sagemaker.serve.utils.tuning import _serial_benchmark, _concurrent_benchmark, _more_performant, _pretty_print_results_tgi
  from sagemaker.djl_inference.model import _get_model_config_properties_from_hf
  from sagemaker.serve.model_server.djl_serving.utils import _get_admissible_tensor_parallel_degrees, _get_default_tensor_parallel_degree
  from sagemaker.serve.model_server.tgi.utils import _get_default_tgi_configurations, _get_admissible_dtypes
  from sagemaker.huggingface import HuggingFaceModel, get_huggingface_llm_image_uri
  from sagemaker.serve.utils.local_hardware import _get_nb_instance, _get_ram_usage_mb, _get_gpu_info, _get_gpu_info_fallback
  from sagemaker.serve.model_server.tgi.prepare import _create_dir_structure
  from sagemaker.serve.utils.predictors import TgiLocalModePredictor
  from sagemaker.serve.utils.types import ModelServer
  from sagemaker.serve.mode.function_pointers import Mode
  from sagemaker.serve.utils.telemetry_logger import _capture_telemetry
  from sagemaker.base_predictor import PredictorBase
label_desc: Use image node_id 7 for calling the TGI obj's underlying member method code with example usage: obj._tgi_model_builder_deploy_wrapper() and returns: predictor, predictor