15
15
import os
16
16
from typing import Dict , List , Optional
17
17
from sagemaker import image_uris
18
+ from sagemaker .jumpstart .exceptions import NO_AVAILABLE_INSTANCES_ERROR_MSG
18
19
from sagemaker .jumpstart .constants import (
19
20
ENV_VARIABLE_JUMPSTART_MODEL_ARTIFACT_BUCKET_OVERRIDE ,
20
21
ENV_VARIABLE_JUMPSTART_SCRIPT_ARTIFACT_BUCKET_OVERRIDE ,
@@ -408,7 +409,7 @@ def _retrieve_default_instance_type(
408
409
region : Optional [str ] = None ,
409
410
tolerate_vulnerable_model : bool = False ,
410
411
tolerate_deprecated_model : bool = False ,
411
- ) -> Optional [ str ] :
412
+ ) -> str :
412
413
"""Retrieves the default instance type for the model.
413
414
414
415
Args:
@@ -428,7 +429,11 @@ def _retrieve_default_instance_type(
428
429
specifications should be tolerated (exception not raised). If False, raises
429
430
an exception if the version of the model is deprecated. (Default: False).
430
431
Returns:
431
- list: the default instance type to use for the model or None.
432
+ str: the default instance type to use for the model or None.
433
+
434
+ Raises:
435
+ ValueError: If the model is not available in the
436
+ specified region due to lack of supported computing instances.
432
437
"""
433
438
434
439
if region is None :
@@ -444,12 +449,17 @@ def _retrieve_default_instance_type(
444
449
)
445
450
446
451
if scope == JumpStartScriptScope .INFERENCE :
447
- return model_specs .default_inference_instance_type
448
- if scope == JumpStartScriptScope .TRAINING :
449
- return model_specs .default_training_instance_type
450
- raise NotImplementedError (
451
- f"Unsupported script scope for retrieving default instance type: '{ scope } '"
452
- )
452
+ default_instance_type = model_specs .default_inference_instance_type
453
+ elif scope == JumpStartScriptScope .TRAINING :
454
+ default_instance_type = model_specs .default_training_instance_type
455
+ else :
456
+ raise NotImplementedError (
457
+ f"Unsupported script scope for retrieving default instance type: '{ scope } '"
458
+ )
459
+
460
+ if default_instance_type in {None , "" }:
461
+ raise ValueError (NO_AVAILABLE_INSTANCES_ERROR_MSG .format (model_id = model_id , region = region ))
462
+ return default_instance_type
453
463
454
464
455
465
def _retrieve_supported_instance_type (
@@ -459,7 +469,7 @@ def _retrieve_supported_instance_type(
459
469
region : Optional [str ] = None ,
460
470
tolerate_vulnerable_model : bool = False ,
461
471
tolerate_deprecated_model : bool = False ,
462
- ) -> Optional [ List [str ] ]:
472
+ ) -> List [str ]:
463
473
"""Retrieves the supported instance types for the model.
464
474
465
475
Args:
@@ -480,6 +490,10 @@ def _retrieve_supported_instance_type(
480
490
an exception if the version of the model is deprecated. (Default: False).
481
491
Returns:
482
492
list: the supported instance types to use for the model or None.
493
+
494
+ Raises:
495
+ ValueError: If the model is not available in the
496
+ specified region due to lack of supported computing instances.
483
497
"""
484
498
485
499
if region is None :
@@ -495,9 +509,15 @@ def _retrieve_supported_instance_type(
495
509
)
496
510
497
511
if scope == JumpStartScriptScope .INFERENCE :
498
- return model_specs .supported_inference_instance_types
499
- if scope == JumpStartScriptScope .TRAINING :
500
- return model_specs .supported_training_instance_types
501
- raise NotImplementedError (
502
- f"Unsupported script scope for retrieving supported instance types: '{ scope } '"
503
- )
512
+ instance_types = model_specs .supported_inference_instance_types
513
+ elif scope == JumpStartScriptScope .TRAINING :
514
+ instance_types = model_specs .supported_training_instance_types
515
+ else :
516
+ raise NotImplementedError (
517
+ f"Unsupported script scope for retrieving supported instance types: '{ scope } '"
518
+ )
519
+
520
+ if instance_types is None or len (instance_types ) == 0 :
521
+ raise ValueError (NO_AVAILABLE_INSTANCES_ERROR_MSG .format (model_id = model_id , region = region ))
522
+
523
+ return instance_types
0 commit comments