Skip to content

Commit b4e1c41

Browse files
committed
adding tests
1 parent f95d374 commit b4e1c41

10 files changed

+168
-196
lines changed

dockerfiles/pytorch/Dockerfile.inf2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ RUN pip install --extra-index-url https://pip.repos.neuron.amazonaws.com --no-ca
110110

111111
COPY . .
112112
# install wheel and setuptools
113-
RUN pip install --no-cache-dir -U pip "."
113+
RUN pip install --no-cache-dir -U pip ".[st]"
114114

115115
# copy application
116116
COPY src/huggingface_inference_toolkit huggingface_inference_toolkit

tests/integ/config.py

Lines changed: 91 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"pytorch": "hf-internal-testing/tiny-random-bert",
3232
"tensorflow": "hf-internal-testing/tiny-random-bert",
3333
},
34-
"ner": {
34+
"token-classification": {
3535
"pytorch": "hf-internal-testing/tiny-random-roberta",
3636
"tensorflow": "hf-internal-testing/tiny-random-roberta",
3737
},
@@ -80,7 +80,7 @@
8080
"tensorflow": "hf-internal-testing/tiny-random-clip-zero-shot-image-classification",
8181
},
8282
"conversational": {
83-
#"pytorch": "hf-internal-testing/tiny-random-blenderbot-small",
83+
# "pytorch": "hf-internal-testing/tiny-random-blenderbot-small",
8484
"pytorch": "microsoft/DialoGPT-small",
8585
"tensorflow": None,
8686
},
@@ -118,7 +118,7 @@
118118
"parameters": {"candidate_labels": ["refund", "legal", "faq"]},
119119
},
120120
"feature-extraction": {"inputs": "What is the best book."},
121-
"ner": {"inputs": "My name is Wolfgang and I live in Berlin"},
121+
"token-classification": {"inputs": "My name is Wolfgang and I live in Berlin"},
122122
"question-answering": {
123123
"inputs": {
124124
"question": "What is used for inference?",
@@ -134,12 +134,24 @@
134134
"inputs": "question: What is 42 context: 42 is the answer to life, the universe and everything."
135135
},
136136
"text-generation": {"inputs": "My name is philipp and I am"},
137-
"image-classification": open(os.path.join(os.getcwd(), "tests/resources/image/tiger.jpeg"), "rb").read(),
138-
"zero-shot-image-classification": open(os.path.join(os.getcwd(), "tests/resources/image/tiger.jpeg"), "rb").read(),
139-
"object-detection": open(os.path.join(os.getcwd(), "tests/resources/image/tiger.jpeg"), "rb").read(),
140-
"image-segmentation": open(os.path.join(os.getcwd(), "tests/resources/image/tiger.jpeg"), "rb").read(),
141-
"automatic-speech-recognition": open(os.path.join(os.getcwd(), "tests/resources/audio/sample1.flac"), "rb").read(),
142-
"audio-classification": open(os.path.join(os.getcwd(), "tests/resources/audio/sample1.flac"), "rb").read(),
137+
"image-classification": open(
138+
os.path.join(os.getcwd(), "tests/resources/image/tiger.jpeg"), "rb"
139+
).read(),
140+
"zero-shot-image-classification": open(
141+
os.path.join(os.getcwd(), "tests/resources/image/tiger.jpeg"), "rb"
142+
).read(),
143+
"object-detection": open(
144+
os.path.join(os.getcwd(), "tests/resources/image/tiger.jpeg"), "rb"
145+
).read(),
146+
"image-segmentation": open(
147+
os.path.join(os.getcwd(), "tests/resources/image/tiger.jpeg"), "rb"
148+
).read(),
149+
"automatic-speech-recognition": open(
150+
os.path.join(os.getcwd(), "tests/resources/audio/sample1.flac"), "rb"
151+
).read(),
152+
"audio-classification": open(
153+
os.path.join(os.getcwd(), "tests/resources/audio/sample1.flac"), "rb"
154+
).read(),
143155
"table-question-answering": {
144156
"inputs": {
145157
"query": "How many stars does the transformers repository have?",
@@ -151,27 +163,25 @@
151163
},
152164
}
153165
},
154-
"conversational": {"inputs": [
155-
{
156-
"role": "user",
157-
"content": "Which movie is the best ?"
158-
},
159-
{
160-
"role": "assistant",
161-
"content": "It's Die Hard for sure."
162-
},
163-
{
164-
"role": "user",
165-
"content": "Can you explain why?"
166-
}
167-
]},
166+
"conversational": {
167+
"inputs": [
168+
{"role": "user", "content": "Which movie is the best ?"},
169+
{"role": "assistant", "content": "It's Die Hard for sure."},
170+
{"role": "user", "content": "Can you explain why?"},
171+
]
172+
},
168173
"sentence-similarity": {
169-
"inputs": {"source_sentence": "Lets create an embedding", "sentences": ["Lets create an embedding"]}
174+
"inputs": {
175+
"source_sentence": "Lets create an embedding",
176+
"sentences": ["Lets create an embedding"],
177+
}
170178
},
171179
"sentence-embeddings": {"inputs": "Lets create an embedding"},
172-
"sentence-ranking": {"inputs": ["Lets create an embedding", "Lets create an embedding"]},
180+
"sentence-ranking": {
181+
"inputs": ["Lets create an embedding", "Lets create an embedding"]
182+
},
173183
"text-to-image": {"inputs": "a man on a horse jumps over a broken down airplane."},
174-
"custom": {"inputs": "this is a test"}
184+
"custom": {"inputs": "this is a test"},
175185
}
176186

