class_docstr: Triton build logic for model builder
class_docstr_tok: ["Triton","build","logic","for","model","builder"]
code: def _prepare_for_triton(self):
      # Prepare directory
      model_path = Path(self.model_path)
      pkl_path = model_path.joinpath("model_repository").joinpath(
          "model"
      )
      if not pkl_path.exists():
          pkl_path.mkdir(parents=True)
  
      # Copy local model artifacts to triton model dir - excluding files under model_repository
      for root, _, files in os.walk(self.model_path):
          for f in files:
              path_file = os.path.join(root, f)
              if "model_repository" not in path_file:
                  shutil.copy2(path_file, str(pkl_path.joinpath(f)))
  
      export_path = (
          model_path.joinpath("model_repository")
          .joinpath("model")
          .joinpath("1")
      )
      if not export_path.exists():
          export_path.mkdir(parents=True)
  
      if self.model:
          self.secret_key = "dummy secret key for onnx backend"
  
          if self._framework == "pytorch":
              self._export_pytorch_to_onnx(
                  export_path=export_path,
                  model=self.model,
                  schema_builder=self.schema_builder,
              )
              return
  
          if self._framework == "tensorflow":
              self._export_tf_to_onnx(
                  export_path=export_path,
                  model=self.model,
                  schema_builder=self.schema_builder,
              )
              return
  
          raise ValueError("%s is not supported" % self._framework)
  
      if self.inference_spec:
          triton_model_path = Path(__file__).parent.joinpath("model.py")
          shutil.copy2(str(triton_model_path), str(export_path))
  
          self._generate_config_pbtxt(pkl_path=pkl_path)
  
          self._pack_conda_env(pkl_path=pkl_path)
  
          self._hmac_signing()
  
          return
  
      raise ValueError(
          "Either model or inference_spec should be provided to ModelBuilder."
      )
  
imports: from __future__ import absolute_import
  import os
  import logging
  import platform
  from abc import abstractmethod
  from pathlib import Path
  import sys
  from typing import Type
  import shutil
  import subprocess
  from sagemaker import Session
  from sagemaker.model import Model
  from sagemaker.base_predictor import Predictor
  from sagemaker.serve.builder.schema_builder import SchemaBuilder
  from sagemaker.serve.mode.function_pointers import Mode
  from sagemaker.serve.detector.image_detector import _detect_framework_and_version, _get_model_base
  from sagemaker.serve.utils.local_hardware import _get_available_gpus
  from sagemaker.base_serializers import JSONSerializer
  from sagemaker.base_deserializers import JSONDeserializer
  from sagemaker.serve.detector.pickler import save_pkl
  from sagemaker.serve.model_server.triton.config_template import CONFIG_TEMPLATE
  from sagemaker.serve.validations.check_integrity import generate_secret_key, compute_hash
  from sagemaker.remote_function.core.serialization import _MetaData
label_desc: Use image node_id 3 for calling the Triton obj's underlying member method code with example usage: obj._prepare_for_triton() without return types