This project provides a production-leaning orchestrator designed for multi-stage LLM pipelines over Tokio, implementing bounded channels and backpressure management. With features like pluggable workers and metrics hooks, it offers a robust solution for handling complex tasks while maintaining resource efficiency and performance.
tokio-prompt-orchestrator is a sophisticated orchestrator designed for managing multi-stage LLM (Large Language Model) pipelines utilizing Tokio. It efficiently incorporates features such as bounded channels, backpressure management, and metrics hooks to enhance pipeline performance and reliability.
The orchestrator follows a well-defined five-stage pipeline architecture that operates with bounded channels to optimize resource management:
PromptRequest → RAG(512) → Assemble(512) → Inference(1024) → Post(512) → Stream(256)
↓ ↓ ↓ ↓ ↓
5ms delay format ModelWorker join tokens emit
The orchestrator is built around the following key stages:
ModelWorker trait.ModelWorker trait allows for integration with any inference backend, facilitating flexibility.Implementing a basic usage of the orchestrator in Rust is straightforward:
use std::sync::Arc;
use tokio_prompt_orchestrator::{EchoWorker, ModelWorker, PromptRequest, SessionId, spawn_pipeline};
#[tokio::main]
async fn main() {
let worker: Arc<dyn ModelWorker> = Arc::new(EchoWorker::new());
let handles = spawn_pipeline(worker);
let request = PromptRequest {
session: SessionId::new("session-1"),
input: "Hello, world!".to_string(),
meta: Default::default(),
};
handles.input_tx.send(request).await.unwrap();
drop(handles.input_tx);
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
}
Custom inference logic can easily be integrated by defining a new worker:
use async_trait::async_trait;
use tokio_prompt_orchestrator::{ModelWorker, OrchestratorError};
struct MyCustomWorker {
// Your model state
}
#[async_trait]
impl ModelWorker for MyCustomWorker {
async fn infer(&self, prompt: &str) -> Result<Vec<String>, OrchestratorError> {
// Your inference logic
Ok(vec!["token1".to_string(), "token2".to_string()])
}
}
Key performance aspects include:
Future Roadmap includes enhancements such as gRPC support, distributed scaling, advanced features like batch processing, and more, intended to elevate performance and capabilities further.
For more details, refer to the complete README.
No comments yet.
Sign in to be the first to comment.