11#!/usr/bin/env python
2- # -*- coding: utf-8; -*-
32
43# Copyright (c) 2023 Oracle and/or its affiliates.
54# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/from typing import Dict
65
76
87from typing import Dict , List
8+
99from ads .jobs .builders .base import Builder
1010
1111MODEL_DEPLOYMENT_RUNTIME_KIND = "runtime"
@@ -519,6 +519,8 @@ class ModelDeploymentContainerRuntime(ModelDeploymentRuntime):
519519 The server port of model deployment container runtime.
520520 health_check_port: int
521521 The health check port of model deployment container runtime.
522+ custom_model_name : str
523+ The custom model name for single model deployment, to be used in predict calls
522524
523525 Methods
524526 -------
@@ -534,6 +536,8 @@ class ModelDeploymentContainerRuntime(ModelDeploymentRuntime):
534536 Sets the server port of model deployment container runtime
535537 with_health_check_port(health_check_port)
536538 Sets the health check port of model deployment container runtime
539+ with_custom_model_name(custom_model_name)
540+ Sets a custom model name for single model deployment, to be used in predict calls
537541
538542 Examples
539543 --------
@@ -560,6 +564,7 @@ class ModelDeploymentContainerRuntime(ModelDeploymentRuntime):
560564 CONST_SERVER_PORT = "serverPort"
561565 CONST_HEALTH_CHECK_PORT = "healthCheckPort"
562566 CONST_INFERENCE_SERVER = "inferenceServer"
567+ CONST_CUSTOM_MODEL_NAME = "customModelName"
563568
564569 attribute_map = {
565570 ** ModelDeploymentRuntime .attribute_map ,
@@ -570,6 +575,7 @@ class ModelDeploymentContainerRuntime(ModelDeploymentRuntime):
570575 CONST_SERVER_PORT : "server_port" ,
571576 CONST_HEALTH_CHECK_PORT : "health_check_port" ,
572577 CONST_INFERENCE_SERVER : "inference_server" ,
578+ CONST_CUSTOM_MODEL_NAME : "custom_model_name" ,
573579 }
574580
575581 payload_attribute_map = {
@@ -580,6 +586,7 @@ class ModelDeploymentContainerRuntime(ModelDeploymentRuntime):
580586 CONST_ENTRYPOINT : f"{ ModelDeploymentRuntime .ENVIRONMENT_CONFIG_DETAILS_PATH } .entrypoint" ,
581587 CONST_SERVER_PORT : f"{ ModelDeploymentRuntime .ENVIRONMENT_CONFIG_DETAILS_PATH } .server_port" ,
582588 CONST_HEALTH_CHECK_PORT : f"{ ModelDeploymentRuntime .ENVIRONMENT_CONFIG_DETAILS_PATH } .health_check_port" ,
589+ CONST_CUSTOM_MODEL_NAME : f"{ ModelDeploymentRuntime .ENVIRONMENT_CONFIG_DETAILS_PATH } .custom_model_name" ,
583590 }
584591
585592 @property
@@ -820,6 +827,62 @@ def with_inference_server(
820827 """
821828 return self .set_spec (self .CONST_INFERENCE_SERVER , inference_server .lower ())
822829
830+ @property
831+ def custom_model_name (self ) -> str :
832+ """Returns the custom model name.
833+
834+ Returns
835+ -------
836+ str
837+ The custom model name.
838+ """
839+ return self .get_spec (self .CONST_CUSTOM_MODEL_NAME , None )
840+
841+ def with_custom_model_name (
842+ self , custom_model_name : str = "odsc-llm"
843+ ) -> "ModelDeploymentContainerRuntime" :
844+ """Sets the custom model name. Defaults to odsc-llm if you do not set the custom model name.
845+
846+ Parameters
847+ ----------
848+ custom_model_name: str
849+ Set the custom model name to be used for inferencing.
850+
851+ Returns
852+ -------
853+ ModelDeploymentContainerRuntime
854+ The ModelDeploymentContainerRuntime instance (self).
855+
856+ Example
857+ -------
858+ >>> from ads.model.deployment import ModelDeployment, ModelDeploymentContainerRuntime, ModelDeploymentInfrastructure
859+ >>> import ads
860+ >>> ads.set_auth("resource_principal")
861+ >>> infrastructure = ModelDeploymentInfrastructure()\
862+ ... .with_project_id(<project_id>)\
863+ ... .with_compartment_id(<comparment_id>)\
864+ ... .with_shape_name("VM.Standard.E4.Flex")\
865+ ... .with_replica(2)\
866+ ... .with_bandwidth_mbps(10)\
867+ ... .with_access_log(log_group_id=<deployment_log_group_id>, log_id=<deployment_access_log_id>)\
868+ ... .with_predict_log(log_group_id=<deployment_log_group_id>, log_id=<deployment_predict_log_id>)
869+
870+ >>> runtime = ModelDeploymentContainerRuntime()\
871+ ... .with_image(<container_image>)\
872+ ... .with_server_port(<server_port>)\
873+ ... .with_health_check_port(<health_check_port>)\
874+ ... .with_model_uri(<model_id>)\
875+ ... .with_env({"key":"value", "key2":"value2"})\
876+ ... .with_inference_server("triton")
877+ >>> deployment = ModelDeployment()\
878+ ... .with_display_name("Triton Example")\
879+ ... .with_infrastructure(infrastructure)\
880+ ... .with_runtime(runtime)
881+ .with_custom_model_name("myModel")
882+ >>> deployment.deploy()
883+ """
884+ return self .set_spec (self .CONST_CUSTOM_MODEL_NAME , custom_model_name )
885+
823886 def init (self , ** kwargs ) -> "ModelDeploymentContainerRuntime" :
824887 """Initializes a starter specification for the runtime.
825888
0 commit comments