Skip to content

Init PD Rust LB (PO2) - #6437

Merged
hnyls2002 merged 39 commits into
mainfrom
lsyin-rust-lb
May 29, 2025
Merged

hnyls2002 merged 39 commits into
mainfrom
lsyin-rust-lb

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented May 19, 2025 •

Copy link
Copy Markdown
Collaborator

The power-of-two random choices implementation of PD LB. Currently, we use the occupied tokens and waiting tokens to denote the load for each server.

The PO2 will be improved in the following PRs, including the load reporter and algorithm part.

@hnyls2002 hnyls2002 self-assigned this May 19, 2025
@hnyls2002
hnyls2002 marked this pull request as draft May 19, 2025 21:12
@hnyls2002 hnyls2002 mentioned this pull request May 20, 2025
1 of 6 tasks

@fzyzcjy fzyzcjy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM since we do not (yet) need to squeeze out the last bit of performance here, thus only some nits

Comment thread bench.sh Resolved
Comment thread python/sglang/srt/managers/scheduler.py Resolved
Comment thread sgl-pdlb/src/server.rs Resolved
Comment thread sgl-pdlb/src/server.rs Resolved
Comment thread sgl-pdlb/src/server.rs Resolved
Comment thread sgl-pdlb/src/server.rs Resolved
Comment thread sgl-pdlb/src/strategy_lb.rs Resolved
Comment thread sgl-pdlb/src/server.rs Resolved
@slin1237

Copy link
Copy Markdown
Collaborator

lgtm overall
minor fixes and improvement can be done later

@fzyzcjy fzyzcjy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only (optional) nits, if in a hurry then just merge this first and update it later.

Comment thread python/sglang/srt/managers/io_struct.py Resolved
Comment thread sgl-pdlb/src/io_struct.rs Resolved
Comment thread sgl-pdlb/src/io_struct.rs
);
} else {
self.set_bootstrap_info(
BootstrapHost::Single(prefill_info.get_hostname()),

ghost May 28, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use From/Into, then can write prefill_info.get_hostname().into() and no need to repeat the Single

Comment thread sgl-pdlb/src/io_struct.rs Resolved
Comment thread sgl-pdlb/src/main.rs
timeout: 600,
};
let lb_state = server::LBState::new(lb_config.clone()).map_err(|e| anyhow::anyhow!(e))?;
let ret: anyhow::Result<()> = actix_web::rt::System::new().block_on(async move {

ghost May 29, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: looks like there are some code dup b/t this and lib.rs, shall we extract to a function

Comment thread sgl-pdlb/src/server.rs Outdated
async fn generate(
&self,
api_path: &str,
mut req: Box<dyn Bootstrap>,

ghost May 29, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mut req: Box<dyn Bootstrap>,
mut req: &impl Bootstrap,

(or use full generic)

Comment thread sgl-pdlb/src/server.rs
Comment on lines +264 to +267
Ok(HttpResponse::Ok().json(json!({
"prefill": prefill_loads.into_iter().map(|l| l.to_json()).collect::<Vec<_>>(),
"decode": decode_loads.into_iter().map(|l| l.to_json()).collect::<Vec<_>>()
})))

ghost May 29, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fn get_loads(){
  fn _transform(loads) { loads.into_iter().map().collec() }
      Ok(HttpResponse::Ok().json(json!({
        "prefill": _transform(prefill_loads)
        "decode": _transform(decode_loads)
    })))
}

Comment thread sgl-pdlb/src/strategy_lb.rs Resolved
let decode_index = rng.random_range(0..self.decode_servers.len());

(
self.prefill_servers[prefill_index].clone(),

ghost May 29, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe return (&EngineInfo, &EngineInfo) to avoid clone

}
}

async fn select_pd_pair_po2(&self, client: &reqwest::Client) -> (EngineInfo, EngineInfo) {

ghost May 29, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: may simplify a bit

ghost May 29, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eg naively

fn get_engine_and_load(servers: &[What]) {
  let server = servers[rng ... ];
  let load = self.get_load_from_engine(client, &a).await;
  (server, load)
}

fn select_pd_item_po2(servers: &[What]) {
  let (a, a_load) = get_engine_and_load();
  let (b, b_load) = get_engine_and_load();
  if a_load < b_load { a } else { b }
}

fn select_pd_pair_po2() {
  (
    select_pd_item_po2(&prefill_servers),
    select_pd_item_po2(&decode_servers),
  )
}

Comment thread sgl-pdlb/src/server.rs Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants