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

//! The entrypoint module provides tools to build a Dynamo runner.
//! - Create an EngineConfig of the engine (potentially auto-discovered) to execute
//! - Connect it to an Input

pub mod input;
9
pub use input::{build_routed_pipeline, build_routed_pipeline_with_preprocessor};
10

11
12
use std::future::Future;
use std::pin::Pin;
13
14
15
16
17
use std::sync::Arc;

use dynamo_runtime::pipeline::RouterMode;

use crate::{
18
19
    backend::ExecutionContext, discovery::LoadThresholdConfig, engines::StreamingEngine,
    kv_router::KvRouterConfig, local_model::LocalModel, model_card::ModelDeploymentCard,
20
    types::openai::chat_completions::OpenAIChatCompletionsStreamingEngine,
21
22
};

23
24
25
26
27
28
29
30
31
32
/// Callback type for engine factory (async)
pub type EngineFactoryCallback = Arc<
    dyn Fn(
            ModelDeploymentCard,
        ) -> Pin<
            Box<dyn Future<Output = anyhow::Result<OpenAIChatCompletionsStreamingEngine>> + Send>,
        > + Send
        + Sync,
>;

33
34
35
36
#[derive(Debug, Clone, Default)]
pub struct RouterConfig {
    pub router_mode: RouterMode,
    pub kv_router_config: KvRouterConfig,
37
38
    /// Load threshold configuration for busy detection
    pub load_threshold_config: LoadThresholdConfig,
39
    pub enforce_disagg: bool,
40
41
42
43
44
45
46
}

impl RouterConfig {
    pub fn new(router_mode: RouterMode, kv_router_config: KvRouterConfig) -> Self {
        Self {
            router_mode,
            kv_router_config,
47
            load_threshold_config: LoadThresholdConfig::default(),
48
            enforce_disagg: false,
49
50
        }
    }
51

52
53
    pub fn with_load_threshold_config(mut self, config: LoadThresholdConfig) -> Self {
        self.load_threshold_config = config;
54
55
        self
    }
56
57
58
59
60

    pub fn with_enforce_disagg(mut self, enforce_disagg: bool) -> Self {
        self.enforce_disagg = enforce_disagg;
        self
    }
61
62
}

63
#[derive(Clone)]
64
pub enum EngineConfig {
65
    /// Remote networked engines that we discover via etcd
66
67
68
69
    Dynamic {
        model: Box<LocalModel>,
        engine_factory: Option<EngineFactoryCallback>,
    },
70

71
72
    /// A Text engine receives text, does it's own tokenization and prompt formatting.
    InProcessText {
73
74
75
76
        engine: Arc<dyn StreamingEngine>,
        model: Box<LocalModel>,
    },

77
78
    /// A Tokens engine receives tokens, expects to be wrapped with pre/post processors that handle tokenization.
    InProcessTokens {
79
80
        engine: ExecutionContext,
        model: Box<LocalModel>,
81
        is_prefill: bool,
82
83
84
85
    },
}

impl EngineConfig {
86
    pub fn local_model(&self) -> &LocalModel {
87
88
        use EngineConfig::*;
        match self {
89
            Dynamic { model, .. } => model,
90
91
            InProcessText { model, .. } => model,
            InProcessTokens { model, .. } => model,
92
93
        }
    }
94
95
96
97
98
99
100

    pub fn engine_factory(&self) -> Option<&EngineFactoryCallback> {
        match self {
            EngineConfig::Dynamic { engine_factory, .. } => engine_factory.as_ref(),
            _ => None,
        }
    }
101
}