@@ -1882,6 +1882,39 @@ def test_resolve_hf_chat_template_kwargs(sample_json_schema, model, expected_kwa
18821882 )
18831883 assert set (resolved_chat_template_kwargs .keys ()) == expected_kwargs
18841884
1885+ # Additional test: Verify HF base parameters work with **kwargs tokenizers
1886+ # This validates the fix for tokenizers like Kimi K2 that use **kwargs
1887+ # to receive standard HuggingFace parameters instead of declaring them explicitly
1888+ from vllm .entrypoints .chat_utils import _get_hf_base_chat_template_params
1889+
1890+ hf_base_params = _get_hf_base_chat_template_params ()
1891+ # Verify common HF parameters are in the base class
1892+ assert {"add_generation_prompt" , "tools" , "continue_final_message" }.issubset (
1893+ hf_base_params
1894+ ), f"Expected HF base params not found in { hf_base_params } "
1895+
1896+ # Test with a mock tokenizer that uses **kwargs (like Kimi K2)
1897+ class MockTokenizerWithKwargs :
1898+ def apply_chat_template (self , conversation , ** kwargs ):
1899+ return "mocked_output"
1900+
1901+ mock_tokenizer = MockTokenizerWithKwargs ()
1902+ mock_kwargs = {
1903+ "add_generation_prompt" : True ,
1904+ "tools" : tools ,
1905+ "continue_final_message" : False ,
1906+ "unknown_param" : "should_be_filtered" ,
1907+ }
1908+ resolved_mock = resolve_chat_template_kwargs (
1909+ mock_tokenizer , chat_template , mock_kwargs , raise_on_unexpected = False
1910+ )
1911+ # HF base params should pass through even with **kwargs tokenizer
1912+ assert "add_generation_prompt" in resolved_mock
1913+ assert "tools" in resolved_mock
1914+ assert "continue_final_message" in resolved_mock
1915+ # Unknown params should be filtered out
1916+ assert "unknown_param" not in resolved_mock
1917+
18851918
18861919# NOTE: Qwen2-Audio default chat template is specially defined inside
18871920# processor class instead of using `tokenizer_config.json`
0 commit comments