@@ -334,7 +334,7 @@ def random_input_kwargs(config: Any) -> Tuple[Dict[str, Any], Callable]:
334334 "hidden_size" ,
335335 "pad_token_id" ,
336336 )
337- check_hasattr (config , "vision_config" , "image_token_index" )
337+ check_hasattr (config , "vision_config" , ( "image_token_index" , "image_token_id" ) )
338338 text_config = True
339339 else :
340340 check_hasattr (
@@ -348,7 +348,7 @@ def random_input_kwargs(config: Any) -> Tuple[Dict[str, Any], Callable]:
348348 "vision_config" ,
349349 )
350350 text_config = False
351- check_hasattr (config .vision_config , "image_size " , "num_channels" )
351+ check_hasattr (config .vision_config , ( "num_channels " , "in_chans" ) )
352352 kwargs = dict (
353353 batch_size = 2 ,
354354 sequence_length = 43 ,
@@ -410,18 +410,34 @@ def random_input_kwargs(config: Any) -> Tuple[Dict[str, Any], Callable]:
410410 if config is None
411411 else (config .text_config .hidden_size if text_config else config .hidden_size )
412412 ),
413- width = 224 if config is None else config .vision_config .image_size ,
414- height = 224 if config is None else config .vision_config .image_size ,
415- num_channels = 3 if config is None else config .vision_config .num_channels ,
413+ width = (
414+ 224
415+ if config is None or not hasattr (config .vision_config , "image_size" )
416+ else config .vision_config .image_size
417+ ),
418+ height = (
419+ 224
420+ if config is None or not hasattr (config .vision_config , "image_size" )
421+ else config .vision_config .image_size
422+ ),
423+ num_channels = (
424+ 3 if config is None else _pick (config .vision_config , "num_channels" , "in_chans" )
425+ ),
416426 pad_token_id = (
417427 0
418- if config is None or not hasattr (config , "text_config" )
428+ if config is None
429+ or not hasattr (config , "text_config" )
430+ or not hasattr (config .text_config , "pad_token_id" )
419431 else config .text_config .pad_token_id
420432 ),
421433 image_token_index = (
422434 4
423- if config is None or not hasattr (config , "image_token_index" )
424- else config .image_token_index
435+ if config is None
436+ or (
437+ not hasattr (config , "image_token_index" )
438+ and not hasattr (config , "image_token_id" )
439+ )
440+ else _pick (config , "image_token_index" , "image_token_id" )
425441 ),
426442 )
427443 return kwargs , get_inputs
0 commit comments