@@ -276,26 +276,33 @@ class ModelConfig:
276
276
277
277
def __init__ (
278
278
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 ,
289
290
):
290
291
r"""Initializes a configuration of a model and the endpoint to be created for it.
291
292
292
293
Args:
293
294
model_name (str): Model name (as created by
294
295
`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``
295
298
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``
296
301
instance_type (str): The type of
297
302
`EC2 instance <https://aws.amazon.com/ec2/instance-types/>`_
298
303
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``
299
306
accept_type (str): The model output format to be used for getting inferences with the
300
307
shadow endpoint. Valid values are ``"text/csv"`` for CSV and
301
308
``"application/jsonlines"``. Default is the same as ``content_type``.
@@ -325,17 +332,41 @@ def __init__(
325
332
target_model (str): Sets the target model name when using a multi-model endpoint. For
326
333
more information about multi-model endpoints, see
327
334
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
328
338
329
339
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
332
348
"""
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 :
339
370
if re .search ("^[a-zA-Z0-9](-*[a-zA-Z0-9])" , endpoint_name_prefix ) is None :
340
371
raise ValueError (
341
372
"Invalid endpoint_name_prefix."
0 commit comments