@@ -35,6 +35,8 @@ def __call__(self, create_request: CreateModelRequest) -> CreateModelResponse:
35
35
if table_item :
36
36
raise ModelAlreadyExistsError (f"Model '{ model_id } ' already exists. Please select another name." )
37
37
38
+ self .validate (create_request )
39
+
38
40
self ._stepfunctions .start_execution (
39
41
stateMachineArn = os .environ ["CREATE_SFN_ARN" ], input = create_request .model_dump_json ()
40
42
)
@@ -46,3 +48,37 @@ def __call__(self, create_request: CreateModelRequest) -> CreateModelResponse:
46
48
}
47
49
)
48
50
return CreateModelResponse (model = lisa_model )
51
+
52
+ @staticmethod
53
+ def validate (create_request : CreateModelRequest ) -> None :
54
+ # The below check ensures that the model is LISA hosted
55
+ if (
56
+ create_request .containerConfig is not None
57
+ and create_request .autoScalingConfig is not None
58
+ and create_request .loadBalancerConfig is not None
59
+ ):
60
+ if create_request .containerConfig .image .baseImage is None :
61
+ raise ValueError ("Base image must be provided for LISA hosted model." )
62
+
63
+ # Validate values relative to current ASG. All conflicting request values have been validated as part of the
64
+ # AutoScalingInstanceConfig model validations, so those are not duplicated here.
65
+ if create_request .autoScalingConfig is not None :
66
+ # Min capacity can't be greater than the deployed ASG's max capacity
67
+ if (
68
+ create_request .autoScalingConfig .minCapacity is not None
69
+ and create_request .autoScalingConfig .maxCapacity is not None
70
+ and create_request .autoScalingConfig .minCapacity > create_request .autoScalingConfig .maxCapacity
71
+ ):
72
+ raise ValueError (
73
+ f"Min capacity cannot exceed ASG max of { create_request .autoScalingConfig .maxCapacity } ."
74
+ )
75
+
76
+ # Max capacity can't be less than the deployed ASG's min capacity
77
+ if (
78
+ create_request .autoScalingConfig .maxCapacity is not None
79
+ and create_request .autoScalingConfig .minCapacity is not None
80
+ and create_request .autoScalingConfig .maxCapacity < create_request .autoScalingConfig .minCapacity
81
+ ):
82
+ raise ValueError (
83
+ f"Max capacity cannot be less than ASG min of { create_request .autoScalingConfig .minCapacity } ."
84
+ )
0 commit comments