@@ -276,26 +276,33 @@ class ModelConfig:
276276
277277 def __init__ (
278278 self ,
279- model_name ,
280- instance_count ,
281- instance_type ,
282- accept_type = None ,
283- content_type = None ,
284- content_template = None ,
285- custom_attributes = None ,
286- accelerator_type = None ,
287- endpoint_name_prefix = None ,
288- target_model = None ,
279+ model_name : str = None ,
280+ instance_count : int = None ,
281+ instance_type : str = None ,
282+ accept_type : str = None ,
283+ content_type : str = None ,
284+ content_template : str = None ,
285+ custom_attributes : str = None ,
286+ accelerator_type : str = None ,
287+ endpoint_name_prefix : str = None ,
288+ target_model : str = None ,
289+ endpoint_name : str = None ,
289290 ):
290291 r"""Initializes a configuration of a model and the endpoint to be created for it.
291292
292293 Args:
293294 model_name (str): Model name (as created by
294295 `CreateModel <https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateModel.html>`_.
296+ Cannot be set when ``endpoint_name`` is set.
297+ Must be set with ``instance_count``, ``instance_type``
295298 instance_count (int): The number of instances of a new endpoint for model inference.
299+ Cannot be set when ``endpoint_name`` is set.
300+ Must be set with ``model_name``, ``instance_type``
296301 instance_type (str): The type of
297302 `EC2 instance <https://aws.amazon.com/ec2/instance-types/>`_
298303 to use for model inference; for example, ``"ml.c5.xlarge"``.
304+ Cannot be set when ``endpoint_name`` is set.
305+ Must be set with ``instance_count``, ``model_name``
299306 accept_type (str): The model output format to be used for getting inferences with the
300307 shadow endpoint. Valid values are ``"text/csv"`` for CSV and
301308 ``"application/jsonlines"``. Default is the same as ``content_type``.
@@ -325,17 +332,41 @@ def __init__(
325332 target_model (str): Sets the target model name when using a multi-model endpoint. For
326333 more information about multi-model endpoints, see
327334 https://docs.aws.amazon.com/sagemaker/latest/dg/multi-model-endpoints.html
335+ endpoint_name (str): Sets the endpoint_name when re-uses an existing endpoint.
336+ Cannot be set when ``model_name``, ``instance_count``,
337+ and ``instance_type`` set
328338
329339 Raises:
330- ValueError: when the ``endpoint_name_prefix`` is invalid, ``accept_type`` is invalid,
331- ``content_type`` is invalid, or ``content_template`` has no placeholder "features"
340+ ValueError: when the
341+ - ``endpoint_name_prefix`` is invalid,
342+ - ``accept_type`` is invalid,
343+ - ``content_type`` is invalid,
344+ - ``content_template`` has no placeholder "features"
345+ - both [``endpoint_name``]
346+ AND [``model_name``, ``instance_count``, ``instance_type``] are set
347+ - both [``endpoint_name``] AND [``endpoint_name_prefix``] are set
332348 """
333- self .predictor_config = {
334- "model_name" : model_name ,
335- "instance_type" : instance_type ,
336- "initial_instance_count" : instance_count ,
337- }
338- if endpoint_name_prefix is not None :
349+
350+ # validation
351+ _model_endpoint_config_rule = (
352+ all ([model_name , instance_count , instance_type ]),
353+ all ([endpoint_name ]),
354+ )
355+ assert any (_model_endpoint_config_rule ) and not all (_model_endpoint_config_rule )
356+ if endpoint_name :
357+ assert not endpoint_name_prefix
358+
359+ # main init logic
360+ self .predictor_config = (
361+ {
362+ "model_name" : model_name ,
363+ "instance_type" : instance_type ,
364+ "initial_instance_count" : instance_count ,
365+ }
366+ if not endpoint_name
367+ else {"endpoint_name" : endpoint_name }
368+ )
369+ if endpoint_name_prefix :
339370 if re .search ("^[a-zA-Z0-9](-*[a-zA-Z0-9])" , endpoint_name_prefix ) is None :
340371 raise ValueError (
341372 "Invalid endpoint_name_prefix."
0 commit comments