forked from NVIDIA/TensorRT-LLM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_llm_api_pytorch.py
More file actions
3366 lines (3011 loc) · 141 KB
/
test_llm_api_pytorch.py
File metadata and controls
3366 lines (3011 loc) · 141 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
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License 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.
import os
import pytest
import torch
from defs.conftest import get_sm_version
from tensorrt_llm import LLM
from tensorrt_llm._torch.modules.fused_moe.fused_moe_triton import \
IS_TRITON_KERNELS_AVAILABLE
from tensorrt_llm._torch.pyexecutor.config import MoeLoadBalancerConfig
from tensorrt_llm.llmapi import (AutoDecodingConfig, CudaGraphConfig,
EagleDecodingConfig, KvCacheConfig, MoeConfig,
MTPDecodingConfig, NGramDecodingConfig,
SamplingParams, TorchCompileConfig)
from tensorrt_llm.quantization import QuantAlgo
from ..conftest import (get_device_count, get_device_memory, llm_models_root,
parametrize_with_ids, skip_no_hopper,
skip_post_blackwell, skip_pre_ada, skip_pre_blackwell,
skip_pre_hopper)
from .accuracy_core import (GSM8K, MMLU, MMMU, CnnDailymail, GPQADiamond,
JsonModeEval, LlmapiAccuracyTestHarness)
class TestLlama3_1_8B(LlmapiAccuracyTestHarness):
MODEL_NAME = "meta-llama/Llama-3.1-8B"
MODEL_PATH = f"{llm_models_root()}/llama-3.1-model/Meta-Llama-3.1-8B"
@pytest.mark.skip_less_device_memory(32000)
def test_auto_dtype(self):
with LLM(self.MODEL_PATH) as llm:
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm)
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_blackwell
def test_nvfp4(self):
model_path = f"{llm_models_root()}/nvfp4-quantized/Meta-Llama-3.1-8B"
with LLM(model_path) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.NVFP4
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm)
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_blackwell
@pytest.mark.parametrize("stream_interval", [4, 64],
ids=["stream_interval_4", "stream_interval_64"])
def test_nvfp4_streaming(self, stream_interval):
# When stream_interval < TLLM_STREAM_INTERVAL_THRESHOLD, hf incremental detokenization is used.
# When stream_interval >= TLLM_STREAM_INTERVAL_THRESHOLD, trtllm implemented incremental detokenization is used.
# The behavior is due to perf considerations, while both paths need to be tested.
with LLM(f"{llm_models_root()}/nvfp4-quantized/Meta-Llama-3.1-8B",
stream_interval=stream_interval) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.NVFP4
assert llm.args.stream_interval == stream_interval
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm, streaming=True)
class TestLlama3_1_8BInstruct(LlmapiAccuracyTestHarness):
MODEL_NAME = "meta-llama/Llama-3.1-8B-Instruct"
MODEL_PATH = f"{llm_models_root()}/llama-3.1-model/Llama-3.1-8B-Instruct"
@pytest.mark.skip_less_device_memory(32000)
@parametrize_with_ids("attn_backend", ["TRTLLM", "FLASHINFER"])
def test_chunked_prefill(self, attn_backend):
with LLM(self.MODEL_PATH,
attn_backend=attn_backend,
enable_chunked_prefill=True,
max_num_tokens=512) as llm:
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
@pytest.mark.skip_less_device_memory(32000)
@parametrize_with_ids("torch_compile", [False, True])
@parametrize_with_ids("attn_backend", ["TRTLLM", "FLASHINFER"])
def test_bfloat16(self, attn_backend, torch_compile):
torch_compile_config = TorchCompileConfig(
enable_fullgraph=True,
enable_piecewise_cuda_graph=True,
capture_num_tokens=[2048, 8192],
max_num_streams=3) if torch_compile else None
pytorch_config = dict(
torch_compile_config=torch_compile_config,
cuda_graph_config=CudaGraphConfig(enable_padding=torch_compile,
batch_sizes=[4]),
attn_backend=attn_backend,
disable_overlap_scheduler=torch_compile,
)
with LLM(self.MODEL_PATH, **pytorch_config) as llm:
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@parametrize_with_ids("torch_compile", [False, True])
@parametrize_with_ids("attn_backend", ["TRTLLM", "FLASHINFER"])
@pytest.mark.parametrize("tp_size,pp_size", [(4, 1), (2, 2), (1, 4)],
ids=["tp4", "tp2pp2", "pp4"])
def test_bfloat16_4gpus(self, tp_size, pp_size, attn_backend,
torch_compile):
if torch_compile and pp_size > 1:
pytest.skip(
"Pipeline parallel with torch.compile is not supported yet.\n"
"Issue: Unfusing flashinfer_fused_add_rmsnorm causes outputs to be "
"discarded at graph breaks.")
torch_compile_config = TorchCompileConfig(
enable_fullgraph=True,
enable_piecewise_cuda_graph=True,
capture_num_tokens=[2048, 8192],
max_num_streams=3) if torch_compile else None
pytorch_config = dict(
torch_compile_config=torch_compile_config,
cuda_graph_config=CudaGraphConfig(enable_padding=torch_compile,
batch_sizes=[4]),
attn_backend=attn_backend,
disable_overlap_scheduler=torch_compile,
)
with LLM(self.MODEL_PATH,
tensor_parallel_size=tp_size,
pipeline_parallel_size=pp_size,
**pytorch_config) as llm:
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_ada
@parametrize_with_ids("torch_compile", [False, True])
@parametrize_with_ids("attn_backend", ["TRTLLM", "FLASHINFER"])
@parametrize_with_ids("fp8kv", [False, True])
def test_fp8(self, fp8kv, attn_backend, torch_compile):
torch_compile_config = TorchCompileConfig(
enable_fullgraph=True,
enable_piecewise_cuda_graph=True,
capture_num_tokens=[2048, 8192],
max_num_streams=3) if torch_compile else None
pytorch_config = dict(
torch_compile_config=torch_compile_config,
cuda_graph_config=CudaGraphConfig(enable_padding=torch_compile,
batch_sizes=[4]),
attn_backend=attn_backend,
disable_overlap_scheduler=torch_compile,
)
if fp8kv:
pytorch_config["kv_cache_config"] = KvCacheConfig(dtype="fp8")
with LLM(
f"{llm_models_root()}/llama-3.1-model/Llama-3.1-8B-Instruct-FP8",
**pytorch_config) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.FP8
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_ada
@parametrize_with_ids("torch_compile", [False, True])
@parametrize_with_ids("attn_backend", ["TRTLLM", "FLASHINFER"])
@parametrize_with_ids("fp8kv", [False, True])
@pytest.mark.parametrize("tp_size,pp_size", [(4, 1), (2, 2), (1, 4)],
ids=["tp4", "tp2pp2", "pp4"])
def test_fp8_4gpus(self, tp_size, pp_size, fp8kv, attn_backend,
torch_compile):
if pp_size > 1 and torch_compile:
pytest.skip(
"Pipeline parallel with torch.compile is not supported yet.\n"
"Issue: Unfusing flashinfer_fused_add_rmsnorm causes outputs to be "
"discarded at graph breaks.")
torch_compile_config = TorchCompileConfig(
enable_fullgraph=True,
enable_piecewise_cuda_graph=True,
capture_num_tokens=[2048, 8192],
max_num_streams=3) if torch_compile else None
pytorch_config = dict(
torch_compile_config=torch_compile_config,
cuda_graph_config=CudaGraphConfig(enable_padding=torch_compile,
batch_sizes=[4]),
attn_backend=attn_backend,
disable_overlap_scheduler=torch_compile,
)
if fp8kv:
pytorch_config["kv_cache_config"] = KvCacheConfig(dtype="fp8")
with LLM(
f"{llm_models_root()}/llama-3.1-model/Llama-3.1-8B-Instruct-FP8",
tensor_parallel_size=tp_size,
pipeline_parallel_size=pp_size,
**pytorch_config) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.FP8
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_hopper
def test_fp8_llm_sampler(self):
model_path = f"{llm_models_root()}/llama-3.1-model/Llama-3.1-8B-Instruct-FP8"
with LLM(model_path, max_batch_size=256) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.FP8
sampling_params = SamplingParams(
temperature=0.8,
top_p=0.95,
)
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm,
sampling_params=sampling_params,
extra_acc_spec="temperature=0.8,top_p=0.95")
task = MMLU(self.MODEL_NAME)
task.evaluate(llm,
sampling_params=sampling_params,
extra_acc_spec="temperature=0.8,top_p=0.95")
@skip_pre_hopper
@parametrize_with_ids("overlap_scheduler", [True, False])
@parametrize_with_ids("eagle3_one_model", [True, False])
def test_eagle3(self, overlap_scheduler, eagle3_one_model):
pytorch_config = dict(
max_batch_size=
1, # add max_batch_size to avoid error in overlap scheduler
disable_overlap_scheduler=not overlap_scheduler,
cuda_graph_config=CudaGraphConfig(max_batch_size=1,
enable_padding=True),
)
kv_cache_config = KvCacheConfig(
enable_block_reuse=True, free_gpu_memory_fraction=0.8
) # both one-model and two-model supports this feature
eagle_model_dir = f"{llm_models_root()}/EAGLE3-LLaMA3.1-Instruct-8B"
target_model_dir = f"{llm_models_root()}/llama-3.1-model/Llama-3.1-8B-Instruct"
draft_len = 4
spec_config = EagleDecodingConfig(max_draft_len=draft_len,
speculative_model_dir=eagle_model_dir,
eagle3_one_model=eagle3_one_model)
with LLM(model=target_model_dir,
**pytorch_config,
kv_cache_config=kv_cache_config,
speculative_config=spec_config,
build_config=None) as llm:
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm)
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_hopper
def test_ngram(self):
pytorch_config = dict(
disable_overlap_scheduler=True,
cuda_graph_config=CudaGraphConfig(batch_sizes=[1]),
)
kv_cache_config = KvCacheConfig(enable_block_reuse=False,
free_gpu_memory_fraction=0.8)
spec_config = NGramDecodingConfig(
max_draft_len=4,
max_matching_ngram_size=2,
is_keep_all=True,
is_use_oldest=True,
is_public_pool=True,
)
with LLM(model=self.MODEL_PATH,
**pytorch_config,
kv_cache_config=kv_cache_config,
speculative_config=spec_config,
max_batch_size=16) as llm:
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_blackwell
@parametrize_with_ids("torch_compile", [False, True])
@parametrize_with_ids("attn_backend", ["TRTLLM"])
def test_nvfp4_kv(self, attn_backend, torch_compile):
torch_compile_config = TorchCompileConfig(
enable_fullgraph=True,
enable_piecewise_cuda_graph=True,
max_num_streams=3) if torch_compile else None
pytorch_config = dict(
torch_compile_config=torch_compile_config,
cuda_graph_config=CudaGraphConfig(enable_padding=torch_compile,
batch_sizes=[4]),
attn_backend=attn_backend,
disable_overlap_scheduler=torch_compile,
)
pytorch_config["kv_cache_config"] = KvCacheConfig(dtype="nvfp4")
with LLM(f"{llm_models_root()}/Llama-3_1-8B-Instruct_nvfp4_fp8_hf",
**pytorch_config) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.FP8
assert llm.args.quant_config.kv_cache_quant_algo == QuantAlgo.NVFP4
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@pytest.mark.parametrize("backend", ["xgrammar", "llguidance"])
def test_guided_decoding(self, backend: str, mocker):
mocker.patch.dict(os.environ, {"TRTLLM_XGUIDANCE_LENIENT": "1"})
llm = LLM(self.MODEL_PATH, guided_decoding_backend=backend)
with llm:
task = JsonModeEval(self.MODEL_NAME)
task.evaluate(llm)
@pytest.mark.timeout(7200)
@pytest.mark.skip_less_device(4)
@pytest.mark.parametrize("backend", ["xgrammar", "llguidance"])
def test_guided_decoding_4gpus(self, backend: str, mocker):
mocker.patch.dict(os.environ, {"TRTLLM_XGUIDANCE_LENIENT": "1"})
with LLM(self.MODEL_PATH,
guided_decoding_backend=backend,
tensor_parallel_size=2,
pipeline_parallel_size=2) as llm:
task = JsonModeEval(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_hopper
@parametrize_with_ids("eagle3_one_model", [True, False])
@pytest.mark.parametrize("backend", ["xgrammar", "llguidance"])
def test_guided_decoding_with_eagle3(self, backend: str,
eagle3_one_model: bool, mocker):
mocker.patch.dict(os.environ, {"TRTLLM_XGUIDANCE_LENIENT": "1"})
kv_cache_config = KvCacheConfig(free_gpu_memory_fraction=0.8)
cuda_graph_config = CudaGraphConfig(enable_padding=True)
spec_config = EagleDecodingConfig(
max_draft_len=3,
speculative_model_dir=
f"{llm_models_root()}/EAGLE3-LLaMA3.1-Instruct-8B",
eagle3_one_model=eagle3_one_model)
llm = LLM(
self.MODEL_PATH,
guided_decoding_backend=backend,
kv_cache_config=kv_cache_config,
cuda_graph_config=cuda_graph_config,
enable_chunked_prefill=True,
speculative_config=spec_config,
# Two-model eagle3 does not support overlap scheduler
disable_overlap_scheduler=not eagle3_one_model)
with llm:
task = JsonModeEval(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_hopper
@pytest.mark.parametrize("backend", ["xgrammar", "llguidance"])
def test_guided_decoding_with_ngram(self, backend: str, mocker):
mocker.patch.dict(os.environ, {"TRTLLM_XGUIDANCE_LENIENT": "1"})
kv_cache_config = KvCacheConfig(free_gpu_memory_fraction=0.8)
cuda_graph_config = CudaGraphConfig(enable_padding=True)
spec_config = NGramDecodingConfig(max_draft_len=3,
max_matching_ngram_size=3)
llm = LLM(self.MODEL_PATH,
guided_decoding_backend=backend,
kv_cache_config=kv_cache_config,
cuda_graph_config=cuda_graph_config,
enable_chunked_prefill=True,
speculative_config=spec_config,
disable_overlap_scheduler=True)
with llm:
task = JsonModeEval(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_hopper
def test_auto_spec_decode(self):
pytorch_config = {
"cuda_graph_config":
CudaGraphConfig(batch_sizes=[1, 32, 64], enable_padding=True)
}
kv_cache_config = KvCacheConfig(enable_block_reuse=False,
free_gpu_memory_fraction=0.5)
spec_config = AutoDecodingConfig()
with LLM(model=self.MODEL_PATH,
**pytorch_config,
kv_cache_config=kv_cache_config,
speculative_config=spec_config,
max_batch_size=64) as llm:
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@parametrize_with_ids("disable_overlap_scheduler", [False, True])
@parametrize_with_ids(
"enable_cuda_graph,enable_padding",
[
(False, False), # No CUDA Graph (padding irrelevant)
(True, False), # CUDA Graph without padding
(True, True), # CUDA Graph with padding
])
def test_auto_dtype_beam_search(self, enable_cuda_graph, enable_padding,
disable_overlap_scheduler):
max_beam_width = 2
sampling_params = SamplingParams(n=max_beam_width,
best_of=max_beam_width,
use_beam_search=True)
if enable_cuda_graph:
# enable_padding only matters when CUDA Graph is enabled
if enable_padding:
batch_sizes = [
1, 8
] # Need batch_size != max_batch_size to enable padding
else:
batch_sizes = [1, 2, 4, 8]
cuda_graph_config = CudaGraphConfig(batch_sizes=batch_sizes,
enable_padding=enable_padding)
else:
cuda_graph_config = None
with LLM(
model=self.MODEL_PATH,
kv_cache_config=KvCacheConfig(free_gpu_memory_fraction=0.5),
max_batch_size=max_beam_width,
max_seq_len=2048,
max_beam_width=max_beam_width,
disable_overlap_scheduler=disable_overlap_scheduler,
cuda_graph_config=cuda_graph_config,
) as llm:
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm,
sampling_params=sampling_params,
extra_acc_spec="beam_width=2")
@skip_pre_hopper
@parametrize_with_ids("disable_overlap_scheduler", [False, True])
@parametrize_with_ids(
"enable_cuda_graph,enable_padding",
[
(False, False), # No CUDA Graph (padding irrelevant)
(True, False), # CUDA Graph without padding
(True, True), # CUDA Graph with padding
])
def test_fp8_beam_search(self, enable_cuda_graph, enable_padding,
disable_overlap_scheduler):
model_path = f"{llm_models_root()}/llama-3.1-model/Llama-3.1-8B-Instruct-FP8"
max_beam_width = 2
sampling_params = SamplingParams(n=max_beam_width,
best_of=max_beam_width,
use_beam_search=True)
if enable_cuda_graph:
# enable_padding only matters when CUDA Graph is enabled
if enable_padding:
batch_sizes = [
1, 8
] # Need batch_size != max_batch_size to enable padding
else:
batch_sizes = [1, 2, 4, 8]
cuda_graph_config = CudaGraphConfig(batch_sizes=batch_sizes,
enable_padding=enable_padding)
else:
cuda_graph_config = None
llm = LLM(
model=model_path,
kv_cache_config=KvCacheConfig(free_gpu_memory_fraction=0.5),
max_batch_size=max_beam_width,
max_seq_len=2048,
max_beam_width=max_beam_width,
disable_overlap_scheduler=disable_overlap_scheduler,
cuda_graph_config=cuda_graph_config,
)
with llm:
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm,
sampling_params=sampling_params,
extra_acc_spec="beam_width=2")
class TestLlama3_2_1B(LlmapiAccuracyTestHarness):
MODEL_NAME = "meta-llama/Llama-3.2-1B"
MODEL_PATH = f"{llm_models_root()}/llama-3.2-models/Llama-3.2-1B"
EXAMPLE_FOLDER = "models/core/llama"
def test_auto_dtype(self):
with LLM(self.MODEL_PATH) as llm:
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_ada
def test_fp8_prequantized(self):
model_path = f"{llm_models_root()}/llama-3.2-models/Llama-3.2-1B-FP8"
with LLM(model_path) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.FP8
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_hopper
@pytest.mark.skip_less_device(4)
@pytest.mark.parametrize("disable_overlap_scheduler", [True, False])
@pytest.mark.parametrize("pp_size", [2, 4], ids=["pp2", "pp4"])
def test_return_logits_pp(self, pp_size, disable_overlap_scheduler):
prompts = ["A B C"]
llm = LLM(model=self.MODEL_PATH,
pipeline_parallel_size=pp_size,
disable_overlap_scheduler=disable_overlap_scheduler)
sampling_params = SamplingParams(max_tokens=8,
return_context_logits=True,
return_generation_logits=True,
logprobs=True)
with llm:
for output in llm.generate(prompts,
sampling_params=sampling_params):
assert output.context_logits is not None
# NOTE: prompt_token_ids of "A B C" becomes [1, 319, 350, 315]
expected_len = len(prompts[0].split()) + 1
assert expected_len == output.context_logits.shape[0]
gen_logits = output.outputs[0].generation_logits
assert gen_logits is not None
assert gen_logits.ndim == 2
assert gen_logits.shape[0] == sampling_params.max_tokens
assert torch.argmax(
gen_logits, dim=1).tolist() == output.outputs[0].token_ids
assert len(
output.outputs[0].logprobs) == sampling_params.max_tokens
class TestLlama3_2_3B(LlmapiAccuracyTestHarness):
MODEL_NAME = "meta-llama/Llama-3.2-3B"
MODEL_PATH = f"{llm_models_root()}/llama-3.2-models/Llama-3.2-3B"
EXAMPLE_FOLDER = "models/core/llama"
def test_auto_dtype(self):
with LLM(self.MODEL_PATH) as llm:
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm)
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_hopper
def test_fp8_prequantized(self):
model_path = f"{llm_models_root()}/llama-3.2-models/Llama-3.2-3B-Instruct-FP8"
with LLM(model_path) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.FP8
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm)
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
@pytest.mark.timeout(7200)
@pytest.mark.skip_less_host_memory(1000000)
@pytest.mark.skip_less_device_memory(80000)
# 1TB is basic requirement for large model tests. CG4 120G only has 800G host memory, and 480G is shared with GPUs. the test will cause the system crash.
class TestLlama3_3_70BInstruct(LlmapiAccuracyTestHarness):
MODEL_NAME = "meta-llama/Llama-3.3-70B-Instruct"
@pytest.mark.skip_less_mpi_world_size(8)
def test_auto_dtype_tp8(self):
model_path = f"{llm_models_root()}/llama-3.3-models/Llama-3.3-70B-Instruct"
with LLM(model_path, tensor_parallel_size=8) as llm:
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
task = GPQADiamond(self.MODEL_NAME)
task.evaluate(llm,
extra_evaluator_kwargs=dict(apply_chat_template=True))
@skip_pre_hopper
@pytest.mark.skip_less_mpi_world_size(8)
@parametrize_with_ids("eagle3_one_model", [True, False])
def test_fp8_eagle3_tp8(self, eagle3_one_model):
model_path = f"{llm_models_root()}/modelopt-hf-model-hub/Llama-3.3-70B-Instruct-fp8"
eagle_model_dir = f"{llm_models_root()}/EAGLE3-LLaMA3.3-Instruct-70B"
kv_cache_config = KvCacheConfig(free_gpu_memory_fraction=0.6)
spec_config = EagleDecodingConfig(max_draft_len=4,
speculative_model_dir=eagle_model_dir,
eagle3_one_model=eagle3_one_model)
pytorch_config = dict(
disable_overlap_scheduler=True,
cuda_graph_config=CudaGraphConfig(max_batch_size=1))
with LLM(model_path,
max_batch_size=16,
tensor_parallel_size=8,
speculative_config=spec_config,
kv_cache_config=kv_cache_config,
**pytorch_config) as llm:
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm)
@pytest.mark.skip_less_device(4)
@skip_pre_hopper
def test_fp8_tp4(self):
model_path = f"{llm_models_root()}/llama-3.3-models/Llama-3.3-70B-Instruct-FP8"
kv_cache_config = KvCacheConfig(free_gpu_memory_fraction=0.5)
with LLM(model_path,
tensor_parallel_size=4,
max_seq_len=8192,
max_batch_size=32,
kv_cache_config=kv_cache_config) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.FP8
sampling_params = SamplingParams(
max_tokens=256,
temperature=0.0,
add_special_tokens=False,
)
task = MMLU(self.MODEL_NAME)
task.evaluate(llm, sampling_params=sampling_params)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm, sampling_params=sampling_params)
task = GPQADiamond(self.MODEL_NAME)
task.evaluate(llm,
extra_evaluator_kwargs=dict(apply_chat_template=True))
@pytest.mark.skip_less_device(4)
@skip_pre_blackwell
def test_nvfp4_tp4(self):
model_path = f"{llm_models_root()}/llama-3.3-models/Llama-3.3-70B-Instruct-FP4"
kv_cache_config = KvCacheConfig(free_gpu_memory_fraction=0.5)
with LLM(model_path,
tensor_parallel_size=4,
max_batch_size=32,
kv_cache_config=kv_cache_config) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.NVFP4
sampling_params = SamplingParams(
max_tokens=256,
temperature=0.0,
add_special_tokens=False,
)
task = MMLU(self.MODEL_NAME)
task.evaluate(llm, sampling_params=sampling_params)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm, sampling_params=sampling_params)
task = GPQADiamond(self.MODEL_NAME)
task.evaluate(llm,
extra_evaluator_kwargs=dict(apply_chat_template=True))
class TestLlama4MaverickInstruct(LlmapiAccuracyTestHarness):
MODEL_NAME = "meta-llama/Llama-4-Maverick-17B-128E-Instruct"
MODEL_PATH = f"{llm_models_root()}/llama4-models/Llama-4-Maverick-17B-128E-Instruct"
@skip_pre_blackwell
@parametrize_with_ids("cuda_graph", [False, True])
@pytest.mark.parametrize(
"tp_size,pp_size,ep_size", [(8, 1, 1), (8, 1, 4), (8, 1, 8), (4, 1, 1),
(4, 1, 2), (4, 1, 4)],
ids=["tp8", "tp8ep4", "tp8ep8", "tp4", "tp4ep2", "tp4ep4"])
def test_auto_dtype(self, cuda_graph, tp_size, pp_size, ep_size):
if get_device_memory() < 270000 and get_device_count() < 8:
pytest.skip("Not enough memory for this test")
if get_device_count() != tp_size * pp_size:
pytest.skip("Device count mismatch with world size")
kv_cache_config = KvCacheConfig(free_gpu_memory_fraction=0.8)
with LLM(
self.MODEL_PATH,
tensor_parallel_size=tp_size,
# Keep this low to avoid warmup OOM in CI
max_seq_len=8192,
pipeline_parallel_size=pp_size,
moe_expert_parallel_size=ep_size,
kv_cache_config=kv_cache_config,
cuda_graph_config=CudaGraphConfig()
if cuda_graph else None) as llm:
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_blackwell
@pytest.mark.skip_less_device(8)
@parametrize_with_ids("attn_backend", ["TRTLLM", "FLASHINFER"])
def test_chunked_prefill(self, attn_backend):
pytorch_config = dict(attn_backend=attn_backend,
disable_overlap_scheduler=True)
with LLM(self.MODEL_PATH,
tensor_parallel_size=8,
pipeline_parallel_size=1,
moe_expert_parallel_size=1,
max_seq_len=8192,
enable_chunked_prefill=True,
max_num_tokens=256,
**pytorch_config) as llm:
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_hopper
@pytest.mark.skip_less_device_memory(80000)
@parametrize_with_ids("cuda_graph", [False, True])
@pytest.mark.parametrize(
"tp_size,pp_size,ep_size", [(8, 1, 1), (8, 1, 4), (8, 1, 8), (4, 1, 1),
(4, 1, 2), (4, 1, 4)],
ids=["tp8", "tp8ep4", "tp8ep8", "tp4", "tp4ep2", "tp4ep4"])
def test_fp8(self, cuda_graph, tp_size, pp_size, ep_size):
if get_device_memory() < 140000 and get_device_count() < 8:
pytest.skip("Not enough memory for this test")
if get_device_count() != tp_size * pp_size:
pytest.skip("Device count mismatch with world size")
with LLM(
f"{llm_models_root()}/llama4-models/nvidia/Llama-4-Maverick-17B-128E-Instruct-FP8",
tensor_parallel_size=tp_size,
# Keep this low to avoid warmup OOM in CI
max_seq_len=8192,
pipeline_parallel_size=pp_size,
moe_expert_parallel_size=ep_size,
cuda_graph_config=CudaGraphConfig()
if cuda_graph else None) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.FP8
assert llm.args.quant_config.kv_cache_quant_algo == QuantAlgo.FP8
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_hopper
@pytest.mark.skip_less_mpi_world_size(8)
@parametrize_with_ids("cuda_graph", [False, True])
@pytest.mark.parametrize("tp_size,pp_size,ep_size", [(8, 1, 8)],
ids=["tp8ep8"])
def test_fp8_chunked_prefill(self, cuda_graph, tp_size, pp_size, ep_size):
with LLM(
f"{llm_models_root()}/llama4-models/nvidia/Llama-4-Maverick-17B-128E-Instruct-FP8",
tensor_parallel_size=tp_size,
# Keep this low to avoid warmup OOM in CI
max_seq_len=8192,
pipeline_parallel_size=pp_size,
moe_expert_parallel_size=ep_size,
enable_chunked_prefill=True,
max_num_tokens=256,
cuda_graph_config=CudaGraphConfig()
if cuda_graph else None) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.FP8
assert llm.args.quant_config.kv_cache_quant_algo == QuantAlgo.FP8
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_hopper
@pytest.mark.skip_less_mpi_world_size(8)
@parametrize_with_ids("torch_compile", [True, False])
@pytest.mark.parametrize("tp_size,pp_size,ep_size", [(8, 1, 1)],
ids=["tp8"])
def test_fp8_eagle3(self, tp_size, pp_size, ep_size, torch_compile):
model_path = f"{llm_models_root()}/llama4-models/nvidia/Llama-4-Maverick-17B-128E-Instruct-FP8"
eagle_model_dir = f"{llm_models_root()}/Llama-4-Maverick-17B-128E-Eagle3"
spec_config = EagleDecodingConfig(max_draft_len=3,
speculative_model_dir=eagle_model_dir)
kv_cache_config = KvCacheConfig(enable_block_reuse=False,
free_gpu_memory_fraction=0.75)
torch_compile_config = TorchCompileConfig(
enable_fullgraph=True,
enable_piecewise_cuda_graph=True,
capture_num_tokens=[2048, 8192],
max_num_streams=3) if torch_compile else None
pytorch_config = dict(
cuda_graph_config=CudaGraphConfig(max_batch_size=8),
enable_attention_dp=False,
torch_compile_config=torch_compile_config)
with LLM(model_path,
kv_cache_config=kv_cache_config,
tensor_parallel_size=tp_size,
pipeline_parallel_size=pp_size,
moe_expert_parallel_size=ep_size,
**pytorch_config,
speculative_config=spec_config) as llm:
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
@pytest.mark.skip_less_device_memory(80000)
@pytest.mark.skip_less_host_memory(100000)
class TestLlama4ScoutInstruct(LlmapiAccuracyTestHarness):
MODEL_NAME = "meta-llama/Llama-4-Scout-17B-16E-Instruct"
@skip_pre_hopper
@parametrize_with_ids("cuda_graph", [False, True])
@pytest.mark.parametrize(
"tp_size,pp_size,ep_size", [(8, 1, 1), (8, 1, 4), (8, 1, 8), (4, 1, 1),
(4, 1, 2), (4, 1, 4)],
ids=["tp8", "tp8ep4", "tp8ep8", "tp4", "tp4ep2", "tp4ep4"])
def test_auto_dtype(self, cuda_graph, tp_size, pp_size, ep_size):
if get_device_count() != tp_size * pp_size:
pytest.skip("Device count mismatch with world size")
model_path = f"{llm_models_root()}/llama4-models/Llama-4-Scout-17B-16E-Instruct"
with LLM(
model_path,
tensor_parallel_size=tp_size,
# Keep this low to avoid warmup OOM in CI
max_seq_len=8192,
pipeline_parallel_size=pp_size,
moe_expert_parallel_size=ep_size,
cuda_graph_config=CudaGraphConfig()
if cuda_graph else None) as llm:
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_hopper
@parametrize_with_ids("cuda_graph", [True])
@pytest.mark.parametrize("tp_size,pp_size,ep_size", [(8, 1, 8), (4, 1, 1)],
ids=["tp8ep8", "tp4"])
def test_fp8(self, cuda_graph, tp_size, pp_size, ep_size):
if get_device_count() != tp_size * pp_size:
pytest.skip("Device count mismatch with world size")
model_path = f"{llm_models_root()}/llama4-models/Llama-4-Scout-17B-16E-Instruct-FP8"
with LLM(
model_path,
tensor_parallel_size=tp_size,
# Keep this low to avoid warmup OOM in CI
max_seq_len=8192,
pipeline_parallel_size=pp_size,
moe_expert_parallel_size=ep_size,
kv_cache_config=KvCacheConfig(free_gpu_memory_fraction=0.8),
cuda_graph_config=CudaGraphConfig()
if cuda_graph else None) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.FP8
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_blackwell
@parametrize_with_ids("cuda_graph", [True])
@pytest.mark.parametrize("tp_size,pp_size,ep_size", [(8, 1, 8), (4, 1, 1)],
ids=["tp8ep8", "tp4"])
def test_fp4(self, cuda_graph, tp_size, pp_size, ep_size):
if get_device_count() != tp_size * pp_size:
pytest.skip("Device count mismatch with world size")
model_path = f"{llm_models_root()}/llama4-models/Llama-4-Scout-17B-16E-Instruct-FP4"
with LLM(
model_path,
tensor_parallel_size=tp_size,
# Keep this low to avoid warmup OOM in CI
max_seq_len=8192,
pipeline_parallel_size=pp_size,
moe_expert_parallel_size=ep_size,
cuda_graph_config=CudaGraphConfig()
if cuda_graph else None) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.NVFP4
assert llm.args.quant_config.kv_cache_quant_algo == QuantAlgo.FP8
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_hopper
@pytest.mark.skip_less_mpi_world_size(4)
@parametrize_with_ids("cuda_graph", [True])
@pytest.mark.parametrize("tp_size,pp_size,ep_size", [(4, 1, 4)],
ids=["tp4ep4"])
def test_fp8_chunked_prefill(self, cuda_graph, tp_size, pp_size, ep_size):
with LLM(
f"{llm_models_root()}/llama4-models/Llama-4-Scout-17B-16E-Instruct-FP8",
tensor_parallel_size=tp_size,
max_seq_len=22000,
pipeline_parallel_size=pp_size,
moe_expert_parallel_size=ep_size,
enable_chunked_prefill=True,
max_num_tokens=256,
cuda_graph_config=CudaGraphConfig()
if cuda_graph else None) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.FP8
assert llm.args.quant_config.kv_cache_quant_algo == QuantAlgo.FP8
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_blackwell
@pytest.mark.skip_less_mpi_world_size(4)
@parametrize_with_ids("cuda_graph", [True])
@pytest.mark.parametrize("tp_size,pp_size,ep_size", [(4, 1, 4)],
ids=["tp4ep4"])
def test_fp4_chunked_prefill(self, cuda_graph, tp_size, pp_size, ep_size):
with LLM(
f"{llm_models_root()}/llama4-models/Llama-4-Scout-17B-16E-Instruct-FP4",
tensor_parallel_size=tp_size,
pipeline_parallel_size=pp_size,
moe_expert_parallel_size=ep_size,
max_seq_len=22000,
enable_chunked_prefill=True,
max_num_tokens=256,
cuda_graph_config=CudaGraphConfig()
if cuda_graph else None) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.NVFP4
assert llm.args.quant_config.kv_cache_quant_algo == QuantAlgo.FP8
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
class TestMistral7B(LlmapiAccuracyTestHarness):
MODEL_NAME = "mistralai/Mistral-7B-v0.1"
MODEL_PATH = f"{llm_models_root()}/mistral-7b-v0.1"
def test_auto_dtype(self):
with LLM(self.MODEL_PATH) as llm:
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm)
class TestMistralSmall24B(LlmapiAccuracyTestHarness):
MODEL_NAME = "mistralai/Mistral-Small-3.1-24B-Instruct-2503"
MODEL_PATH = f"{llm_models_root()}/Mistral-Small-3.1-24B-Instruct-2503"
@pytest.mark.skip_less_device_memory(80000)
def test_auto_dtype(self):
kv_cache_config = KvCacheConfig(free_gpu_memory_fraction=0.75)
with LLM(self.MODEL_PATH, kv_cache_config=kv_cache_config) as llm:
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm)
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_ada
@pytest.mark.skip_less_device_memory(80000)
def test_fp8(self):
kv_cache_config = KvCacheConfig(free_gpu_memory_fraction=0.75)
model_path = f"{llm_models_root()}/Mistral-Small-3.1-24B-Instruct-2503-fp8"
with LLM(model_path, kv_cache_config=kv_cache_config) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.FP8
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm)
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
class TestMinistral8BInstruct(LlmapiAccuracyTestHarness):
MODEL_NAME = "mistralai/Ministral-8B-Instruct-2410"
MODEL_PATH = f"{llm_models_root()}/Ministral-8B-Instruct-2410"
def test_auto_dtype(self):
with LLM(self.MODEL_PATH) as llm:
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
@skip_pre_ada
def test_fp8(self):
# Test with FP8 quantization if pre-quantized model is available
model_path = f"{llm_models_root()}/Ministral-8B-Instruct-2410-FP8"
try:
with LLM(model_path) as llm:
assert llm.args.quant_config.quant_algo == QuantAlgo.FP8
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
except (FileNotFoundError, OSError):
pytest.skip("FP8 pre-quantized Ministral-8B model not available")
@skip_post_blackwell
@skip_pre_hopper
class TestGemma3_27BInstruct(LlmapiAccuracyTestHarness):
MODEL_NAME = "google/gemma-3-27b-it"
MODEL_PATH = f"{llm_models_root()}/gemma/gemma-3-27b-it/"
def test_auto_dtype(self):
# Disabling kv cache reuse as a WAR to deal with gaps in kernel support for Gemma3's non-inclusive sliding window size.
kv_cache_config = KvCacheConfig(
enable_block_reuse=False,
enable_partial_reuse=False,
free_gpu_memory_fraction=0.5,
)
# We use FlashInfer as the attention backend for Gemma3 VLM to support custom mask for images.
# So, testing with it here.
with LLM(self.MODEL_PATH,
kv_cache_config=kv_cache_config,
attn_backend="FLASHINFER",
cuda_graph_config=None,
max_batch_size=128,
max_seq_len=4096) as llm:
task = CnnDailymail(self.MODEL_NAME)
task.evaluate(llm)
task = MMLU(self.MODEL_NAME)
task.evaluate(llm)
task = GSM8K(self.MODEL_NAME)
task.evaluate(llm)