From 4ed57807c26e0128a649e1dc6689c9d84cce75a7 Mon Sep 17 00:00:00 2001 From: Simo Lin Date: Wed, 9 Jul 2025 21:52:06 -0700 Subject: [PATCH] [bugfix] add pd router policy validation (#7904) --- sgl-router/src/config/types.rs | 16 ++++++--------- sgl-router/src/config/validation.rs | 31 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/sgl-router/src/config/types.rs b/sgl-router/src/config/types.rs index 3926db5a2..9d57f439d 100644 --- a/sgl-router/src/config/types.rs +++ b/sgl-router/src/config/types.rs @@ -231,16 +231,12 @@ impl RouterConfig { PolicyConfig::PowerOfTwo { .. } => { crate::pd_types::PDSelectionPolicy::PowerOfTwo } - PolicyConfig::CacheAware { - cache_threshold, - balance_abs_threshold, - balance_rel_threshold, - .. - } => crate::pd_types::PDSelectionPolicy::CacheAware { - cache_threshold: *cache_threshold, - balance_abs_threshold: *balance_abs_threshold, - balance_rel_threshold: *balance_rel_threshold, - }, + PolicyConfig::CacheAware { .. } => { + return Err(ConfigError::IncompatibleConfig { + reason: "CacheAware policy is not supported in PD disaggregated mode" + .to_string(), + }); + } PolicyConfig::RoundRobin => { return Err(ConfigError::IncompatibleConfig { reason: "RoundRobin policy is not supported in PD disaggregated mode" diff --git a/sgl-router/src/config/validation.rs b/sgl-router/src/config/validation.rs index ed08c212c..838742722 100644 --- a/sgl-router/src/config/validation.rs +++ b/sgl-router/src/config/validation.rs @@ -270,6 +270,12 @@ impl ConfigValidator { .to_string(), }); } + (RoutingMode::PrefillDecode { .. }, PolicyConfig::CacheAware { .. }) => { + return Err(ConfigError::IncompatibleConfig { + reason: "CacheAware policy is not supported in PD disaggregated mode" + .to_string(), + }); + } _ => {} } @@ -471,6 +477,31 @@ mod tests { .contains("RoundRobin policy is not supported in PD disaggregated mode")); } + #[test] + fn test_validate_cache_aware_with_pd_mode() { + // CacheAware with PD mode should fail + let config = RouterConfig::new( + RoutingMode::PrefillDecode { + prefill_urls: vec![("http://prefill:8000".to_string(), None)], + decode_urls: vec!["http://decode:8000".to_string()], + }, + PolicyConfig::CacheAware { + cache_threshold: 0.5, + balance_abs_threshold: 32, + balance_rel_threshold: 1.1, + eviction_interval_secs: 60, + max_tree_size: 1000, + }, + ); + + let result = ConfigValidator::validate(&config); + assert!(result.is_err()); + assert!(result + .unwrap_err() + .to_string() + .contains("CacheAware policy is not supported in PD disaggregated mode")); + } + #[test] fn test_validate_power_of_two_with_regular_mode() { // PowerOfTwo with Regular mode should fail