44from  typing  import  Optional 
55
66import  pytest 
7- from  packaging .version  import  Version 
8- from  transformers  import  __version__  as  TRANSFORMERS_VERSION 
97
108from  vllm .assets .image  import  ImageAsset 
119from  vllm .config  import  ModelConfig 
1917from  vllm .multimodal .utils  import  encode_image_base64 
2018from  vllm .transformers_utils .tokenizer_group  import  TokenizerGroup 
2119
20+ from  ..models .registry  import  HF_EXAMPLE_MODELS 
2221from  ..utils  import  VLLM_PATH 
2322
2423EXAMPLES_DIR  =  VLLM_PATH  /  "examples" 
@@ -772,6 +771,7 @@ def get_conversation(is_hf: bool):
772771        enable_lora = False ,
773772        max_num_seqs = 5 ,
774773        max_input_length = None ,
774+         trust_remote_code = model_config .trust_remote_code ,
775775    )
776776    tokenizer  =  tokenizer_group .tokenizer 
777777
@@ -793,8 +793,8 @@ def get_conversation(is_hf: bool):
793793    )
794794
795795    vllm_result  =  apply_hf_chat_template (
796+         model_config ,
796797        tokenizer ,
797-         trust_remote_code = model_config .trust_remote_code ,
798798        conversation = conversation ,
799799        chat_template = None ,
800800        tools = None ,
@@ -813,13 +813,24 @@ def get_conversation(is_hf: bool):
813813@pytest .mark .parametrize ("use_tools" , [True , False ]) 
814814def  test_resolve_hf_chat_template (sample_json_schema , model , use_tools ):
815815    """checks that chat_template is a dict type for HF models.""" 
816+     model_info  =  HF_EXAMPLE_MODELS .find_hf_info (model )
817+     model_info .check_available_online (on_fail = "skip" )
818+ 
819+     model_config  =  ModelConfig (
820+         model ,
821+         tokenizer = model_info .tokenizer  or  model ,
822+         tokenizer_mode = model_info .tokenizer_mode ,
823+         trust_remote_code = model_info .trust_remote_code ,
824+         hf_overrides = model_info .hf_overrides ,
825+     )
816826
817827    # Build the tokenizer group and grab the underlying tokenizer 
818828    tokenizer_group  =  TokenizerGroup (
819829        model ,
820830        enable_lora = False ,
821831        max_num_seqs = 5 ,
822832        max_input_length = None ,
833+         trust_remote_code = model_config .trust_remote_code ,
823834    )
824835    tokenizer  =  tokenizer_group .tokenizer 
825836
@@ -834,10 +845,10 @@ def test_resolve_hf_chat_template(sample_json_schema, model, use_tools):
834845
835846    # Test detecting the tokenizer's chat_template 
836847    chat_template  =  resolve_hf_chat_template (
848+         model_config ,
837849        tokenizer ,
838850        chat_template = None ,
839851        tools = tools ,
840-         trust_remote_code = True ,
841852    )
842853    assert  isinstance (chat_template , str )
843854
@@ -857,24 +868,32 @@ def test_resolve_hf_chat_template(sample_json_schema, model, use_tools):
857868) 
858869# yapf: enable 
859870def  test_resolve_content_format_hf_defined (model , expected_format ):
860-     if  model  ==  QWEN25VL_MODEL_ID  and  Version (TRANSFORMERS_VERSION ) <  Version (
861-             "4.49.0" ):
862-         pytest .skip ("Qwen2.5-VL requires transformers>=4.49.0" )
871+     model_info  =  HF_EXAMPLE_MODELS .find_hf_info (model )
872+     model_info .check_available_online (on_fail = "skip" )
873+ 
874+     model_config  =  ModelConfig (
875+         model ,
876+         tokenizer = model_info .tokenizer  or  model ,
877+         tokenizer_mode = model_info .tokenizer_mode ,
878+         trust_remote_code = model_info .trust_remote_code ,
879+         hf_overrides = model_info .hf_overrides ,
880+     )
863881
864882    tokenizer_group  =  TokenizerGroup (
865883        model ,
866884        enable_lora = False ,
867885        max_num_seqs = 5 ,
868886        max_input_length = None ,
887+         trust_remote_code = model_config .trust_remote_code ,
869888    )
870889    tokenizer  =  tokenizer_group .tokenizer 
871890
872891    # Test detecting the tokenizer's chat_template 
873892    chat_template  =  resolve_hf_chat_template (
893+         model_config ,
874894        tokenizer ,
875895        chat_template = None ,
876896        tools = None ,
877-         trust_remote_code = True ,
878897    )
879898    assert  isinstance (chat_template , str )
880899
@@ -884,11 +903,70 @@ def test_resolve_content_format_hf_defined(model, expected_format):
884903    print (_try_extract_ast (chat_template ))
885904
886905    resolved_format  =  resolve_chat_template_content_format (
906+         model_config ,
907+         None ,  # Test detecting the tokenizer's chat_template 
908+         None ,
909+         "auto" ,
910+         tokenizer ,
911+     )
912+ 
913+     assert  resolved_format  ==  expected_format 
914+ 
915+ 
916+ # yapf: disable 
917+ @pytest .mark .parametrize ( 
918+     ("model" , "expected_format" ), 
919+     [("Salesforce/blip2-opt-2.7b" , "string" ), 
920+      ("facebook/chameleon-7b" , "string" ), 
921+      ("deepseek-ai/deepseek-vl2-tiny" , "string" ), 
922+      ("microsoft/Florence-2-base" , "string" ), 
923+      ("adept/fuyu-8b" , "string" ), 
924+      ("google/paligemma-3b-mix-224" , "string" ), 
925+      ("Qwen/Qwen-VL" , "string" ), 
926+      ("Qwen/Qwen-VL-Chat" , "string" )], 
927+ ) 
928+ # yapf: enable 
929+ def  test_resolve_content_format_fallbacks (model , expected_format ):
930+     model_info  =  HF_EXAMPLE_MODELS .find_hf_info (model )
931+     model_info .check_available_online (on_fail = "skip" )
932+ 
933+     model_config  =  ModelConfig (
934+         model ,
935+         tokenizer = model_info .tokenizer  or  model ,
936+         tokenizer_mode = model_info .tokenizer_mode ,
937+         trust_remote_code = model_info .trust_remote_code ,
938+         hf_overrides = model_info .hf_overrides ,
939+     )
940+ 
941+     tokenizer_group  =  TokenizerGroup (
942+         model_config .tokenizer ,
943+         enable_lora = False ,
944+         max_num_seqs = 5 ,
945+         max_input_length = None ,
946+         trust_remote_code = model_config .trust_remote_code ,
947+     )
948+     tokenizer  =  tokenizer_group .tokenizer 
949+ 
950+     # Test detecting the tokenizer's chat_template 
951+     chat_template  =  resolve_hf_chat_template (
952+         model_config ,
953+         tokenizer ,
954+         chat_template = None ,
955+         tools = None ,
956+     )
957+     assert  isinstance (chat_template , str )
958+ 
959+     print ("[TEXT]" )
960+     print (chat_template )
961+     print ("[AST]" )
962+     print (_try_extract_ast (chat_template ))
963+ 
964+     resolved_format  =  resolve_chat_template_content_format (
965+         model_config ,
887966        None ,  # Test detecting the tokenizer's chat_template 
888967        None ,
889968        "auto" ,
890969        tokenizer ,
891-         trust_remote_code = True ,
892970    )
893971
894972    assert  resolved_format  ==  expected_format 
@@ -899,22 +977,14 @@ def test_resolve_content_format_hf_defined(model, expected_format):
899977    ("template_path" , "expected_format" ), 
900978    [("template_alpaca.jinja" , "string" ), 
901979     ("template_baichuan.jinja" , "string" ), 
902-      ("template_blip2.jinja" , "string" ), 
903-      ("template_chameleon.jinja" , "string" ), 
904980     ("template_chatglm.jinja" , "string" ), 
905981     ("template_chatglm2.jinja" , "string" ), 
906982     ("template_chatml.jinja" , "string" ), 
907-      ("template_deepseek_vl2.jinja" , "string" ), 
908983     ("template_dse_qwen2_vl.jinja" , "openai" ), 
909984     ("template_falcon_180b.jinja" , "string" ), 
910985     ("template_falcon.jinja" , "string" ), 
911-      ("template_florence2.jinja" , "string" ), 
912-      ("template_fuyu.jinja" , "string" ), 
913986     ("template_inkbot.jinja" , "string" ), 
914-      ("template_paligemma.jinja" , "string" ), 
915987     ("template_teleflm.jinja" , "string" ), 
916-      ("template_qwen_vl.jinja" , "string" ), 
917-      ("template_qwen_vl_chat.jinja" , "string" ), 
918988     ("template_vlm2vec.jinja" , "openai" ), 
919989     ("tool_chat_template_granite_20b_fc.jinja" , "string" ), 
920990     ("tool_chat_template_hermes.jinja" , "string" ), 
@@ -926,11 +996,18 @@ def test_resolve_content_format_hf_defined(model, expected_format):
926996) 
927997# yapf: enable 
928998def  test_resolve_content_format_examples (template_path , expected_format ):
999+     model_config  =  ModelConfig (
1000+         PHI3V_MODEL_ID ,  # Dummy 
1001+         tokenizer = PHI3V_MODEL_ID ,  # Dummy 
1002+         trust_remote_code = True ,
1003+     )
1004+ 
9291005    tokenizer_group  =  TokenizerGroup (
930-         PHI3V_MODEL_ID ,
1006+         PHI3V_MODEL_ID ,   # Dummy 
9311007        enable_lora = False ,
9321008        max_num_seqs = 5 ,
9331009        max_input_length = None ,
1010+         trust_remote_code = model_config .trust_remote_code ,
9341011    )
9351012    dummy_tokenizer  =  tokenizer_group .tokenizer 
9361013    dummy_tokenizer .chat_template  =  None 
@@ -944,11 +1021,11 @@ def test_resolve_content_format_examples(template_path, expected_format):
9441021    print (_try_extract_ast (chat_template ))
9451022
9461023    resolved_format  =  resolve_chat_template_content_format (
1024+         model_config ,
9471025        chat_template ,
9481026        None ,
9491027        "auto" ,
9501028        dummy_tokenizer ,
951-         trust_remote_code = True ,
9521029    )
9531030
9541031    assert  resolved_format  ==  expected_format 
0 commit comments