-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathtest_huggingface_llm.py
155 lines (139 loc) · 6.83 KB
/
test_huggingface_llm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from __future__ import absolute_import
import pytest
from packaging.version import parse
from sagemaker.huggingface import get_huggingface_llm_image_uri
from tests.unit.sagemaker.image_uris import expected_uris, conftest
LMI_VERSIONS = ["0.24.0"]
TEI_VERSIONS_MAPPING = {
"gpu": {
"1.2.3": "2.0.1-tei1.2.3-gpu-py310-cu122-ubuntu22.04",
"1.4.0": "2.0.1-tei1.4.0-gpu-py310-cu122-ubuntu22.04",
"1.6.0": "2.0.1-tei1.6.0-gpu-py310-cu122-ubuntu22.04",
},
"cpu": {
"1.2.3": "2.0.1-tei1.2.3-cpu-py310-ubuntu22.04",
"1.4.0": "2.0.1-tei1.4.0-cpu-py310-ubuntu22.04",
"1.6.0": "2.0.1-tei1.6.0-cpu-py310-ubuntu22.04",
},
}
HF_VERSIONS_MAPPING = {
"gpu": {
"0.6.0": "2.0.0-tgi0.6.0-gpu-py39-cu118-ubuntu20.04",
"0.8.2": "2.0.0-tgi0.8.2-gpu-py39-cu118-ubuntu20.04",
"0.9.3": "2.0.1-tgi0.9.3-gpu-py39-cu118-ubuntu20.04",
"1.0.3": "2.0.1-tgi1.0.3-gpu-py39-cu118-ubuntu20.04",
"1.1.0": "2.0.1-tgi1.1.0-gpu-py39-cu118-ubuntu20.04",
"1.2.0": "2.1.1-tgi1.2.0-gpu-py310-cu121-ubuntu20.04",
"1.3.1": "2.1.1-tgi1.3.1-gpu-py310-cu121-ubuntu20.04",
"1.3.3": "2.1.1-tgi1.3.3-gpu-py310-cu121-ubuntu20.04",
"1.4.0": "2.1.1-tgi1.4.0-gpu-py310-cu121-ubuntu20.04",
"1.4.2": "2.1.1-tgi1.4.2-gpu-py310-cu121-ubuntu22.04",
"1.4.5": "2.1.1-tgi1.4.5-gpu-py310-cu121-ubuntu22.04",
"2.0.0": "2.1.1-tgi2.0.0-gpu-py310-cu121-ubuntu22.04",
"2.0.1": "2.1.1-tgi2.0.1-gpu-py310-cu121-ubuntu22.04",
"2.0.2": "2.3.0-tgi2.0.2-gpu-py310-cu121-ubuntu22.04",
"2.2.0": "2.3.0-tgi2.2.0-gpu-py310-cu121-ubuntu22.04-v2.0",
"2.3.1": "2.4.0-tgi2.3.1-gpu-py311-cu124-ubuntu22.04",
"2.4.0": "2.4.0-tgi2.4.0-gpu-py311-cu124-ubuntu22.04-v2.2",
"3.0.1": "2.4.0-tgi3.0.1-gpu-py311-cu124-ubuntu22.04-v2.1",
},
"inf2": {
"0.0.16": "1.13.1-optimum0.0.16-neuronx-py310-ubuntu22.04",
"0.0.17": "1.13.1-optimum0.0.17-neuronx-py310-ubuntu22.04",
"0.0.18": "1.13.1-optimum0.0.18-neuronx-py310-ubuntu22.04",
"0.0.19": "1.13.1-optimum0.0.19-neuronx-py310-ubuntu22.04",
"0.0.20": "1.13.1-optimum0.0.20-neuronx-py310-ubuntu22.04",
"0.0.21": "1.13.1-optimum0.0.21-neuronx-py310-ubuntu22.04",
"0.0.22": "2.1.2-optimum0.0.22-neuronx-py310-ubuntu22.04",
"0.0.23": "2.1.2-optimum0.0.23-neuronx-py310-ubuntu22.04",
"0.0.24": "2.1.2-optimum0.0.24-neuronx-py310-ubuntu22.04",
"0.0.25": "2.1.2-optimum0.0.25-neuronx-py310-ubuntu22.04",
"0.0.27": "2.1.2-optimum0.0.27-neuronx-py310-ubuntu22.04",
},
}
@pytest.mark.parametrize(
"load_config", ["huggingface-llm.json", "huggingface-llm-neuronx.json"], indirect=True
)
def test_huggingface_uris(load_config):
VERSIONS = load_config["inference"]["versions"]
device = load_config["inference"]["processors"][0]
backend = "huggingface-neuronx" if device == "inf2" else "huggingface"
# Fail if device is not in mapping
if device not in HF_VERSIONS_MAPPING:
raise ValueError(f"Device {device} not found in HF_VERSIONS_MAPPING")
# Get highest version for the device
highest_version = max(HF_VERSIONS_MAPPING[device].keys(), key=lambda x: parse(x))
for version in VERSIONS:
ACCOUNTS = load_config["inference"]["versions"][version]["registries"]
for region in ACCOUNTS.keys():
uri = get_huggingface_llm_image_uri(backend, region=region, version=version)
# Skip only if test version is higher than highest known version.
# There's now automation to add new TGI releases to image_uri_config directory
# that doesn't involve a human raising a PR.
if parse(version) > parse(highest_version):
print(
f"Skipping version check for {version} as there is "
"automation that now updates the image_uri_config "
"without a human raising a PR. Tests will pass for "
f"versions higher than {highest_version} that are not in HF_VERSIONS_MAPPING."
)
continue
expected = expected_uris.huggingface_llm_framework_uri(
"huggingface-pytorch-tgi-inference",
ACCOUNTS[region],
version,
HF_VERSIONS_MAPPING[device][version],
region=region,
)
assert expected == uri
@pytest.mark.parametrize(
"load_config", ["huggingface-tei.json", "huggingface-tei-cpu.json"], indirect=True
)
def test_huggingface_tei_uris(load_config):
VERSIONS = load_config["inference"]["versions"]
device = load_config["inference"]["processors"][0]
backend = "huggingface-tei" if device == "gpu" else "huggingface-tei-cpu"
repo = "tei" if device == "gpu" else "tei-cpu"
for version in VERSIONS:
ACCOUNTS = load_config["inference"]["versions"][version]["registries"]
for region in ACCOUNTS.keys():
uri = get_huggingface_llm_image_uri(backend, region=region, version=version)
expected = expected_uris.huggingface_llm_framework_uri(
repo,
ACCOUNTS[region],
version,
TEI_VERSIONS_MAPPING[device][version],
region=region,
)
assert expected == uri
@pytest.mark.parametrize("load_config", ["huggingface-llm.json"], indirect=True)
def test_lmi_uris(load_config):
VERSIONS = load_config["inference"]["versions"]
for version in VERSIONS:
ACCOUNTS = load_config["inference"]["versions"][version]["registries"]
for region in ACCOUNTS.keys():
for lmi_version in LMI_VERSIONS:
djl_deepspeed_config = conftest.get_config("djl-deepspeed.json")
DJL_DEEPSPEED_REGIONS = djl_deepspeed_config["versions"][lmi_version][
"registries"
].keys()
if region not in DJL_DEEPSPEED_REGIONS:
continue
uri = get_huggingface_llm_image_uri("lmi", region=region, version=lmi_version)
tag = djl_deepspeed_config["versions"][lmi_version]["tag_prefix"]
expected = expected_uris.djl_framework_uri(
"djl-inference", ACCOUNTS[region], tag, region=region
)
assert expected == uri