@@ -62,6 +62,65 @@ def matches_test_type(test_info: VLMTestInfo, test_type: VLMTestType):
6262 return matching_tests
6363
6464
65+ def get_model_type_cases (
66+ model_type : str ,
67+ test_info : VLMTestInfo ,
68+ test_type : VLMTestType ,
69+ ):
70+ # Ensure that something is wrapped as an iterable it's not already
71+ ensure_wrapped = lambda e : e if isinstance (e , (list , tuple )) else (e ,)
72+
73+ # This is essentially the same as nesting a bunch of mark.parametrize
74+ # decorators, but we do it programmatically to allow overrides for on
75+ # a per-model basis, while still being able to execute each of these
76+ # as individual test cases in pytest.
77+ iter_kwargs = OrderedDict (
78+ [
79+ ("model" , ensure_wrapped (test_info .models )),
80+ ("max_tokens" , ensure_wrapped (test_info .max_tokens )),
81+ ("num_logprobs" , ensure_wrapped (test_info .num_logprobs )),
82+ ("dtype" , ensure_wrapped (test_info .dtype )),
83+ (
84+ "distributed_executor_backend" ,
85+ ensure_wrapped (test_info .distributed_executor_backend ),
86+ ),
87+ ]
88+ )
89+
90+ # num_frames is video only
91+ if test_type == VLMTestType .VIDEO :
92+ iter_kwargs ["num_video_frames" ] = ensure_wrapped (test_info .num_video_frames )
93+ iter_kwargs ["needs_video_metadata" ] = ensure_wrapped (
94+ test_info .needs_video_metadata
95+ )
96+
97+ # No sizes passed for custom inputs, since inputs are directly provided
98+ if test_type not in (
99+ VLMTestType .CUSTOM_INPUTS ,
100+ VLMTestType .AUDIO ,
101+ ):
102+ wrapped_sizes = get_wrapped_test_sizes (test_info , test_type )
103+ if wrapped_sizes is None :
104+ raise ValueError (f"Sizes must be set for test type { test_type } " )
105+ iter_kwargs ["size_wrapper" ] = wrapped_sizes
106+
107+ # Otherwise expand the custom test options instead
108+ elif test_type == VLMTestType .CUSTOM_INPUTS :
109+ if test_info .custom_test_opts is None :
110+ raise ValueError ("Test has type CUSTOM_INPUTS, but none given" )
111+ iter_kwargs ["custom_test_opts" ] = test_info .custom_test_opts
112+
113+ # Wrap all model cases in a pytest parameter & pass marks through
114+ return [
115+ pytest .param (
116+ model_type ,
117+ ExpandableVLMTestArgs (** {k : v for k , v in zip (iter_kwargs .keys (), case )}),
118+ marks = test_info .marks if test_info .marks is not None else [],
119+ )
120+ for case in list (itertools .product (* iter_kwargs .values ()))
121+ ]
122+
123+
65124def get_parametrized_options (
66125 test_settings : dict [str , VLMTestInfo ],
67126 test_type : VLMTestType ,
@@ -76,64 +135,11 @@ def get_parametrized_options(
76135 test_settings , test_type , create_new_process_for_each_test
77136 )
78137
79- # Ensure that something is wrapped as an iterable it's not already
80- ensure_wrapped = lambda e : e if isinstance (e , (list , tuple )) else (e ,)
81-
82- def get_model_type_cases (model_type : str , test_info : VLMTestInfo ):
83- # This is essentially the same as nesting a bunch of mark.parametrize
84- # decorators, but we do it programmatically to allow overrides for on
85- # a per-model basis, while still being able to execute each of these
86- # as individual test cases in pytest.
87- iter_kwargs = OrderedDict (
88- [
89- ("model" , ensure_wrapped (test_info .models )),
90- ("max_tokens" , ensure_wrapped (test_info .max_tokens )),
91- ("num_logprobs" , ensure_wrapped (test_info .num_logprobs )),
92- ("dtype" , ensure_wrapped (test_info .dtype )),
93- (
94- "distributed_executor_backend" ,
95- ensure_wrapped (test_info .distributed_executor_backend ),
96- ),
97- ]
98- )
99-
100- # num_frames is video only
101- if test_type == VLMTestType .VIDEO :
102- iter_kwargs ["num_video_frames" ] = ensure_wrapped (test_info .num_video_frames )
103- iter_kwargs ["needs_video_metadata" ] = ensure_wrapped (
104- test_info .needs_video_metadata
105- )
106-
107- # No sizes passed for custom inputs, since inputs are directly provided
108- if test_type not in (VLMTestType .CUSTOM_INPUTS , VLMTestType .AUDIO ):
109- wrapped_sizes = get_wrapped_test_sizes (test_info , test_type )
110- if wrapped_sizes is None :
111- raise ValueError (f"Sizes must be set for test type { test_type } " )
112- iter_kwargs ["size_wrapper" ] = wrapped_sizes
113-
114- # Otherwise expand the custom test options instead
115- elif test_type == VLMTestType .CUSTOM_INPUTS :
116- if test_info .custom_test_opts is None :
117- raise ValueError ("Test has type CUSTOM_INPUTS, but none given" )
118- iter_kwargs ["custom_test_opts" ] = test_info .custom_test_opts
119-
120- # Wrap all model cases in a pytest parameter & pass marks through
121- return [
122- pytest .param (
123- model_type ,
124- ExpandableVLMTestArgs (
125- ** {k : v for k , v in zip (iter_kwargs .keys (), case )}
126- ),
127- marks = test_info .marks if test_info .marks is not None else [],
128- )
129- for case in list (itertools .product (* iter_kwargs .values ()))
130- ]
131-
132138 # Get a list per model type, where each entry contains a tuple of all of
133139 # that model type's cases, then flatten them into the top level so that
134140 # we can consume them in one mark.parametrize call.
135141 cases_by_model_type = [
136- get_model_type_cases (model_type , test_info )
142+ get_model_type_cases (model_type , test_info , test_type )
137143 for model_type , test_info in matching_tests .items ()
138144 ]
139145 return list (itertools .chain (* cases_by_model_type ))
0 commit comments