Skip to content

Commit 9b2146e

Browse files
raviguptaamdravgupta
authored andcommitted
dpfix: moriio_dp_size + effective_dp_size + remote_dp_rank_override for 2P2D KV-notify (rebased onto upstream tip; upstream already has round-robin)
(cherry picked from commit 82dc981)
1 parent f105c15 commit 9b2146e

5 files changed

Lines changed: 58 additions & 7 deletions

File tree

‎src/config/types.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ pub struct RouterConfig {
3333
/// Intra-node data parallel size (number of DP replicas per worker URL). When > 1, the router will create multiple worker instances per URL, one for each DP rank.
3434
#[serde(default = "default_intra_node_data_parallel_size")]
3535
pub intra_node_data_parallel_size: usize,
36+
/// Total (cross-pod) MoRI-IO DP world size for Wide-EP. For multi-pod 2P2D
37+
/// DP=16 this is 16 (vs intra_node=8). Used to round-robin a single per-request
38+
/// DP rank over the FULL world and to stamp remote_dp_size/remote_dp_rank_override
39+
/// so the MoRIIO connector pins both prefill and decode legs to the same rank
40+
/// (no decode-side re-hash). 0 -> fall back to intra_node_data_parallel_size.
41+
#[serde(default)]
42+
pub moriio_dp_size: usize,
3643
/// The api key used for the authorization with the worker
3744
pub api_key: Option<String>,
3845
/// API key validation URLs (if set, incoming requests must validate against them)
@@ -885,6 +892,7 @@ impl Default for RouterConfig {
885892
worker_startup_timeout_secs: 600,
886893
worker_startup_check_interval_secs: 30,
887894
intra_node_data_parallel_size: 1,
895+
moriio_dp_size: 0,
888896
api_key: None,
889897
api_key_validation_urls: vec![],
890898
discovery: None,
@@ -1595,6 +1603,7 @@ mod tests {
15951603
worker_startup_timeout_secs: 60,
15961604
worker_startup_check_interval_secs: 5,
15971605
intra_node_data_parallel_size: 1,
1606+
moriio_dp_size: 0,
15981607
api_key: None,
15991608
api_key_validation_urls: vec![],
16001609
discovery: Some(DiscoveryConfig {
@@ -1662,6 +1671,7 @@ mod tests {
16621671
worker_startup_timeout_secs: 180,
16631672
worker_startup_check_interval_secs: 15,
16641673
intra_node_data_parallel_size: 1,
1674+
moriio_dp_size: 0,
16651675
api_key: None,
16661676
api_key_validation_urls: vec![],
16671677
discovery: Some(DiscoveryConfig {
@@ -1720,6 +1730,7 @@ mod tests {
17201730
worker_startup_timeout_secs: 600,
17211731
worker_startup_check_interval_secs: 20,
17221732
intra_node_data_parallel_size: 1,
1733+
moriio_dp_size: 0,
17231734
api_key: None,
17241735
api_key_validation_urls: vec![],
17251736
discovery: Some(DiscoveryConfig {

‎src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ impl Router {
196196
worker_startup_timeout_secs: self.worker_startup_timeout_secs,
197197
worker_startup_check_interval_secs: self.worker_startup_check_interval,
198198
intra_node_data_parallel_size: self.intra_node_data_parallel_size,
199+
moriio_dp_size: 0,
199200
api_key: self.api_key.clone(),
200201
api_key_validation_urls: self.api_key_validation_urls.clone(),
201202
discovery,

‎src/main.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ struct CliArgs {
200200
#[arg(long, default_value_t = 1)]
201201
intra_node_data_parallel_size: usize,
202202

203+
/// Total (cross-pod) MoRI-IO DP world size for Wide-EP (e.g. 16 for 2P2D DP=16,
204+
/// vs intra_node=8). 0 -> fall back to intra_node_data_parallel_size.
205+
#[arg(long, default_value_t = 0)]
206+
moriio_dp_size: usize,
207+
203208
/// API key for worker authorization
204209
#[arg(long)]
205210
api_key: Option<String>,
@@ -549,6 +554,7 @@ impl CliArgs {
549554
worker_startup_timeout_secs: self.worker_startup_timeout_secs,
550555
worker_startup_check_interval_secs: self.worker_startup_check_interval,
551556
intra_node_data_parallel_size: self.intra_node_data_parallel_size,
557+
moriio_dp_size: self.moriio_dp_size,
552558
api_key: self.api_key.clone(),
553559
api_key_validation_urls,
554560
discovery,

‎src/routers/http/router.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,6 +2673,7 @@ mod tests {
26732673
worker_startup_timeout_secs: 5,
26742674
worker_startup_check_interval_secs: 1,
26752675
intra_node_data_parallel_size: 1,
2676+
moriio_dp_size: 0,
26762677
api_key: None,
26772678
client: Client::new(),
26782679
retry_config: RetryConfig::default(),
@@ -2968,6 +2969,7 @@ mod tests {
29682969
worker_startup_timeout_secs: 5,
29692970
worker_startup_check_interval_secs: 1,
29702971
intra_node_data_parallel_size: 1,
2972+
moriio_dp_size: 0,
29712973
api_key: None,
29722974
client: Client::new(),
29732975
retry_config: RetryConfig::default(),

‎src/routers/http/vllm_pd_router.rs‎

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ pub struct VllmPDRouter {
8989
intra_node_data_parallel_size: usize,
9090
/// Round-robin counter for prefill DP rank selection
9191
prefill_dp_round_robin: Arc<AtomicUsize>,
92+
/// Total (cross-pod) MoRI-IO DP world size for Wide-EP (e.g. 16 for 2P2D DP=16).
93+
/// 0 -> fall back to intra_node_data_parallel_size.
94+
moriio_dp_size: usize,
9295
/// KV connector type
9396
kv_connector: KvConnector,
9497
/// Mooncake bootstrap info: prefill base_url -> MooncakePrefillInfo
@@ -234,6 +237,18 @@ impl VllmPDRouter {
234237
}
235238
}
236239

240+
/// Effective MoRI-IO DP world size: the total cross-pod DP size when configured
241+
/// (--moriio-dp-size, e.g. 16 for 2P2D DP=16), else the intra-node size. Used to
242+
/// round-robin a single per-request DP rank over the whole world and to stamp
243+
/// remote_dp_size so the MoRIIO connector's rank arithmetic matches the topology.
244+
fn effective_dp_size(&self) -> usize {
245+
if self.moriio_dp_size > 0 {
246+
self.moriio_dp_size
247+
} else {
248+
self.intra_node_data_parallel_size
249+
}
250+
}
251+
237252
/// Build kv_transfer_params for the prefill request.
238253
///
239254
/// Returns an error for MoRI-IO when no transfer mode has been registered yet, so that
@@ -271,7 +286,7 @@ impl VllmPDRouter {
271286
"do_remote_prefill": false,
272287
"remote_engine_id": serde_json::Value::Null,
273288
"remote_block_ids": serde_json::Value::Null,
274-
"remote_dp_size": self.intra_node_data_parallel_size,
289+
"remote_dp_size": self.effective_dp_size(),
275290
"remote_tp_size": remote_tp_size,
276291
"transfer_id": transfer_id.unwrap_or(""),
277292
});
@@ -287,7 +302,7 @@ impl VllmPDRouter {
287302
"remote_engine_id": serde_json::Value::Null,
288303
"remote_block_ids": serde_json::Value::Null,
289304
"transfer_id": transfer_id.unwrap_or(""),
290-
"remote_dp_size": self.intra_node_data_parallel_size,
305+
"remote_dp_size": self.effective_dp_size(),
291306
}))
292307
}
293308
}
@@ -345,12 +360,18 @@ impl VllmPDRouter {
345360
"remote_engine_id": serde_json::Value::Null,
346361
"remote_block_ids": serde_json::Value::Null,
347362
"transfer_id": transfer_id.unwrap_or(""),
348-
"remote_dp_size": self.intra_node_data_parallel_size,
363+
"remote_dp_size": self.effective_dp_size(),
349364
"remote_tp_size": tp_size,
350365
});
351-
if self.intra_node_data_parallel_size > 1 {
366+
if self.effective_dp_size() > 1 {
352367
if let Some(rank) = prefill_dp_rank {
353368
params["remote_dp_rank"] = json!(rank);
369+
// Sentinel: tell the MoRIIO connector (vllm#45043) to honor
370+
// this rank VERBATIM on both legs instead of re-hashing
371+
// blake2s(rid)%dp_size for the decode notify. Without it the
372+
// decode notify targets a different rank than the prefill was
373+
// pinned to -> "remote blocks never arrived" write expiry.
374+
params["remote_dp_rank_override"] = json!(true);
354375
}
355376
}
356377
Some(params)
@@ -1111,13 +1132,21 @@ impl VllmPDRouter {
11111132
let transfer_id = self.generate_transfer_id();
11121133

11131134
let (prefill_base_http, mut prefill_dp_rank) = dp_utils::parse_worker_url(prefill_http);
1114-
let (decode_base_http, decode_dp_rank) = dp_utils::parse_worker_url(decode_http);
1135+
let (decode_base_http, mut decode_dp_rank) = dp_utils::parse_worker_url(decode_http);
11151136

1116-
if self.intra_node_data_parallel_size > 1 && prefill_dp_rank.is_none() {
1137+
// Round-robin a single DP rank H over the FULL (cross-pod) DP world (effective_dp_size:
1138+
// --moriio-dp-size when set, else intra-node) so the prefill request is pinned to rank H
1139+
// and the decode kv_transfer_params carry remote_dp_rank=H (+ override).
1140+
let _eff_dp = self.effective_dp_size();
1141+
if _eff_dp > 1 && prefill_dp_rank.is_none() {
11171142
let rank = self.prefill_dp_round_robin.fetch_add(1, Ordering::Relaxed)
1118-
% self.intra_node_data_parallel_size;
1143+
% _eff_dp;
11191144
prefill_dp_rank = Some(rank);
11201145
}
1146+
// Pin decode to the SAME rank as prefill (override contract requires it).
1147+
if prefill_dp_rank.is_some() {
1148+
decode_dp_rank = prefill_dp_rank;
1149+
}
11211150

11221151
// Add kv_transfer_params for KV connector support at top level
11231152
prefill_request["kv_transfer_params"] = self.build_prefill_kv_transfer_params(
@@ -2134,6 +2163,7 @@ impl VllmPDRouter {
21342163
profiling_tasks: Arc::new(Mutex::new(HashMap::new())),
21352164
intra_node_data_parallel_size: ctx.router_config.intra_node_data_parallel_size,
21362165
prefill_dp_round_robin: Arc::new(AtomicUsize::new(0)),
2166+
moriio_dp_size: ctx.router_config.moriio_dp_size,
21372167
kv_connector,
21382168
mooncake_prefill_info: Arc::new(Mutex::new(HashMap::new())),
21392169
nixl_prefill_info: RwLock::new(HashMap::new()),
@@ -2228,6 +2258,7 @@ impl VllmPDRouter {
22282258
profiling_tasks: Arc::new(Mutex::new(HashMap::new())),
22292259
intra_node_data_parallel_size: ctx.router_config.intra_node_data_parallel_size,
22302260
prefill_dp_round_robin: Arc::new(AtomicUsize::new(0)),
2261+
moriio_dp_size: ctx.router_config.moriio_dp_size,
22312262
kv_connector,
22322263
mooncake_prefill_info,
22332264
nixl_prefill_info: RwLock::new(HashMap::new()),

0 commit comments

Comments
 (0)