Skip to content

Commit 4ed5780

Browse files
authored
[bugfix] add pd router policy validation (#7904)
1 parent dd445a4 commit 4ed5780

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

sgl-router/src/config/types.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,12 @@ impl RouterConfig {
231231
PolicyConfig::PowerOfTwo { .. } => {
232232
crate::pd_types::PDSelectionPolicy::PowerOfTwo
233233
}
234-
PolicyConfig::CacheAware {
235-
cache_threshold,
236-
balance_abs_threshold,
237-
balance_rel_threshold,
238-
..
239-
} => crate::pd_types::PDSelectionPolicy::CacheAware {
240-
cache_threshold: *cache_threshold,
241-
balance_abs_threshold: *balance_abs_threshold,
242-
balance_rel_threshold: *balance_rel_threshold,
243-
},
234+
PolicyConfig::CacheAware { .. } => {
235+
return Err(ConfigError::IncompatibleConfig {
236+
reason: "CacheAware policy is not supported in PD disaggregated mode"
237+
.to_string(),
238+
});
239+
}
244240
PolicyConfig::RoundRobin => {
245241
return Err(ConfigError::IncompatibleConfig {
246242
reason: "RoundRobin policy is not supported in PD disaggregated mode"

sgl-router/src/config/validation.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ impl ConfigValidator {
270270
.to_string(),
271271
});
272272
}
273+
(RoutingMode::PrefillDecode { .. }, PolicyConfig::CacheAware { .. }) => {
274+
return Err(ConfigError::IncompatibleConfig {
275+
reason: "CacheAware policy is not supported in PD disaggregated mode"
276+
.to_string(),
277+
});
278+
}
273279
_ => {}
274280
}
275281

@@ -471,6 +477,31 @@ mod tests {
471477
.contains("RoundRobin policy is not supported in PD disaggregated mode"));
472478
}
473479

480+
#[test]
481+
fn test_validate_cache_aware_with_pd_mode() {
482+
// CacheAware with PD mode should fail
483+
let config = RouterConfig::new(
484+
RoutingMode::PrefillDecode {
485+
prefill_urls: vec![("http://prefill:8000".to_string(), None)],
486+
decode_urls: vec!["http://decode:8000".to_string()],
487+
},
488+
PolicyConfig::CacheAware {
489+
cache_threshold: 0.5,
490+
balance_abs_threshold: 32,
491+
balance_rel_threshold: 1.1,
492+
eviction_interval_secs: 60,
493+
max_tree_size: 1000,
494+
},
495+
);
496+
497+
let result = ConfigValidator::validate(&config);
498+
assert!(result.is_err());
499+
assert!(result
500+
.unwrap_err()
501+
.to_string()
502+
.contains("CacheAware policy is not supported in PD disaggregated mode"));
503+
}
504+
474505
#[test]
475506
fn test_validate_power_of_two_with_regular_mode() {
476507
// PowerOfTwo with Regular mode should fail

0 commit comments

Comments
 (0)