177187
task2output = {
@@ -181,30 +191,67 @@
181191
"labels": ["refund", "faq", "legal"],
182192
"scores": [0.96, 0.027, 0.008],
183193
},
184-
"ner": [
185-
{"word": "Wolfgang", "score": 0.99, "entity": "I-PER", "index": 4, "start": 11, "end": 19},
186-
{"word": "Berlin", "score": 0.99, "entity": "I-LOC", "index": 9, "start": 34, "end": 40},
194+
"token-classification": [
195+
{
196+
"word": "Wolfgang",
197+
"score": 0.99,
198+
"entity": "I-PER",
199+
"index": 4,
200+
"start": 11,
201+
"end": 19,
202+
},
203+
{
204+
"word": "Berlin",
205+
"score": 0.99,
206+
"entity": "I-LOC",
207+
"index": 9,
208+
"start": 34,
209+
"end": 40,
210+
},
211+
],
212+
"question-answering": {
213+
"score": 0.99,
214+
"start": 68,
215+
"end": 77,
216+
"answer": "sagemaker",
217+
},
218+
"summarization": [
219+
{"summary_text": " The A The The ANew York City has been installed in the US."}
220+
],
221+
"translation_xx_to_yy": [
222+
{"translation_text": "Mein Name ist Sarah und ich lebe in London"}
223+
],
224+
"text2text-generation": [
225+
{"generated_text": "42 is the answer to life, the universe and everything"}
187226
],
188-
"question-answering": {"score": 0.99, "start": 68, "end": 77, "answer": "sagemaker"},
189-
"summarization": [{"summary_text": " The A The The ANew York City has been installed in the US."}],
190-
"translation_xx_to_yy": [{"translation_text": "Mein Name ist Sarah und ich lebe in London"}],
191-
"text2text-generation": [{"generated_text": "42 is the answer to life, the universe and everything"}],
192227
"feature-extraction": None,
193228
"fill-mask": None,
194229
"text-generation": None,
195230
"image-classification": [
196231
{"score": 0.8858247399330139, "label": "tiger, Panthera tigris"},
197232
{"score": 0.10940514504909515, "label": "tiger cat"},
198-
{"score": 0.0006216464680619538, "label": "jaguar, panther, Panthera onca, Felis onca"},
233+
{
234+
"score": 0.0006216464680619538,
235+
"label": "jaguar, panther, Panthera onca, Felis onca",
236+
},
199237
{"score": 0.0004262699221726507, "label": "dhole, Cuon alpinus"},
200-
{"score": 0.00030842673731967807, "label": "lion, king of beasts, Panthera leo"},
238+
{
239+
"score": 0.00030842673731967807,
240+
"label": "lion, king of beasts, Panthera leo",
241+
},
201242
],
202243
"zero-shot-image-classification": [
203244
{"score": 0.8858247399330139, "label": "tiger, Panthera tigris"},
204245
{"score": 0.10940514504909515, "label": "tiger cat"},
205-
{"score": 0.0006216464680619538, "label": "jaguar, panther, Panthera onca, Felis onca"},
246+
{
247+
"score": 0.0006216464680619538,
248+
"label": "jaguar, panther, Panthera onca, Felis onca",
249+
},
206250
{"score": 0.0004262699221726507, "label": "dhole, Cuon alpinus"},
207-
{"score": 0.00030842673731967807, "label": "lion, king of beasts, Panthera leo"},
251+
{
252+
"score": 0.00030842673731967807,
253+
"label": "lion, king of beasts, Panthera leo",
254+
},
208255
],
209256
"automatic-speech-recognition": {
210257
"text": "GOING ALONG SLUSHY COUNTRY ROADS AND SPEAKING TO DAMP OAUDIENCES IN DROFTY SCHOOL ROOMS DAY AFTER DAY FOR A FORT NIGHT HE'LL HAVE TO PUT IN AN APPEARANCE AT SOME PLACE OF WORSHIP ON SUNDAY MORNING AND HE CAN COME TO US IMMEDIATELY AFTERWARDS"
@@ -217,16 +264,16 @@
217264
"image-segmentation": [{"score": 0.9143241047859192, "label": "cat", "mask": {}}],
218265
"table-question-answering": {"answer": "36542"},
219266
"conversational": [
220-
{'role': 'user', 'content': 'Which movie is the best ?'},
221-
{'role': 'assistant', 'content': "It's Die Hard for sure."},
222-
{'role': 'user', 'content': 'Can you explain why?'},
223-
{'role': 'assistant', 'content': "It's a great movie."},
267+
{"role": "user", "content": "Which movie is the best ?"},
268+
{"role": "assistant", "content": "It's Die Hard for sure."},
269+
{"role": "user", "content": "Can you explain why?"},
270+
{"role": "assistant", "content": "It's a great movie."},
224271
],
225272
"sentence-similarity": {"similarities": ""},
226273
"sentence-embeddings": {"embeddings": ""},
227274
"sentence-ranking": {"scores": ""},
228275
"text-to-image": bytes,
229-
"custom": {"inputs": "this is a test"}
276+
"custom": {"inputs": "this is a test"},
230277
}
231278

232279

@@ -235,7 +282,7 @@
235282
"zero-shot-classification": validate_zero_shot_classification,
236283
"zero-shot-image-classification": validate_zero_shot_classification,
237284
"feature-extraction": validate_feature_extraction,
238-
"ner": validate_ner,
285+
"token-classification": validate_ner,
239286
"question-answering": validate_question_answering,
240287
"fill-mask": validate_fill_mask,
241288
"summarization": validate_summarization,
@@ -253,5 +300,5 @@
253300
"sentence-embeddings": validate_zero_shot_classification,
254301
"sentence-ranking": validate_zero_shot_classification,
255302
"text-to-image": validate_text_to_image,
256-
"custom": validate_custom
303+
"custom": validate_custom,
257304
}

