generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathtests.py
More file actions
1203 lines (989 loc) · 45.4 KB
/
tests.py
File metadata and controls
1203 lines (989 loc) · 45.4 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import os
import subprocess
import logging
import pytest
import llm.prepare as prepare
import llm.client as client
import rb_client as rb_client
import test_client
djl_version = os.environ.get('TEST_DJL_VERSION', '').strip()
override_image_tag_suffix = os.environ.get('OVERRIDE_IMAGE_TAG_SUFFIX',
'').strip()
image_repo = os.environ.get('IMAGE_REPO', '').strip()
def is_applicable_cuda_capability(arch: int) -> bool:
import torch
if not torch.cuda.is_available():
return False
major, minor = torch.cuda.get_device_capability()
return (10 * major + minor) >= arch
class Runner:
def __init__(self, container, test_name=None, download=False):
self.container = container
self.test_name = test_name
self.client_file_handler = None
# Compute flavor and repo
repo = image_repo
if djl_version is None or len(
djl_version) == 0 or djl_version == "nightly":
flavor = f"{container}-nightly"
elif djl_version == "temp":
flavor = f"{container}-temp-{os.environ['GITHUB_SHA']}"
else:
flavor = f"{container}-{djl_version}-{os.environ['GITHUB_SHA']}"
if override_image_tag_suffix:
flavor = f"{container}-{override_image_tag_suffix}"
self.image = f"{repo}:{flavor}"
# os.system(f'docker pull {self.image}')
os.system('rm -rf models')
if download:
os.system(f"./download_models.sh {self.container}")
logging.info(f"Using the following image for tests: {self.image}")
def __enter__(self):
return self
def __exit__(self, *args):
client.remove_file_handler_from_logger(self.client_file_handler)
if self.test_name is not None:
esc_test_name = self.test_name.replace("/", "-")
os.system(f"mkdir -p all_logs/{esc_test_name}")
os.system(
f"cp client_logs/{esc_test_name}_client.log all_logs/{esc_test_name}/ || true"
)
os.system(f"cp -r logs all_logs/{esc_test_name}")
subprocess.run(["./remove_container.sh"],
check=True,
capture_output=True)
os.system("cat logs/serving.log")
def launch(self, env_vars=None, container=None, cmd=None):
if env_vars is not None:
if isinstance(env_vars, list):
env_vars = "\n".join(env_vars)
with open("docker_env", "w") as f:
f.write(env_vars)
else:
if os.path.isfile("docker_env"):
os.remove("docker_env")
if container is None:
container = self.container
if cmd is None:
cmd = 'serve -m test=file:/opt/ml/model/test/'
model_dir = os.path.join(os.getcwd(), 'models')
os.makedirs("client_logs", exist_ok=True)
if self.test_name:
esc_test_name = self.test_name.replace("/", "-")
self.client_file_handler = client.add_file_handler_to_logger(
f"client_logs/{esc_test_name}_client.log")
return subprocess.run(
f'./launch_container.sh {self.image} {model_dir} {container} {cmd}'
.split(),
check=True,
capture_output=True)
@pytest.mark.cpu
class TestCpuFull:
def test_python_model(self):
with Runner('cpu-full', 'python_model', download=True) as r:
r.launch(
cmd=
"serve -m test::Python=file:/opt/ml/model/resnet18_all_batch.zip"
)
os.system("./test_client.sh image/jpg models/kitten.jpg")
os.system("./test_client.sh tensor/ndlist 1,3,224,224")
os.system("./test_client.sh tensor/npz 1,3,224,224")
def test_python_dynamic_batch(self):
with Runner('cpu-full', 'dynamic_batch', download=True) as r:
env = ["SERVING_BATCH_SIZE=2", "SERVING_MAX_BATCH_DELAY=30000"]
r.launch(
env_vars=env,
cmd=
"serve -m test::Python=file:/opt/ml/model/resnet18_all_batch.zip"
)
os.system(
"EXPECT_TIMEOUT=1 ./test_client.sh image/jpg models/kitten.jpg"
)
os.system("./test_client.sh image/jpg models/kitten.jpg")
@pytest.mark.cpu
@pytest.mark.parametrize('arch', ["cpu", "cpu-full"])
class TestCpuBoth:
def test_pytorch(self, arch):
with Runner(arch, 'pytorch', download=True) as r:
r.launch(
cmd=
"serve -m test::PyTorch=file:/opt/ml/model/resnet18_all_batch.zip"
)
os.system("./test_client.sh image/jpg models/kitten.jpg")
def test_pytorch_binary(self, arch):
with Runner(arch, 'pytorch_binary', download=True) as r:
r.launch(
cmd=
'serve -m "test::PyTorch=file:/opt/ml/model/resnet18_all_batch.zip?translatorFactory=ai.djl.translate.NoopServingTranslatorFactory&application=undefined'
)
os.system("./test_client.sh tensor/ndlist 1,3,224,224")
os.system("./test_client.sh tensor/npz 1,3,224,224")
def test_pytorch_dynamic_batch(self, arch):
with Runner(arch, 'pytorch_dynamic_batch', download=True) as r:
env = ["SERVING_BATCH_SIZE=2", "SERVING_MAX_BATCH_DELAY=30000"]
r.launch(
env_vars=env,
cmd=
'serve -m "test::PyTorch=file:/opt/ml/model/resnet18_all_batch.zip?translatorFactory=ai.djl.translate.NoopServingTranslatorFactory&application=undefined'
)
os.system(
"EXPECT_TIMEOUT=1 ./test_client.sh image/jpg models/kitten.jpg"
)
os.system("./test_client.sh image/jpg models/kitten.jpg")
def test_mxnet(self, arch):
with Runner(arch, 'mxnet', download=True) as r:
r.launch(
cmd='serve -m test::MXNet=file:/opt/ml/model/ssd_resnet50.zip')
os.system("./test_client.sh image/jpg models/kitten.jpg")
def test_onnx(self, arch):
with Runner(arch, 'onnx', download=True) as r:
r.launch(
cmd=
'serve -m test::OnnxRuntime=file:/opt/ml/model/resnet18-v1-7.zip'
)
os.system("./test_client.sh image/jpg models/kitten.jpg")
def test_tensorflow_binary(self, arch):
with Runner(arch, 'tensorflow_binary', download=True) as r:
r.launch(
cmd=
'serve -m test::TensorFlow=file:/opt/ml/model/resnet50v1.zip?model_name=resnet50'
)
os.system("./test_client.sh tensor/ndlist 1,224,224,3")
@pytest.mark.gpu
@pytest.mark.gpu_4
class TestGpu:
def test_python_model(self):
with Runner('pytorch-gpu', 'python_model', download=True) as r:
r.launch(
cmd=
"serve -m test::Python=file:/opt/ml/model/resnet18_all_batch.zip"
)
os.system("./test_client.sh image/jpg models/kitten.jpg")
def test_pytorch(self):
with Runner('pytorch-gpu', 'pytorch_model', download=True) as r:
r.launch(
cmd=
"serve -m test::PyTorch=file:/opt/ml/model/resnet18_all_batch.zip"
)
os.system("./test_client.sh image/jpg models/kitten.jpg")
@pytest.mark.aarch64
class TestAarch64:
def test_pytorch(self):
with Runner('aarch64', 'pytorch_model', download=True) as r:
r.launch(
cmd=
"serve -m test::PyTorch=file:/opt/ml/model/resnet18_all_batch.zip"
)
os.system("./test_client.sh image/jpg models/kitten.jpg")
def test_onnx(self):
with Runner('aarch64', 'onnx', download=True) as r:
r.launch(
cmd=
'serve -m test::OnnxRuntime=file:/opt/ml/model/resnet18-v1-7.zip'
)
os.system("./test_client.sh image/jpg models/kitten.jpg")
@pytest.mark.hf
@pytest.mark.gpu_4
class TestHfHandler:
def test_gpt_neo(self):
with Runner('lmi', 'test_gpt_neo_2.7b') as r:
prepare.build_hf_handler_model("gpt-neo-2.7b")
r.launch()
client.run("huggingface gpt-neo-2.7b".split())
def test_bloom_7b(self):
with Runner('lmi', 'bloom-7b1') as r:
prepare.build_hf_handler_model("bloom-7b1")
r.launch()
client.run("huggingface bloom-7b1".split())
def test_llama2_7b(self):
with Runner('lmi', 'llama-2-7b') as r:
prepare.build_hf_handler_model("llama-2-7b")
r.launch()
client.run("huggingface llama-2-7b".split())
def test_gptj_6B(self):
with Runner('lmi', 'gpt-j-6b') as r:
prepare.build_hf_handler_model("gpt-j-6b")
r.launch()
client.run("huggingface gpt-j-6b".split())
def test_llama3_lora(self):
with Runner('lmi', 'llama3-tiny-random-lora') as r:
prepare.build_hf_handler_model("llama3-tiny-random-lora")
r.launch()
client.run("huggingface llama3-tiny-random-lora".split())
def test_streaming_bigscience_bloom_3b(self):
with Runner('lmi', 'bigscience/bloom-3b') as r:
prepare.build_hf_handler_model("bigscience/bloom-3b")
r.launch("CUDA_VISIBLE_DEVICES=1,2")
client.run("huggingface bigscience/bloom-3b".split())
def test_streaming_t5_large(self):
with Runner('lmi', 't5-large') as r:
prepare.build_hf_handler_model("t5-large")
r.launch("CUDA_VISIBLE_DEVICES=1")
client.run("huggingface t5-large".split())
@pytest.mark.trtllm
@pytest.mark.gpu_4
class TestTrtLlmHandler1:
def test_llama2_13b_tp4(self):
with Runner('tensorrt-llm', 'llama2-13b') as r:
prepare.build_trtllm_handler_model("llama2-13b")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run("trtllm llama2-13b".split())
def test_internlm_7b(self):
with Runner('tensorrt-llm', 'internlm-7b') as r:
prepare.build_trtllm_handler_model("internlm-7b")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run("trtllm internlm-7b".split())
def test_baichuan2_13b(self):
with Runner('tensorrt-llm', 'baichuan2-13b') as r:
prepare.build_trtllm_handler_model("baichuan2-13b")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run("trtllm baichuan2-13b".split())
def test_chatglm3_6b(self):
with Runner('tensorrt-llm', 'chatglm3-6b') as r:
prepare.build_trtllm_handler_model("chatglm3-6b")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run("trtllm chatglm3-6b".split())
def test_gpt2(self):
with Runner('tensorrt-llm', 'gpt2') as r:
prepare.build_trtllm_handler_model("gpt2")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run("trtllm gpt2".split())
def test_santacoder(self):
with Runner('tensorrt-llm', 'santacoder') as r:
prepare.build_trtllm_handler_model("santacoder")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run("trtllm santacoder".split())
def test_llama_31_8b(self):
with Runner('tensorrt-llm', 'llama-3-1-8b') as r:
prepare.build_trtllm_handler_model('llama-3-1-8b')
r.launch()
client.run("trtllm llama-3-1-8b".split())
@pytest.mark.trtllm
@pytest.mark.gpu_4
class TestTrtLlmHandler2:
def test_llama2_7b_hf_smoothquant(self):
with Runner('tensorrt-llm', 'llama2-7b-smoothquant') as r:
prepare.build_trtllm_handler_model("llama2-7b-smoothquant")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run("trtllm llama2-7b-smoothquant".split())
def test_mistral(self):
with Runner('tensorrt-llm', 'mistral-7b') as r:
prepare.build_trtllm_handler_model("mistral-7b")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run("trtllm mistral-7b".split())
def test_gpt_j_6b(self):
with Runner('tensorrt-llm', 'gpt-j-6b') as r:
prepare.build_trtllm_handler_model("gpt-j-6b")
r.launch("CUDA_VISIBLE_DEVICES=0")
client.run("trtllm gpt-j-6b".split())
def test_qwen_7b(self):
with Runner('tensorrt-llm', 'qwen-7b') as r:
prepare.build_trtllm_handler_model("qwen-7b")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run("trtllm qwen-7b".split())
def test_llama2_7b_chat(self):
with Runner('tensorrt-llm', 'llama2-7b-chat') as r:
prepare.build_trtllm_handler_model("llama2-7b-chat")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run("trtllm_chat llama2-7b-chat".split())
def test_flan_t5_xl(self):
with Runner('tensorrt-llm', "flan-t5-xl") as r:
prepare.build_trtllm_handler_model("flan-t5-xl")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run("trtllm flan-t5-xl".split())
@pytest.mark.lmi_dist
@pytest.mark.gpu_4
class TestSchedulerSingleGPU:
def test_gpt2(self):
with Runner('lmi', 'gpt2') as r:
prepare.build_rolling_batch_model("gpt2")
r.launch()
rb_client.run("correctness gpt2".split())
def test_bllm(self):
with Runner('lmi', 'bloom-560m') as r:
prepare.build_rolling_batch_model("bloom-560m")
r.launch()
rb_client.run("scheduler_single_gpu bloom-560m".split())
@pytest.mark.lmi_dist
@pytest.mark.gpu_4
class TestSchedulerMultiGPU:
def test_gptj_6b(self):
with Runner('lmi', 'gpt-j-6b') as r:
prepare.build_rolling_batch_model("gpt-j-6b")
r.launch()
rb_client.run("scheduler_multi_gpu gpt-j-6b".split())
@pytest.mark.lmi_dist
@pytest.mark.gpu_4
class TestLmiDist1:
def test_gpt_neox_20b(self):
with Runner('lmi', 'gpt-neox-20b') as r:
prepare.build_lmi_dist_model("gpt-neox-20b")
r.launch()
client.run("lmi_dist gpt-neox-20b".split())
def test_falcon_7b(self):
with Runner('lmi', 'falcon-7b') as r:
prepare.build_lmi_dist_model("falcon-7b")
r.launch()
client.run("lmi_dist falcon-7b".split())
def test_falcon2_11b(self):
with Runner('lmi', 'falcon-11b') as r:
prepare.build_lmi_dist_model("falcon-11b")
r.launch()
client.run("lmi_dist falcon-11b".split())
def test_gpt2(self):
with Runner('lmi', 'gpt2') as r:
prepare.build_lmi_dist_model("gpt2")
envs = [
"OPTION_MAX_ROLLING_BATCH_SIZE=2",
"OPTION_OUTPUT_FORMATTER=jsonlines",
"TENSOR_PARALLEL_DEGREE=1", "OPTION_TASK=text-generation",
"OPTION_ROLLING_BATCH=lmi-dist"
]
r.launch("\n".join(envs))
client.run("lmi_dist gpt2".split())
def test_mpt_7b(self):
with Runner('lmi', 'mpt-7b') as r:
prepare.build_lmi_dist_model("mpt-7b")
r.launch()
client.run("lmi_dist mpt-7b".split())
def test_mistral_7b_marlin(self):
with Runner('lmi', 'mistral-7b-marlin') as r:
prepare.build_lmi_dist_model("mistral-7b-marlin")
r.launch()
client.run("lmi_dist mistral-7b-marlin".split())
def test_llama2_13b_flashinfer(self):
with Runner('lmi', 'llama-2-13b-flashinfer') as r:
prepare.build_lmi_dist_model("llama-2-13b-flashinfer")
envs = [
"VLLM_ATTENTION_BACKEND=FLASHINFER",
]
r.launch(env_vars=envs)
client.run("lmi_dist llama-2-13b-flashinfer".split())
def test_llama2_tiny_autoawq(self):
with Runner('lmi', 'llama-2-tiny-autoawq') as r:
prepare.build_lmi_dist_model("llama-2-tiny")
r.launch(
"CUDA_VISIBLE_DEVICES=0,1,2,3",
cmd=
"partition --model-dir /opt/ml/input/data/training --save-mp-checkpoint-path /opt/ml/input/data/training/aot"
)
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3",
cmd="serve -m test=file:/opt/ml/model/test/aot")
client.run("lmi_dist llama-2-tiny".split())
os.system('sudo rm -rf models')
def test_llama3_8b_chunked_prefill(self):
with Runner('lmi', 'llama3-8b-chunked-prefill') as r:
prepare.build_lmi_dist_model("llama3-8b-chunked-prefill")
r.launch()
client.run(
"lmi_dist llama3-8b-chunked-prefill --in_tokens 1200".split())
def test_falcon_11b_chunked_prefill(self):
with Runner('lmi', 'falcon-11b-chunked-prefill') as r:
prepare.build_lmi_dist_model("falcon-11b-chunked-prefill")
r.launch()
client.run(
"lmi_dist falcon-11b-chunked-prefill --in_tokens 1200".split())
def test_flan_t5_xl(self):
with Runner('lmi', 'flan-t5-xl') as r:
prepare.build_lmi_dist_model("flan-t5-xl")
r.launch()
client.run("lmi_dist flan-t5-xl".split())
@pytest.mark.lmi_dist
@pytest.mark.gpu_4
class TestLmiDist2:
def test_gpt_neox_20b(self):
with Runner('lmi', 'octocoder') as r:
prepare.build_lmi_dist_model("octocoder")
r.launch()
client.run("lmi_dist octocoder".split())
def test_speculative_llama_13b(self):
with Runner('lmi', 'speculative-llama-13b') as r:
prepare.build_lmi_dist_model("speculative-llama-13b")
r.launch()
client.run("lmi_dist speculative-llama-13b".split())
def test_starcoder2_7b(self):
with Runner('lmi', 'starcoder2-7b') as r:
prepare.build_lmi_dist_model("starcoder2-7b")
r.launch()
client.run("lmi_dist starcoder2-7b".split())
def test_gemma_2b(self):
with Runner('lmi', 'gemma-2b') as r:
prepare.build_lmi_dist_model("gemma-2b")
r.launch()
client.run("lmi_dist gemma-2b".split())
def test_llama2_13b_gptq(self):
with Runner('lmi', 'llama2-13b-gptq') as r:
prepare.build_lmi_dist_model("llama2-13b-gptq")
r.launch()
client.run("lmi_dist llama2-13b-gptq".split())
def test_mistral_7b(self):
with Runner('lmi', 'mistral-7b') as r:
prepare.build_lmi_dist_model("mistral-7b")
r.launch()
client.run("lmi_dist mistral-7b".split())
def test_llama2_7b_32k(self):
with Runner('lmi', 'llama2-7b-32k') as r:
prepare.build_lmi_dist_model("llama2-7b-32k")
r.launch()
client.run("lmi_dist llama2-7b-32k".split())
def test_mistral_7b_128k_awq(self):
with Runner('lmi', 'mistral-7b-128k-awq') as r:
prepare.build_lmi_dist_model("mistral-7b-128k-awq")
r.launch()
client.run("lmi_dist mistral-7b-128k-awq".split())
def test_llama2_7b_chat(self):
with Runner('lmi', 'llama2-7b-chat') as r:
prepare.build_lmi_dist_model("llama2-7b-chat")
r.launch()
client.run("lmi_dist_chat llama2-7b-chat".split())
def test_llama31_8b_secure(self):
with Runner('lmi', 'llama-3.1-8b') as r:
prepare.build_lmi_dist_model("llama-3.1-8b")
envs = [
"SAGEMAKER_SECURE_MODE=True",
"SAGEMAKER_SECURITY_CONTROLS=DISALLOW_CUSTOM_INFERENCE_SCRIPTS"
]
r.launch(env_vars=envs)
client.run("lmi_dist llama-3.1-8b".split())
@pytest.mark.lmi_dist
@pytest.mark.gpu_4
class TestLmiDistMultiNode:
def test_llama3_8b(self):
with Runner('lmi', 'llama3-8b') as r:
prepare.build_lmi_dist_model("llama3-8b")
r.launch(cmd="multi_node")
client.run("lmi_dist llama3-8b --in_tokens 1200".split())
@pytest.mark.vllm
@pytest.mark.gpu_4
class TestVllm1:
def test_gpt_neox_20b(self):
with Runner('lmi', 'gpt-neox-20b') as r:
prepare.build_vllm_model("gpt-neox-20b")
r.launch()
client.run("vllm gpt-neox-20b".split())
def test_mistral_7b(self):
with Runner('lmi', 'mistral-7b') as r:
prepare.build_vllm_model("mistral-7b")
r.launch()
client.run("vllm mistral-7b".split())
client.run("vllm_chat mistral-7b".split())
def test_phi2(self):
with Runner('lmi', 'phi-2') as r:
prepare.build_vllm_model("phi-2")
r.launch()
client.run("vllm phi-2".split())
def test_starcoder2_7b(self):
with Runner('lmi', 'starcoder2-7b') as r:
prepare.build_vllm_model("starcoder2-7b")
r.launch()
client.run("vllm starcoder2-7b".split())
def test_gemma_2b(self):
with Runner('lmi', 'gemma-2b') as r:
prepare.build_vllm_model("gemma-2b")
r.launch()
client.run("vllm gemma-2b".split())
def test_llama2_7b_chat(self):
with Runner('lmi', 'llama2-7b-chat') as r:
prepare.build_vllm_model("llama2-7b-chat")
r.launch()
client.run("vllm_chat llama2-7b-chat".split())
@pytest.mark.skipif(not is_applicable_cuda_capability(89),
reason="Unsupported CUDA capability")
def test_qwen2_7b_fp8(self):
with Runner('lmi', 'qwen2-7b-fp8') as r:
prepare.build_vllm_model("qwen2-7b-fp8")
r.launch()
client.run("vllm qwen2-7b-fp8".split())
def test_llama3_8b_chunked_prefill(self):
with Runner('lmi', 'llama3-8b-chunked-prefill') as r:
prepare.build_vllm_model("llama3-8b-chunked-prefill")
r.launch()
client.run(
"vllm llama3-8b-chunked-prefill --in_tokens 1200".split())
def test_falcon_11b_chunked_prefill(self):
with Runner('lmi', 'falcon-11b-chunked-prefill') as r:
prepare.build_vllm_model("falcon-11b-chunked-prefill")
r.launch()
client.run(
"vllm falcon-11b-chunked-prefill --in_tokens 1200".split())
def test_llama_68m_speculative_medusa(self):
with Runner('lmi', 'llama-68m-speculative-medusa') as r:
prepare.build_vllm_model("llama-68m-speculative-medusa")
r.launch()
client.run("vllm llama-68m-speculative-medusa".split())
def test_llama_68m_speculative_eagle(self):
with Runner('lmi', 'llama-68m-speculative-eagle') as r:
prepare.build_vllm_model("llama-68m-speculative-eagle")
r.launch()
client.run("vllm llama-68m-speculative-eagle".split())
def test_llama3_1_8b_instruct_tool(self):
with Runner('lmi', 'llama3-1-8b-instruct-tool') as r:
prepare.build_vllm_model("llama3-1-8b-instruct-tool")
r.launch()
client.run("vllm_tool llama3-1-8b-instruct-tool".split())
def test_mistral_7b_instruct_v03_tool(self):
with Runner('lmi', 'mistral-7b-instruct-v03-tool') as r:
prepare.build_vllm_model("mistral-7b-instruct-v03-tool")
r.launch()
client.run("vllm_tool mistral-7b-instruct-v03-tool".split())
def test_deepseek_r1_distill_qwen_1_5b(self):
with Runner('lmi', 'deepseek-r1-distill-qwen-1-5b') as r:
prepare.build_vllm_model("deepseek-r1-distill-qwen-1-5b")
r.launch()
client.run("vllm_chat deepseek-r1-distill-qwen-1-5b".split())
@pytest.mark.vllm
@pytest.mark.lora
@pytest.mark.gpu_4
class TestVllmLora:
def test_lora_llama2_7b(self):
with Runner('lmi', 'llama-7b-unmerged-lora') as r:
prepare.build_vllm_model("llama-7b-unmerged-lora")
r.launch()
client.run("vllm_adapters llama-7b-unmerged-lora".split())
def test_lora_llama2_7b_overflow(self):
with Runner('lmi', 'llama-7b-unmerged-lora-overflow') as r:
prepare.build_vllm_model("llama-7b-unmerged-lora-overflow")
r.launch()
client.run("vllm_adapters llama-7b-unmerged-lora-overflow".split())
def test_lora_llama2_13b_awq(self):
with Runner('lmi', 'llama2-13b-awq-unmerged-lora') as r:
prepare.build_vllm_model("llama2-13b-awq-unmerged-lora")
r.launch()
client.run("vllm_adapters llama2-13b-awq-unmerged-lora".split())
def test_lora_mistral_7b(self):
with Runner('lmi', 'mistral-7b-unmerged-lora') as r:
prepare.build_vllm_model("mistral-7b-unmerged-lora")
r.launch()
client.run("vllm_adapters mistral-7b-unmerged-lora".split())
def test_lora_mistral_7b_awq(self):
with Runner('lmi', 'mistral-7b-awq-unmerged-lora') as r:
prepare.build_vllm_model("mistral-7b-awq-unmerged-lora")
r.launch()
client.run("vllm_adapters mistral-7b-awq-unmerged-lora".split())
def test_lora_mistral_7b_gptq(self):
with Runner('lmi', 'mistral-7b-gptq-unmerged-lora') as r:
prepare.build_lmi_dist_model("mistral-7b-gptq-unmerged-lora")
r.launch()
client.run("vllm_adapters mistral-7b-gptq-unmerged-lora".split())
def test_lora_llama3_8b(self):
with Runner('lmi', 'llama3-8b-unmerged-lora') as r:
prepare.build_vllm_model("llama3-8b-unmerged-lora")
r.launch()
client.run("vllm_adapters llama3-8b-unmerged-lora".split())
def test_lora_gemma_7b(self):
with Runner('lmi', 'gemma-7b-unmerged-lora') as r:
prepare.build_lmi_dist_model("gemma-7b-unmerged-lora")
r.launch()
client.run("vllm_adapters gemma-7b-unmerged-lora".split())
def test_lora_phi2(self):
with Runner('lmi', 'phi2-unmerged-lora') as r:
prepare.build_lmi_dist_model("phi2-unmerged-lora")
r.launch()
client.run("vllm_adapters phi2-unmerged-lora".split())
@pytest.mark.lmi_dist
@pytest.mark.lora
@pytest.mark.gpu_4
class TestLmiDistLora:
def test_lora_llama2_7b(self):
with Runner('lmi', 'llama-7b-unmerged-lora') as r:
prepare.build_lmi_dist_model("llama-7b-unmerged-lora")
r.launch()
client.run("lmi_dist_adapters llama-7b-unmerged-lora".split())
def test_lora_llama2_7b_overflow(self):
with Runner('lmi', 'llama-7b-unmerged-lora-overflow') as r:
prepare.build_lmi_dist_model("llama-7b-unmerged-lora-overflow")
r.launch()
client.run(
"lmi_dist_adapters llama-7b-unmerged-lora-overflow".split())
def test_lora_llama2_13b_awq(self):
with Runner('lmi', 'llama2-13b-awq-unmerged-lora') as r:
prepare.build_lmi_dist_model("llama2-13b-awq-unmerged-lora")
r.launch()
client.run(
"lmi_dist_adapters llama2-13b-awq-unmerged-lora".split())
def test_lora_mistral_7b(self):
with Runner('lmi', 'mistral-7b-unmerged-lora') as r:
prepare.build_lmi_dist_model("mistral-7b-unmerged-lora")
r.launch()
client.run("lmi_dist_adapters mistral-7b-unmerged-lora".split())
def test_lora_mistral_7b_awq(self):
with Runner('lmi', 'mistral-7b-awq-unmerged-lora') as r:
prepare.build_lmi_dist_model("mistral-7b-awq-unmerged-lora")
r.launch()
client.run(
"lmi_dist_adapters mistral-7b-awq-unmerged-lora".split())
def test_lora_mistral_7b_gptq(self):
with Runner('lmi', 'mistral-7b-gptq-unmerged-lora') as r:
prepare.build_lmi_dist_model("mistral-7b-gptq-unmerged-lora")
r.launch()
client.run(
"lmi_dist_adapters mistral-7b-gptq-unmerged-lora".split())
def test_lora_llama3_8b(self):
with Runner('lmi', 'llama3-8b-unmerged-lora') as r:
prepare.build_lmi_dist_model("llama3-8b-unmerged-lora")
r.launch()
client.run("lmi_dist_adapters llama3-8b-unmerged-lora".split())
def test_lora_gemma_7b(self):
with Runner('lmi', 'gemma-7b-unmerged-lora') as r:
prepare.build_lmi_dist_model("gemma-7b-unmerged-lora")
r.launch()
client.run("lmi_dist_adapters gemma-7b-unmerged-lora".split())
def test_lora_phi2(self):
with Runner('lmi', 'phi2-unmerged-lora') as r:
prepare.build_lmi_dist_model("phi2-unmerged-lora")
r.launch()
client.run("lmi_dist_adapters phi2-unmerged-lora".split())
@pytest.mark.inf
class TestNeuronx1:
def test_python_mode(self):
with Runner('pytorch-inf2', 'test_python_mode', download=True) as r:
r.launch(
cmd=
'serve -m test::PyTorch:nc0=file:/opt/ml/model/resnet18_inf2_2_4.tar.gz',
container='pytorch-inf2-1')
test_client.run()
def test_gpt2(self):
with Runner('pytorch-inf2', 'gpt2') as r:
prepare.build_transformers_neuronx_handler_model("gpt2")
r.launch(container='pytorch-inf2-1')
client.run("transformers_neuronx gpt2".split())
def test_gpt2_quantize(self):
with Runner('pytorch-inf2', 'gpt2-quantize') as r:
prepare.build_transformers_neuronx_handler_model("gpt2-quantize")
r.launch(container='pytorch-inf2-1')
client.run("transformers_neuronx gpt2-quantize".split())
@pytest.mark.parametrize(
"model",
["tiny-llama-rb-aot", "tiny-llama-rb-aot-quant", "tiny-llama-rb-lcnc"])
def test_partition(self, model):
with Runner('pytorch-inf2', f'partition-{model}') as r:
try:
prepare.build_transformers_neuronx_handler_model(model)
r.launch(
container="pytorch-inf2-1",
cmd=
"partition --model-dir /opt/ml/input/data/training --save-mp-checkpoint-path /opt/ml/input/data/training/aot --skip-copy"
)
r.launch(container="pytorch-inf2-1",
cmd="serve -m test=file:/opt/ml/model/test/aot")
client.run(
"transformers_neuronx_rolling_batch tiny-llama-rb".split())
finally:
os.system('sudo rm -rf models')
@pytest.mark.inf
class TestNeuronx2:
def test_stream_opt(self):
with Runner('pytorch-inf2', 'opt-1.3b-streaming') as r:
prepare.build_transformers_neuronx_handler_model(
"opt-1.3b-streaming")
r.launch(container='pytorch-inf2-6')
client.run("transformers_neuronx opt-1.3b-streaming".split())
def test_mixtral(self):
with Runner('pytorch-inf2', 'mixtral-8x7b') as r:
prepare.build_transformers_neuronx_handler_model("mixtral-8x7b")
r.launch(container='pytorch-inf2-4')
client.run("transformers_neuronx mixtral-8x7b".split())
def test_stable_diffusion_1_5(self):
with Runner('pytorch-inf2', 'stable-diffusion-1.5-neuron') as r:
prepare.build_transformers_neuronx_handler_model(
"stable-diffusion-1.5-neuron")
r.launch(container='pytorch-inf2-2')
client.run(
"neuron-stable-diffusion stable-diffusion-1.5-neuron".split())
def test_stable_diffusion_2_1(self):
with Runner('pytorch-inf2', 'stable-diffusion-2.1-neuron') as r:
prepare.build_transformers_neuronx_handler_model(
"stable-diffusion-2.1-neuron")
r.launch(container='pytorch-inf2-2')
client.run(
"neuron-stable-diffusion stable-diffusion-2.1-neuron".split())
def test_stable_diffusion_xl(self):
with Runner('pytorch-inf2', 'stable-diffusion-xl-neuron') as r:
prepare.build_transformers_neuronx_handler_model(
"stable-diffusion-xl-neuron")
r.launch(container='pytorch-inf2-2')
client.run(
"neuron-stable-diffusion stable-diffusion-xl-neuron".split())
@pytest.mark.inf
class TestNeuronxRollingBatch:
def test_llama_7b(self):
with Runner('pytorch-inf2', 'llama-7b-rb') as r:
prepare.build_transformers_neuronx_handler_model("llama-7b-rb")
r.launch(container='pytorch-inf2-2')
client.run(
"transformers_neuronx_rolling_batch llama-7b-rb".split())
def test_tiny_llama_vllm(self):
with Runner('pytorch-inf2', 'tiny-llama-rb-vllm') as r:
prepare.build_transformers_neuronx_handler_model(
"tiny-llama-rb-vllm")
r.launch(container='pytorch-inf2-1')
client.run("transformers_neuronx_rolling_batch tiny-llama-rb-vllm".
split())
def test_llama3_vllm(self):
with Runner('pytorch-inf2', 'llama-3-8b-rb-vllm') as r:
prepare.build_transformers_neuronx_handler_model(
"llama-3-8b-rb-vllm")
r.launch(container='pytorch-inf2-4')
client.run("transformers_neuronx_rolling_batch llama-3-8b-rb-vllm".
split())
def test_mistral(self):
with Runner('pytorch-inf2', 'mistral-7b-rb') as r:
prepare.build_transformers_neuronx_handler_model("mistral-7b-rb")
r.launch(container='pytorch-inf2-2')
client.run(
"transformers_neuronx_rolling_batch mistral-7b-rb".split())
def test_llama_speculative(self):
with Runner('pytorch-inf2', 'llama-speculative-rb') as r:
prepare.build_transformers_neuronx_handler_model(
"llama-speculative-rb")
r.launch(container='pytorch-inf2-6')
client.run(
"transformers_neuronx_rolling_batch llama-speculative-rb".
split())
def test_llama_speculative_compiled(self):
with Runner('pytorch-inf2', 'llama-speculative-compiled-rb') as r:
prepare.build_transformers_neuronx_handler_model(
"llama-speculative-compiled-rb")
r.launch(container='pytorch-inf2-6')
client.run(
"transformers_neuronx_rolling_batch llama-speculative-compiled-rb"
.split())
def test_llama_8b_vllm_nxdi_aot(self):
with Runner('pytorch-inf2', 'llama-3-1-8b-instruct-vllm-nxdi') as r:
prepare.build_transformers_neuronx_handler_model(
"llama-3-1-8b-instruct-vllm-nxdi")
r.launch(
container="pytorch-inf2-4",
cmd=
"partition --model-dir /opt/ml/input/data/training --save-mp-checkpoint-path /opt/ml/input/data/training/aot"
)
r.launch(container='pytorch-inf2-4',
cmd="serve -m test=file:/opt/ml/model/test/aot")
client.run(
"transformers_neuronx_rolling_batch llama-3-1-8b-instruct-vllm-nxdi"
.split())
def test_llama_vllm_nxdi_aot(self):
with Runner('pytorch-inf2',
'llama-3-2-1b-instruct-vllm-nxdi-aot') as r:
prepare.build_transformers_neuronx_handler_model(
"llama-3-2-1b-instruct-vllm-nxdi-aot")
r.launch(
container="pytorch-inf2-1",
cmd=
"partition --model-dir /opt/ml/input/data/training --save-mp-checkpoint-path /opt/ml/input/data/training/aot"
)
r.launch(container="pytorch-inf2-1",
cmd="serve -m test=file:/opt/ml/model/test/aot")
client.run(
"transformers_neuronx_rolling_batch llama-3-2-1b-instruct-vllm-nxdi-aot"
.split())
@pytest.mark.correctness
@pytest.mark.trtllm
@pytest.mark.gpu_4
class TestCorrectnessTrtLlm:
def test_codestral_22b(self):
with Runner('tensorrt-llm', 'codestral-22b') as r:
prepare.build_correctness_model("trtllm-codestral-22b")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run("correctness trtllm-codestral-22b".split())
def test_llama3_8b(self):
with Runner('tensorrt-llm', 'llama3-8b') as r:
prepare.build_correctness_model("trtllm-llama3-8b")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run("correctness trtllm-llama3-8b".split())
def test_llama3_8b_fp8(self):
with Runner('tensorrt-llm', 'llama3-3b') as r:
prepare.build_correctness_model("trtllm-meta-llama3-8b-fp8")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run("correctness trtllm-meta-llama3-8b-fp8".split())
def test_mistral_7b(self):
with Runner('tensorrt-llm', 'mistral-7b') as r:
prepare.build_correctness_model("trtllm-mistral-7b-instruct-v0.3")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run("correctness trtllm-mistral-7b-instruct-v0.3".split())
def test_mistral_7b_fp8(self):
with Runner('tensorrt-llm', 'mistral-7b') as r:
prepare.build_correctness_model(
"trtllm-mistral-7b-instruct-v0.3-fp8")
r.launch("CUDA_VISIBLE_DEVICES=0,1,2,3")
client.run(
"correctness trtllm-mistral-7b-instruct-v0.3-fp8".split())
@pytest.mark.correctness
@pytest.mark.lmi_dist
@pytest.mark.gpu_4
class TestCorrectnessLmiDist:
def test_codestral_22b(self):
with Runner('lmi', 'codestral-22b') as r:
prepare.build_correctness_model("lmi-dist-codestral-22b")
r.launch()
client.run("correctness lmi-dist-codestral-22b".split())
def test_llama3_1_8b(self):
with Runner('lmi', 'llama3-1-8b') as r:
prepare.build_correctness_model("lmi-dist-llama3-1-8b")
r.launch()
client.run("correctness lmi-dist-llama3-1-8b".split())
@pytest.mark.correctness