@@ -277,26 +277,30 @@ class ModelConfig:
277277
278278 def __init__ (
279279 self ,
280- model_name ,
281- instance_count ,
282- instance_type ,
283- accept_type = None ,
284- content_type = None ,
285- content_template = None ,
286- custom_attributes = None ,
287- accelerator_type = None ,
288- endpoint_name_prefix = None ,
289- target_model = None ,
280+ model_name : str = None ,
281+ instance_count : int = None ,
282+ instance_type : str = None ,
283+ accept_type : str = None ,
284+ content_type : str = None ,
285+ content_template : str = None ,
286+ custom_attributes : str = None ,
287+ accelerator_type : str = None ,
288+ endpoint_name_prefix : str = None ,
289+ target_model : str = None ,
290+ endpoint_name : str = None ,
290291 ):
291292 r"""Initializes a configuration of a model and the endpoint to be created for it.
292293
293294 Args:
294295 model_name (str): Model name (as created by
295296 `CreateModel <https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateModel.html>`_.
297+ Cannot be set when ``endpoint_name`` is set. Must be set with ``instance_count``, ``instance_type``
296298 instance_count (int): The number of instances of a new endpoint for model inference.
299+ Cannot be set when ``endpoint_name`` is set. Must be set with ``model_name``, ``instance_type``
297300 instance_type (str): The type of
298301 `EC2 instance <https://aws.amazon.com/ec2/instance-types/>`_
299302 to use for model inference; for example, ``"ml.c5.xlarge"``.
303+ Cannot be set when ``endpoint_name`` is set. Must be set with ``instance_count``, ``model_name``
300304 accept_type (str): The model output format to be used for getting inferences with the
301305 shadow endpoint. Valid values are ``"text/csv"`` for CSV and
302306 ``"application/jsonlines"``. Default is the same as ``content_type``.
@@ -326,17 +330,39 @@ def __init__(
326330 target_model (str): Sets the target model name when using a multi-model endpoint. For
327331 more information about multi-model endpoints, see
328332 https://docs.aws.amazon.com/sagemaker/latest/dg/multi-model-endpoints.html
333+ endpoint_name (str): Sets the endpoint_name when re-uses an existing endpoint. Cannot be set
334+ when ``model_name``, ``instance_count``, and ``instance_type`` set
329335
330336 Raises:
331- ValueError: when the ``endpoint_name_prefix`` is invalid, ``accept_type`` is invalid,
332- ``content_type`` is invalid, or ``content_template`` has no placeholder "features"
337+ ValueError: when the
338+ - ``endpoint_name_prefix`` is invalid,
339+ - ``accept_type`` is invalid,
340+ - ``content_type`` is invalid,
341+ - ``content_template`` has no placeholder "features"
342+ - both [``endpoint_name``] AND [``model_name``, ``instance_count``, ``instance_type``] are set
343+ - both [``endpoint_name``] AND [``endpoint_name_prefix``] are set
333344 """
334- self .predictor_config = {
335- "model_name" : model_name ,
336- "instance_type" : instance_type ,
337- "initial_instance_count" : instance_count ,
338- }
339- if endpoint_name_prefix is not None :
345+
346+ # validation
347+ _model_endpoint_config_rule = (
348+ all ([model_name , instance_count , instance_type ]),
349+ all ([endpoint_name ]),
350+ )
351+ assert any (_model_endpoint_config_rule ) and not all (_model_endpoint_config_rule )
352+ if endpoint_name :
353+ assert not endpoint_name_prefix
354+
355+ # main init logic
356+ self .predictor_config = (
357+ {
358+ "model_name" : model_name ,
359+ "instance_type" : instance_type ,
360+ "initial_instance_count" : instance_count ,
361+ }
362+ if not endpoint_name
363+ else {"endpoint_name" : endpoint_name }
364+ )
365+ if endpoint_name_prefix :
340366 if re .search ("^[a-zA-Z0-9](-*[a-zA-Z0-9])" , endpoint_name_prefix ) is None :
341367 raise ValueError (
342368 "Invalid endpoint_name_prefix."
0 commit comments