tests/integ/conftest.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,17 @@ def remote_container(device, task, framework):
6868
def local_container(device, task, repository_id, framework):
6969
try:
7070
time.sleep(random.randint(1, 5))
71-
id = uuid.uuid4()
7271
if not (task == "custom"):
7372
model = task2model[task][framework]
7473
id = task
7574
else:
7675
model = repository_id
7776

77+
env = {
78+
"HF_MODEL_DIR": "/opt/huggingface/model",
79+
"HF_TASK": task,
80+
}
81+
7882
logging.info(f"Starting container with model: {model}")
7983

8084
if not model:
@@ -101,8 +105,19 @@ def local_container(device, task, repository_id, framework):
101105
device_request = (
102106
[docker.types.DeviceRequest(count=-1, capabilities=[["gpu"]])]
103107
if device == "gpu"
104-
else []
108+
else None
105109
)
110+
if device == "inf2":
111+
devices = {
112+
"/dev/neuron0": {
113+
"PathInContainer": "/dev/neuron0",
114+
"CgroupPermissions": "rwm",
115+
}
116+
}
117+
env["HF_OPTIMUM_BATCH_SIZE"] = 1
118+
env["HF_OPTIMUM_SEQUENCE_LENGTH"] = 128
119+
else:
120+
devices = None
106121

107122
object_id = model.replace("/", "--")
108123
model_dir = f"{HF_HUB_CACHE}/{object_id}"
@@ -115,11 +130,13 @@ def local_container(device, task, repository_id, framework):
115130
container_image,
116131
name=container_name,
117132
ports={"5000": port},
118-
environment={"HF_MODEL_DIR": "/opt/huggingface/model", "HF_TASK": task},
133+
environment=env,
119134
volumes={model_dir: {"bind": "/opt/huggingface/model", "mode": "ro"}},
120135
detach=True,
121136
# GPU
122137
device_requests=device_request,
138+
# INF2
139+
devices=devices,
123140
), port
124141

125142
# Teardown

tests/integ/helpers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def verify_task(
119119
[
120120
"text-classification",
121121
"zero-shot-classification",
122-
"ner",
122+
"token-classification",
123123
"question-answering",
124124
"fill-mask",
125125
"summarization",
@@ -177,7 +177,7 @@ def test_pt_container_remote_model(task) -> None:
177177
[
178178
"text-classification",
179179
"zero-shot-classification",
180-
"ner",
180+
"token-classification",
181181
"question-answering",
182182
"fill-mask",
183183
"summarization",
@@ -315,7 +315,7 @@ def test_pt_container_legacy_custom_pipeline(repository_id) -> None:
315315
[
316316
"text-classification",
317317
"zero-shot-classification",
318-
"ner",
318+
"token-classification",
319319
"question-answering",
320320
"fill-mask",
321321
"summarization",
@@ -371,7 +371,7 @@ def test_tf_container_remote_model(task) -> None:
371371
[
372372
"text-classification",
373373
"zero-shot-classification",
374-
"ner",
374+
"token-classification",
375375
"question-answering",
376376
"fill-mask",
377377
"summarization",

0 commit comments

Comments
 (0)