1
1
import json
2
2
import os
3
+ import re
3
4
4
5
import numpy as np
5
6
import pytest
11
12
from sagemaker .model import Model
12
13
13
14
14
- ROLE_NAME = "sagemaker_execution_role"
15
- PROFILE = "hf-sm"
16
- REGION = "us-east-1"
17
- os .environ ["AWS_PROFILE" ] = PROFILE # setting aws profile for our boto3 client
18
- os .environ ["AWS_DEFAULT_REGION" ] = REGION # current DLCs are only in us-east-1 available
15
+ os .environ ["AWS_DEFAULT_REGION" ] = os .environ .get ("AWS_DEFAULT_REGION" , "us-east-1" )
16
+ SAGEMAKER_EXECUTION_ROLE = os .environ .get ("SAGEMAKER_EXECUTION_ROLE" , "sagemaker_execution_role" )
19
17
20
- # TODO: Replace with released DLC images
21
- images = {
22
- "pytorch" : {
23
- "cpu" : "558105141721.dkr.ecr.us-east-1.amazonaws.com/huggingface-inference-pytorch:cpu-0.0.1" ,
24
- "gpu" : "558105141721.dkr.ecr.us-east-1.amazonaws.com/huggingface-inference-pytorch:gpu-0.0.1" ,
25
- },
26
- "tensorflow" : {
27
- "cpu" : "558105141721.dkr.ecr.us-east-1.amazonaws.com/huggingface-inference-tensorflow:cpu-0.0.1" ,
28
- "gpu" : "558105141721.dkr.ecr.us-east-1.amazonaws.com/huggingface-inference-tensorflow:gpu-0.0.1" ,
29
- },
30
- }
18
+
19
+ def get_framework_ecr_image (registry_id = "763104351884" , repository_name = "huggingface-pytorch-inference" , device = "cpu" ):
20
+ client = boto3 .client ("ecr" )
21
+
22
+ def get_all_ecr_images (registry_id , repository_name , result_key ):
23
+ response = client .list_images (
24
+ registryId = registry_id ,
25
+ repositoryName = repository_name ,
26
+ )
27
+ results = response [result_key ]
28
+ while "nextToken" in response :
29
+ response = client .list_images (
30
+ registryId = registry_id ,
31
+ nextToken = response ["nextToken" ],
32
+ repositoryName = repository_name ,
33
+ )
34
+ results .extend (response [result_key ])
35
+ return results
36
+
37
+ images = get_all_ecr_images (registry_id = registry_id , repository_name = repository_name , result_key = "imageIds" )
38
+ image_tags = [image ["imageTag" ] for image in images ]
39
+ print (image_tags )
40
+ image_regex = re .compile ("\d\.\d\.\d-" + device + "-.{4}$" )
41
+ image = sorted (list (filter (image_regex .match , image_tags )), reverse = True )[0 ]
42
+ return image
31
43
32
44
33
45
@pytest .mark .parametrize (
47
59
)
48
60
@pytest .mark .parametrize (
49
61
"framework" ,
50
- [
51
- "pytorch" ,
52
- ],
53
- ) # "tensorflow"])
62
+ ["pytorch" , "tensorflow" ],
63
+ )
54
64
@pytest .mark .parametrize (
55
65
"device" ,
56
66
[
57
- # "gpu",
67
+ "gpu" ,
58
68
"cpu" ,
59
69
],
60
70
)
61
71
def test_deployment_from_hub (task , device , framework ):
62
- image_uri = images [ framework ][ device ]
72
+ image_uri = get_framework_ecr_image ( repository_name = f"huggingface- { framework } -inference" , device = device )
63
73
name = f"hf-test-{ framework } -{ device } -{ task } " .replace ("_" , "-" )
64
74
model = task2model [task ][framework ]
65
75
instance_type = "ml.m5.large" if device == "cpu" else "ml.g4dn.xlarge"
@@ -76,7 +86,7 @@ def test_deployment_from_hub(task, device, framework):
76
86
image_uri = image_uri , # A Docker image URI.
77
87
model_data = None , # The S3 location of a SageMaker model data .tar.gz
78
88
env = env , # Environment variables to run with image_uri when hosted in SageMaker (default: None).
79
- role = ROLE_NAME , # An AWS IAM role (either name or full ARN).
89
+ role = SAGEMAKER_EXECUTION_ROLE , # An AWS IAM role (either name or full ARN).
80
90
name = name , # The model name
81
91
sagemaker_session = sagemaker_session ,
82
92
)
@@ -127,6 +137,7 @@ def test_deployment_from_hub(task, device, framework):
127
137
"p95_request_time" : np .percentile (time_buffer , 95 ),
128
138
"body" : json .loads (response_body ),
129
139
}
140
+ print (data )
130
141
json .dump (data , outfile )
131
142
132
143
assert task2performance [task ][device ]["average_request_time" ] >= np .mean (time_buffer )
0 commit comments