entrypoint.rs 2.6 KB
Newer Older
1
2
3
4
5
6
7
8
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// 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
13
14
15
16
17
18
19
20
21
22
23

use std::sync::Arc;

use dynamo_runtime::pipeline::RouterMode;

use crate::{
    backend::ExecutionContext, engines::StreamingEngine, kv_router::KvRouterConfig,
    local_model::LocalModel,
};

#[derive(Debug, Clone, Default)]
pub struct RouterConfig {
    pub router_mode: RouterMode,
    pub kv_router_config: KvRouterConfig,
24
25
26
27
    /// Threshold for active decode blocks utilization (0.0-1.0)
    pub active_decode_blocks_threshold: Option<f64>,
    /// Threshold for active prefill tokens utilization (literal token count)
    pub active_prefill_tokens_threshold: Option<u64>,
28
    pub enforce_disagg: bool,
29
30
31
32
33
34
35
}

impl RouterConfig {
    pub fn new(router_mode: RouterMode, kv_router_config: KvRouterConfig) -> Self {
        Self {
            router_mode,
            kv_router_config,
36
37
            active_decode_blocks_threshold: None,
            active_prefill_tokens_threshold: None,
38
            enforce_disagg: false,
39
40
        }
    }
41

42
43
44
45
46
47
48
    pub fn with_active_decode_blocks_threshold(mut self, threshold: Option<f64>) -> Self {
        self.active_decode_blocks_threshold = threshold;
        self
    }

    pub fn with_active_prefill_tokens_threshold(mut self, threshold: Option<u64>) -> Self {
        self.active_prefill_tokens_threshold = threshold;
49
50
        self
    }
51
52
53
54
55

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

58
#[derive(Clone)]
59
pub enum EngineConfig {
60
    /// Remote networked engines that we discover via etcd
61
62
    Dynamic(Box<LocalModel>),

63
64
    /// A Text engine receives text, does it's own tokenization and prompt formatting.
    InProcessText {
65
66
67
68
        engine: Arc<dyn StreamingEngine>,
        model: Box<LocalModel>,
    },

69
70
    /// A Tokens engine receives tokens, expects to be wrapped with pre/post processors that handle tokenization.
    InProcessTokens {
71
72
        engine: ExecutionContext,
        model: Box<LocalModel>,
73
        is_prefill: bool,
74
75
76
77
78
79
80
81
    },
}

impl EngineConfig {
    fn local_model(&self) -> &LocalModel {
        use EngineConfig::*;
        match self {
            Dynamic(lm) => lm,
82
83
            InProcessText { model, .. } => model,
            InProcessTokens { model, .. } => model,
84
85
86
        }
    }
}