1414from dynamo .common .utils .topology import apply_topology_config
1515from dynamo .llm import ModelRuntimeConfig
1616from dynamo .mocker import MockEngineArgs , ReasoningConfig , SglangArgs , TrtllmArgs
17+ from dynamo .mocker .utils .kv_cache import get_model_max_context_length
1718
1819_DEFAULT_NUM_GPU_BLOCKS = 16384
1920_DEFAULT_MAX_NUM_SEQS = 256
@@ -183,14 +184,20 @@ def _resolve_raw_engine_args(
183184 * ,
184185 fallback_model_path : str | None = None ,
185186) -> dict :
187+ engine_type = raw .get ("engine_type" ) or "vllm"
188+ model_path = raw .get ("aic_model_path" ) or fallback_model_path
189+ if raw .get ("max_model_len" ) is None and engine_type == "vllm" and model_path :
190+ max_model_len = get_model_max_context_length (model_path )
191+ if max_model_len is not None :
192+ raw ["max_model_len" ] = max_model_len
193+
186194 if raw .get ("num_gpu_blocks" ) is not None :
187195 return raw
188196
189197 aic_backend = raw .get ("aic_backend" )
190198 if aic_backend is None :
191199 return raw
192200
193- engine_type = raw .get ("engine_type" ) or "vllm"
194201 sglang = raw .get ("sglang" )
195202 sglang_page_size = sglang .get ("page_size" ) if isinstance (sglang , dict ) else None
196203 raw ["num_gpu_blocks" ] = _estimate_aic_num_gpu_blocks (
@@ -201,7 +208,7 @@ def _resolve_raw_engine_args(
201208 aic_system = raw .get ("aic_system" ),
202209 aic_backend_version = raw .get ("aic_backend_version" ),
203210 aic_tp_size = raw .get ("aic_tp_size" ),
204- aic_model_path = raw . get ( "aic_model_path" ) or fallback_model_path ,
211+ aic_model_path = model_path ,
205212 aic_moe_tp_size = raw .get ("aic_moe_tp_size" ),
206213 aic_moe_ep_size = raw .get ("aic_moe_ep_size" ),
207214 aic_attention_dp_size = raw .get ("aic_attention_dp_size" ),
@@ -243,6 +250,10 @@ def build_mocker_engine_args(args: argparse.Namespace) -> MockEngineArgs:
243250 aic_moe_ep_size = getattr (args , "aic_moe_ep_size" , None )
244251 aic_attention_dp_size = getattr (args , "aic_attention_dp_size" , None )
245252 engine_type = getattr (args , "engine_type" , None ) or "vllm"
253+ max_model_len = getattr (args , "max_model_len" , None )
254+ model_path = getattr (args , "model_path" , None )
255+ if max_model_len is None and engine_type == "vllm" and model_path :
256+ max_model_len = get_model_max_context_length (model_path )
246257 num_gpu_blocks = _resolve_num_gpu_blocks (
247258 explicit_num_gpu_blocks = getattr (args , "num_gpu_blocks" , None ),
248259 engine_type = engine_type ,
@@ -267,6 +278,7 @@ def build_mocker_engine_args(args: argparse.Namespace) -> MockEngineArgs:
267278 engine_type = engine_type ,
268279 num_gpu_blocks = num_gpu_blocks ,
269280 block_size = getattr (args , "block_size" , 0 ) or 0 ,
281+ max_model_len = max_model_len ,
270282 max_num_seqs = getattr (args , "max_num_seqs" , _DEFAULT_MAX_NUM_SEQS ),
271283 max_num_batched_tokens = getattr (
272284 args , "max_num_batched_tokens" , _DEFAULT_MAX_NUM_BATCHED_TOKENS
@@ -349,8 +361,7 @@ def build_runtime_config(
349361 engine_args : MockEngineArgs ,
350362) -> tuple [int , ModelRuntimeConfig ]:
351363 rc = ModelRuntimeConfig ()
352- # Mocker does not enforce a model context limit.
353- rc .context_length = 0
364+ rc .context_length = engine_args .max_model_len or 0
354365 rc .total_kv_blocks = engine_args .num_gpu_blocks
355366 rc .max_num_seqs = engine_args .max_num_seqs
356367 if rc .max_num_seqs is None :
0 commit comments