@@ -272,26 +272,30 @@ class ModelConfig:
272272
273273 def __init__ (
274274 self ,
275- model_name ,
276- instance_count ,
277- instance_type ,
278- accept_type = None ,
279- content_type = None ,
280- content_template = None ,
281- custom_attributes = None ,
282- accelerator_type = None ,
283- endpoint_name_prefix = None ,
284- target_model = None ,
275+ model_name : str = None ,
276+ instance_count : int = None ,
277+ instance_type : str = None ,
278+ accept_type : str = None ,
279+ content_type : str = None ,
280+ content_template : str = None ,
281+ custom_attributes : str = None ,
282+ accelerator_type : str = None ,
283+ endpoint_name_prefix : str = None ,
284+ target_model : str = None ,
285+ endpoint_name : str = None ,
285286 ):
286287 r"""Initializes a configuration of a model and the endpoint to be created for it.
287288
288289 Args:
289290 model_name (str): Model name (as created by
290291 `CreateModel <https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateModel.html>`_.
292+ Cannot be set when endpoint_name is set. Must be set with `instance_count`, `instance_type`
291293 instance_count (int): The number of instances of a new endpoint for model inference.
294+ Cannot be set when endpoint_name is set. Must be set with `model_name`, `instance_type`
292295 instance_type (str): The type of
293296 `EC2 instance <https://aws.amazon.com/ec2/instance-types/>`_
294297 to use for model inference; for example, ``"ml.c5.xlarge"``.
298+ Cannot be set when endpoint_name is set. Must be set with `instance_count`, `model_name`
295299 accept_type (str): The model output format to be used for getting inferences with the
296300 shadow endpoint. Valid values are ``"text/csv"`` for CSV and
297301 ``"application/jsonlines"``. Default is the same as ``content_type``.
@@ -321,17 +325,39 @@ def __init__(
321325 target_model (str): Sets the target model name when using a multi-model endpoint. For
322326 more information about multi-model endpoints, see
323327 https://docs.aws.amazon.com/sagemaker/latest/dg/multi-model-endpoints.html
328+ endpoint_name (str): Sets the endpoint_name when re-uses an existing endpoint. Cannot be set
329+ when `model_name`, `instance_count`, and `instance_type` set
324330
325331 Raises:
326- ValueError: when the ``endpoint_name_prefix`` is invalid, ``accept_type`` is invalid,
327- ``content_type`` is invalid, or ``content_template`` has no placeholder "features"
332+ ValueError: when the
333+ - ``endpoint_name_prefix`` is invalid,
334+ - ``accept_type`` is invalid,
335+ - ``content_type`` is invalid,
336+ - ``content_template`` has no placeholder "features"
337+ - both [``endpoint_name``] AND [``model_name``, ``instance_count``, ``instance_type``] are set
338+ - both [``endpoint_name``] AND [``endpoint_name_prefix``] are set
328339 """
329- self .predictor_config = {
330- "model_name" : model_name ,
331- "instance_type" : instance_type ,
332- "initial_instance_count" : instance_count ,
333- }
334- if endpoint_name_prefix is not None :
340+
341+ # validation
342+ _model_endpoint_config_rule = (
343+ all ([model_name , instance_count , instance_type ]),
344+ all ([endpoint_name ]),
345+ )
346+ assert any (_model_endpoint_config_rule ) and not all (_model_endpoint_config_rule )
347+ if endpoint_name :
348+ assert not endpoint_name_prefix
349+
350+ # main init logic
351+ self .predictor_config = (
352+ {
353+ "model_name" : model_name ,
354+ "instance_type" : instance_type ,
355+ "initial_instance_count" : instance_count ,
356+ }
357+ if not endpoint_name
358+ else {"endpoint_name" : endpoint_name }
359+ )
360+ if endpoint_name_prefix :
335361 if re .search ("^[a-zA-Z0-9](-*[a-zA-Z0-9])" , endpoint_name_prefix ) is None :
336362 raise ValueError (
337363 "Invalid endpoint_name_prefix."
0 commit comments