-
Notifications
You must be signed in to change notification settings - Fork 141
feat(grpc): support batched completion prompts in the pipeline #1957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ use std::time::Instant; | |
|
|
||
| use async_trait::async_trait; | ||
| use axum::response::Response; | ||
| use futures::future::join_all; | ||
| use futures::future::{join_all, try_join_all}; | ||
| use tracing::{debug, error, info_span, Instrument}; | ||
|
|
||
| use super::PipelineStage; | ||
|
|
@@ -15,8 +15,8 @@ use crate::{ | |
| grpc::{ | ||
| common::stages::encode::EncodeDispatchPlan, | ||
| context::{ | ||
| ClientSelection, ExecutionPlan, ExecutionResult, LoadGuards, PdTiming, | ||
| RequestContext, WorkerSelection, | ||
| ClientSelection, ExecutionPlan, ExecutionPlanKind, ExecutionResult, LoadGuards, | ||
| PdTiming, RequestContext, WorkerSelection, | ||
| }, | ||
| proto_wrapper::{ | ||
| ProtoEmbedRequest, ProtoGenerateRequest, ProtoRequest, ProtoResponseVariant, | ||
|
|
@@ -167,7 +167,15 @@ impl PipelineStage for RequestExecutionStage { | |
| ) | ||
| })?; | ||
|
|
||
| ctx.state.load_guards = Some(LoadGuards::new(workers, ctx.input.headers.as_ref())); | ||
| let sub_requests = match &execution_plan { | ||
| ExecutionPlan::Batch { requests, .. } => requests.len(), | ||
| _ => 1, | ||
| }; | ||
| ctx.state.load_guards = Some(LoadGuards::scaled( | ||
| workers, | ||
| ctx.input.headers.as_ref(), | ||
| sub_requests, | ||
| )); | ||
|
|
||
| // Extract dispatch metadata for tracing span | ||
| let dispatch = ctx.state.dispatch.as_ref(); | ||
|
|
@@ -204,6 +212,10 @@ impl PipelineStage for RequestExecutionStage { | |
| self.execute_epd_dispatch(request, clients, workers, model, encode_dispatch) | ||
| .await | ||
| } | ||
| ExecutionPlan::Batch { kind, requests, .. } => { | ||
| self.execute_batch_dispatch(kind, requests, clients, workers, model) | ||
| .await | ||
| } | ||
| } | ||
| } | ||
| .instrument(span) | ||
|
|
@@ -329,6 +341,37 @@ impl RequestExecutionStage { | |
| }); | ||
| } | ||
|
|
||
| /// Dispatch one backend request per batched prompt concurrently, preserving | ||
| /// prompt order. Fail-fast: the first failed dispatch fails the batch and | ||
| /// drops the remaining streams (abort-on-drop reclaims them backend-side). | ||
| async fn execute_batch_dispatch( | ||
| &self, | ||
| kind: ExecutionPlanKind, | ||
| requests: Vec<ProtoGenerateRequest>, | ||
| clients: &ClientSelection, | ||
| workers: &WorkerSelection, | ||
| model: &str, | ||
| ) -> Result<ExecutionResult, Response> { | ||
| let dispatches = requests.into_iter().map(|request| { | ||
| let mut clients = clients.clone(); | ||
|
Comment on lines
+355
to
+356
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| async move { | ||
| match kind { | ||
| ExecutionPlanKind::Single => { | ||
| self.execute_single(request, &mut clients, workers).await | ||
| } | ||
| // Completion EPD carries no encode jobs; sub-requests dispatch as PD. | ||
| ExecutionPlanKind::PrefillDecode | ExecutionPlanKind::EncodePrefillDecode => { | ||
| self.execute_pd_dispatch(request, &mut clients, workers, model) | ||
| .await | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| let results = try_join_all(dispatches).await?; | ||
| Ok(ExecutionResult::Batch { results }) | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| async fn execute_single( | ||
| &self, | ||
| mut proto_request: ProtoGenerateRequest, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.