code: def retrieve_predictor(
      endpoint_name: str,
      schema_builder: SchemaBuilder,
      sagemaker_session: Session,
      model_server: ModelServer = ModelServer.TORCHSERVE,
  ) -> Predictor:
      """Retrieve the predictor for existing sagemaker endpoint"""
      # TODO: extend to LOCAL_CONTAINER mode
      if model_server == ModelServer.TRITON:
          schema_builder._update_serializer_deserializer_for_triton()
          schema_builder._detect_dtype_for_triton()
          dtype = schema_builder._input_triton_dtype.split("_")[-1]
          serializer = TritonSerializer(
              input_serializer=schema_builder.input_serializer,
              dtype=dtype,
          )
          deserializer = JSONDeserializer()
  
      elif model_server == ModelServer.TORCHSERVE:
          serializer = (
              schema_builder.custom_input_translator
              if hasattr(schema_builder, "custom_input_translator")
              else schema_builder.input_serializer
          )
          deserializer = (
              schema_builder.custom_output_translator
              if hasattr(schema_builder, "custom_output_translator")
              else schema_builder.output_deserializer
          )
  
      else:
          raise ValueError(
              "Unsupproted model_server: %s" % model_server
          )
  
      return Predictor(
          endpoint_name=endpoint_name,
          sagemaker_session=sagemaker_session,
          serializer=serializer,
          deserializer=deserializer,
      )
  
imports: from __future__ import absolute_import
  import io
  from typing import Type
  from sagemaker import Session
  from sagemaker.serve.mode.local_container_mode import LocalContainerMode
  from sagemaker.serve.builder.schema_builder import SchemaBuilder
  from sagemaker.serializers import IdentitySerializer, JSONSerializer
  from sagemaker.deserializers import BytesDeserializer, JSONDeserializer
  from sagemaker.base_predictor import PredictorBase, Predictor
  from sagemaker.serve.utils.types import ModelServer
  from sagemaker.serve.model_server.triton.triton_builder import TritonSerializer
label_desc: Use image node_id 2 for calling a global function with example usage: retrieve_predictor(endpoint_name, schema_builder, sagemaker_session, model_server) and returns: Predictor