@@ -272,26 +272,30 @@ class ModelConfig:
272
272
273
273
def __init__ (
274
274
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 ,
285
286
):
286
287
r"""Initializes a configuration of a model and the endpoint to be created for it.
287
288
288
289
Args:
289
290
model_name (str): Model name (as created by
290
291
`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`
291
293
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`
292
295
instance_type (str): The type of
293
296
`EC2 instance <https://aws.amazon.com/ec2/instance-types/>`_
294
297
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`
295
299
accept_type (str): The model output format to be used for getting inferences with the
296
300
shadow endpoint. Valid values are ``"text/csv"`` for CSV and
297
301
``"application/jsonlines"``. Default is the same as ``content_type``.
@@ -321,17 +325,39 @@ def __init__(
321
325
target_model (str): Sets the target model name when using a multi-model endpoint. For
322
326
more information about multi-model endpoints, see
323
327
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
324
330
325
331
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
328
339
"""
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 :
335
361
if re .search ("^[a-zA-Z0-9](-*[a-zA-Z0-9])" , endpoint_name_prefix ) is None :
336
362
raise ValueError (
337
363
"Invalid endpoint_name_prefix."
0 commit comments