"lib/llm/src/entrypoint/input/grpc.rs" did not exist on "2d2a102727d9439eb680dd93e8976a12dfc5c365"
opt.rs 3.09 KB
Newer Older
1
2
3
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

4
use dynamo_runtime::protocols::ENDPOINT_SCHEME;
5
use std::fmt;
6

7
8
9
pub enum Output {
    /// Accept un-preprocessed requests, echo the prompt back as the response
    EchoFull,
10

11
12
13
    /// Accept preprocessed requests, echo the tokens back as the response
    EchoCore,

14
15
    /// Listen for models on nats/etcd, add/remove dynamically
    Dynamic,
16

17
18
19
    #[cfg(feature = "mistralrs")]
    /// Run inference on a model in a GGUF file using mistralrs w/ candle
    MistralRs,
20

21
22
23
    #[cfg(feature = "llamacpp")]
    /// Run inference using llama.cpp
    LlamaCpp,
Graham King's avatar
Graham King committed
24

25
26
27
    /// Run inference using sglang
    SgLang,

28
29
30
    /// Run inference using trtllm
    Trtllm,

31
32
    // Start vllm in a sub-process connecting via nats
    // Sugar for `python vllm_inc.py --endpoint <thing> --model <thing>`
Graham King's avatar
Graham King committed
33
    Vllm,
34
35
36
37
38
39
40
}

impl TryFrom<&str> for Output {
    type Error = anyhow::Error;

    fn try_from(s: &str) -> anyhow::Result<Self> {
        match s {
41
42
43
            #[cfg(feature = "mistralrs")]
            "mistralrs" => Ok(Output::MistralRs),

44
45
46
            #[cfg(feature = "llamacpp")]
            "llamacpp" | "llama_cpp" => Ok(Output::LlamaCpp),

47
            "sglang" => Ok(Output::SgLang),
48
            "trtllm" => Ok(Output::Trtllm),
Graham King's avatar
Graham King committed
49
            "vllm" => Ok(Output::Vllm),
50

51
            "echo_full" => Ok(Output::EchoFull),
52
            "echo_core" => Ok(Output::EchoCore),
53

54
55
56
            "dyn" => Ok(Output::Dynamic),

            // Deprecated, should only use `out=dyn`
57
            endpoint_path if endpoint_path.starts_with(ENDPOINT_SCHEME) => {
58
59
60
61
62
                tracing::warn!(
                    "out=dyn://<path> is deprecated, the path is not used. Please use 'out=dyn'"
                );
                //let path = endpoint_path.strip_prefix(ENDPOINT_SCHEME).unwrap();
                Ok(Output::Dynamic)
63
64
            }

65
66
67
68
69
70
71
72
            e => Err(anyhow::anyhow!("Invalid out= option '{e}'")),
        }
    }
}

impl fmt::Display for Output {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let s = match self {
73
74
75
            #[cfg(feature = "mistralrs")]
            Output::MistralRs => "mistralrs",

76
77
78
            #[cfg(feature = "llamacpp")]
            Output::LlamaCpp => "llamacpp",

79
            Output::SgLang => "sglang",
80
            Output::Trtllm => "trtllm",
Graham King's avatar
Graham King committed
81
            Output::Vllm => "vllm",
82

83
            Output::EchoFull => "echo_full",
84
            Output::EchoCore => "echo_core",
85

86
            Output::Dynamic => "dyn",
87
88
89
90
        };
        write!(f, "{s}")
    }
}
91

92
93
94
95
96
97
98
99
100
101
102
103
104
105
impl Output {
    #[allow(unused_mut)]
    pub fn available_engines() -> Vec<String> {
        let mut out = vec!["echo_core".to_string(), "echo_full".to_string()];
        #[cfg(feature = "mistralrs")]
        {
            out.push(Output::MistralRs.to_string());
        }

        #[cfg(feature = "llamacpp")]
        {
            out.push(Output::LlamaCpp.to_string());
        }

106
        out.push(Output::SgLang.to_string());
107
        out.push(Output::Trtllm.to_string());
108
        out.push(Output::Vllm.to_string());
109
110
111
112

        out
    }
}