engine.rs 1.41 KB
Newer Older
1
2
3
4
5
6
7
8
// SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

//! Engine factory — creates the appropriate scheduler based on [`EngineType`].

use tokio::sync::mpsc;
use tokio_util::sync::CancellationToken;

9
10
11
use crate::common::protocols::{
    EngineType, FpmPublisher, KvEventPublishers, MockEngineArgs, OutputSignal,
};
12
13
14
15
16
17
18
19
20
use crate::scheduler::{Scheduler, SchedulerHandle, SglangScheduler};

/// Create a scheduler for the configured engine type.
///
/// Returns a boxed [`SchedulerHandle`] that the engine wrapper can use
/// without knowing which backend is running underneath.
pub fn create_engine(
    args: MockEngineArgs,
    dp_rank: u32,
21
    output_tx: Option<mpsc::UnboundedSender<Vec<OutputSignal>>>,
22
    kv_event_publishers: KvEventPublishers,
23
    cancellation_token: Option<CancellationToken>,
24
    fpm_publisher: FpmPublisher,
25
26
27
28
29
30
) -> Box<dyn SchedulerHandle> {
    match args.engine_type {
        EngineType::Vllm => Box::new(Scheduler::new(
            args,
            dp_rank,
            output_tx,
31
            kv_event_publishers,
32
            cancellation_token,
33
            fpm_publisher,
34
35
36
37
38
        )),
        EngineType::Sglang => Box::new(SglangScheduler::new(
            args,
            dp_rank,
            output_tx,
39
            kv_event_publishers,
40
            cancellation_token,
41
            fpm_publisher,
42
43
44
        )),
    }
}