1515
1616import json
1717import os
18+ from types import SimpleNamespace
1819from unittest .mock import patch
1920
20- from vllm .config import VllmConfig
21+ from vllm .config import KVTransferConfig , VllmConfig
2122
2223from tests .ut .base import TestBase
2324from vllm_ascend .ascend_config import clear_ascend_config , get_ascend_config , init_ascend_config
@@ -38,6 +39,20 @@ def wrapper(*args, **kwargs):
3839
3940 return wrapper
4041
42+ @staticmethod
43+ def _make_model_config (
44+ total_num_attention_heads : int = 32 ,
45+ total_num_kv_heads : int = 8 ,
46+ is_deepseek_mla : bool = False ,
47+ ):
48+ return SimpleNamespace (
49+ is_deepseek_mla = is_deepseek_mla ,
50+ use_mla = is_deepseek_mla ,
51+ enforce_eager = True ,
52+ model_arch_config = SimpleNamespace (total_num_attention_heads = total_num_attention_heads ),
53+ get_total_num_kv_heads = lambda : total_num_kv_heads ,
54+ )
55+
4156 @_clean_up_ascend_config
4257 @patch ("vllm_ascend.platform.NPUPlatform.check_and_update_config" )
4358 def test_init_ascend_config_without_additional_config (self , mock_fix_incompatible_config ):
@@ -94,6 +109,103 @@ def test_init_ascend_config_enable_npugraph_ex(self, mock_fix_incompatible_confi
94109 self .assertTrue (ascend_compilation_config .enable_npugraph_ex )
95110 self .assertTrue (ascend_compilation_config .enable_static_kernel )
96111
112+ @_clean_up_ascend_config
113+ @patch ("vllm_ascend.platform.NPUPlatform.check_and_update_config" )
114+ def test_init_ascend_config_rejects_mooncake_c8_kv_cache_consumer (self , mock_fix_incompatible_config ):
115+ test_vllm_config = VllmConfig ()
116+ test_vllm_config .kv_transfer_config = KVTransferConfig (
117+ kv_connector = "MooncakeConnectorV1" ,
118+ kv_role = "kv_consumer" ,
119+ )
120+ test_vllm_config .quant_config = SimpleNamespace (enable_c8_quant = True )
121+ test_vllm_config .model_config = self ._make_model_config ()
122+
123+ with self .assertRaisesRegex (ValueError , "does not support C8 KV cache quantization" ):
124+ init_ascend_config (test_vllm_config )
125+
126+ @_clean_up_ascend_config
127+ @patch ("vllm_ascend.platform.NPUPlatform.check_and_update_config" )
128+ def test_init_ascend_config_rejects_multi_connector_mooncake_c8_consumer (self , mock_fix_incompatible_config ):
129+ test_vllm_config = VllmConfig ()
130+ test_vllm_config .kv_transfer_config = KVTransferConfig (
131+ kv_connector = "MultiConnector" ,
132+ kv_role = "kv_consumer" ,
133+ kv_connector_extra_config = {
134+ "connectors" : [
135+ {
136+ "kv_connector" : "MooncakeConnectorV1" ,
137+ "kv_role" : "kv_consumer" ,
138+ }
139+ ]
140+ },
141+ )
142+ test_vllm_config .quant_config = SimpleNamespace (enable_c8_quant = True )
143+ test_vllm_config .model_config = self ._make_model_config ()
144+
145+ with self .assertRaisesRegex (ValueError , "does not support C8 KV cache quantization" ):
146+ init_ascend_config (test_vllm_config )
147+
148+ @_clean_up_ascend_config
149+ @patch ("vllm_ascend.platform.NPUPlatform.check_and_update_config" )
150+ def test_init_ascend_config_allows_layerwise_c8_kv_cache_consumer (self , mock_fix_incompatible_config ):
151+ test_vllm_config = VllmConfig ()
152+ test_vllm_config .kv_transfer_config = KVTransferConfig (
153+ kv_connector = "MooncakeLayerwiseConnector" ,
154+ kv_role = "kv_consumer" ,
155+ )
156+ test_vllm_config .quant_config = SimpleNamespace (enable_c8_quant = True )
157+ test_vllm_config .model_config = self ._make_model_config ()
158+
159+ ascend_config = init_ascend_config (test_vllm_config )
160+
161+ self .assertIsNotNone (ascend_config )
162+
163+ @_clean_up_ascend_config
164+ @patch ("vllm_ascend.platform.NPUPlatform.check_and_update_config" )
165+ def test_init_ascend_config_allows_mha_mooncake_c8_kv_cache_consumer (self , mock_fix_incompatible_config ):
166+ test_vllm_config = VllmConfig ()
167+ test_vllm_config .kv_transfer_config = KVTransferConfig (
168+ kv_connector = "MooncakeConnectorV1" ,
169+ kv_role = "kv_consumer" ,
170+ )
171+ test_vllm_config .quant_config = SimpleNamespace (enable_c8_quant = True )
172+ test_vllm_config .model_config = self ._make_model_config (
173+ total_num_attention_heads = 8 ,
174+ total_num_kv_heads = 8 ,
175+ )
176+
177+ ascend_config = init_ascend_config (test_vllm_config )
178+
179+ self .assertIsNotNone (ascend_config )
180+
181+ @_clean_up_ascend_config
182+ @patch ("vllm_ascend.platform.NPUPlatform.check_and_update_config" )
183+ def test_init_ascend_config_rejects_mooncake_c8_kv_cache_producer (self , mock_fix_incompatible_config ):
184+ test_vllm_config = VllmConfig ()
185+ test_vllm_config .kv_transfer_config = KVTransferConfig (
186+ kv_connector = "MooncakeConnectorV1" ,
187+ kv_role = "kv_producer" ,
188+ )
189+ test_vllm_config .quant_config = SimpleNamespace (enable_c8_quant = True )
190+ test_vllm_config .model_config = self ._make_model_config ()
191+
192+ with self .assertRaisesRegex (ValueError , "does not support C8 KV cache quantization" ):
193+ init_ascend_config (test_vllm_config )
194+
195+ @_clean_up_ascend_config
196+ @patch ("vllm_ascend.platform.NPUPlatform.check_and_update_config" )
197+ def test_init_ascend_config_rejects_mooncake_c8_kv_cache_both_role (self , mock_fix_incompatible_config ):
198+ test_vllm_config = VllmConfig ()
199+ test_vllm_config .kv_transfer_config = KVTransferConfig (
200+ kv_connector = "MooncakeConnectorV1" ,
201+ kv_role = "kv_both" ,
202+ )
203+ test_vllm_config .quant_config = SimpleNamespace (enable_c8_quant = True )
204+ test_vllm_config .model_config = self ._make_model_config ()
205+
206+ with self .assertRaisesRegex (ValueError , "does not support C8 KV cache quantization" ):
207+ init_ascend_config (test_vllm_config )
208+
97209 @_clean_up_ascend_config
98210 @patch ("vllm_ascend.ascend_config.logger.info_once" )
99211 @patch ("vllm_ascend.platform.NPUPlatform.check_and_update_config" )
0 commit comments