Skip to content

Commit bbc3bfc

Browse files
committed
fix: Feedback from Code Rabbit. Excellent as usual.
1 parent 3cca471 commit bbc3bfc

File tree

5 files changed

+35
-36
lines changed

5 files changed

+35
-36
lines changed

examples/cli/cli.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,14 @@ async def run(runtime: DistributedRuntime):
7979
input = args.input_source
8080
output = args.output_type
8181

82-
if output == "echo":
83-
engine_type = EngineType.Echo
84-
elif output == "mistralrs":
85-
engine_type = EngineType.MistralRs
86-
elif output == "llamacpp":
87-
engine_type = EngineType.LlamaCpp
88-
elif output == "dyn":
89-
engine_type = EngineType.Dynamic
90-
else:
82+
engine_type_map = {
83+
"echo": EngineType.Echo,
84+
"mistralrs": EngineType.MistralRs,
85+
"llamacpp": EngineType.LlamaCpp,
86+
"dyn": EngineType.Dynamic,
87+
}
88+
engine_type = engine_type_map.get(output)
89+
if engine_type is None:
9190
print(f"Unsupported output type: {output}")
9291
sys.exit(1)
9392

lib/bindings/python/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ uv pip install maturin
4646
maturin develop --uv
4747
```
4848

49-
5. Experimental: To allow using mistral.rs and llama.cpp via the bindings, build with feature flags
49+
5. Experimental: To allow using mistral.rs and llama.cpp via the bindings, build with feature flags:
5050

5151
```
5252
maturin develop --features mistralrs,llamacpp
@@ -61,7 +61,7 @@ the stub `libcuda.so` is earlier on the library search path than the real libcud
6161
patchelf --set-rpath '' _core.cpython-312-x86_64-linux-gnu.so
6262
```
6363

64-
If you include `llamacpp` feature flag, `libllama.so` and `libggml.so` (and family) will need to be available at runtime.
64+
If you include the `llamacpp` feature flag, `libllama.so` and `libggml.so` (and family) will need to be available at runtime.
6565

6666

6767
## Run Examples

lib/bindings/python/rust/llm/entrypoint.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use std::fmt::Display;
55
use std::path::PathBuf;
6+
use std::sync::Arc;
67

78
use pyo3::{exceptions::PyException, prelude::*};
89

@@ -52,9 +53,16 @@ impl EntrypointArgs {
5253
//router_config: Option<RouterConfig>,
5354
kv_cache_block_size: Option<u32>,
5455
http_port: Option<u16>,
55-
) -> Self {
56-
let endpoint_id_obj: Option<EndpointId> = endpoint_id.and_then(|eid| eid.parse().ok());
57-
EntrypointArgs {
56+
) -> PyResult<Self> {
57+
let endpoint_id_obj: Option<EndpointId> = match endpoint_id {
58+
Some(eid) => Some(eid.parse().map_err(|_| {
59+
PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
60+
"Invalid endpoint_id format: {eid}"
61+
))
62+
})?),
63+
None => None,
64+
};
65+
Ok(EntrypointArgs {
5866
engine_type,
5967
model_path,
6068
model_name,
@@ -65,14 +73,14 @@ impl EntrypointArgs {
6573
//router_config,
6674
kv_cache_block_size,
6775
http_port,
68-
}
76+
})
6977
}
7078
}
7179

7280
#[pyclass]
7381
#[derive(Clone)]
7482
pub(crate) struct EngineConfig {
75-
inner: RsEngineConfig,
83+
inner: Arc<RsEngineConfig>,
7684
}
7785

7886
#[pyfunction]
@@ -97,7 +105,9 @@ pub fn make_engine<'p>(
97105
let inner = select_engine(distributed_runtime, args.engine_type, local_model)
98106
.await
99107
.map_err(to_pyerr)?;
100-
Ok(EngineConfig { inner })
108+
Ok(EngineConfig {
109+
inner: Arc::new(inner),
110+
})
101111
})
102112
}
103113

@@ -154,7 +164,6 @@ async fn select_engine(
154164
Ok(inner)
155165
}
156166

157-
// TODO input should be an enum
158167
#[pyfunction]
159168
#[pyo3(signature = (distributed_runtime, input, engine_config))]
160169
pub fn run_input<'p>(
@@ -164,11 +173,16 @@ pub fn run_input<'p>(
164173
engine_config: EngineConfig,
165174
) -> PyResult<Bound<'p, PyAny>> {
166175
let input_enum: Input = input.parse().map_err(to_pyerr)?;
176+
let Some(engine_config) = Arc::into_inner(engine_config.inner) else {
177+
return Err(to_pyerr(anyhow::anyhow!(
178+
"EngineConfig Arc has been cloned. Should be impossible."
179+
)));
180+
};
167181
pyo3_async_runtimes::tokio::future_into_py(py, async move {
168182
dynamo_llm::entrypoint::input::run_input(
169183
either::Either::Right(distributed_runtime.inner.clone()),
170184
input_enum,
171-
engine_config.inner,
185+
engine_config,
172186
)
173187
.await
174188
.map_err(to_pyerr)?;

lib/bindings/python/src/dynamo/_core.pyi

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,6 @@ async def register_llm(model_type: ModelType, endpoint: Endpoint, model_path: st
787787
"""Attach the model at path to the given endpoint, and advertise it as model_type"""
788788
...
789789

790-
class EngineType:
791-
"""Enum saying which backend to us: Echo, MistralRs, Dyn, etc."""
792-
...
793-
794790
class EngineConfig:
795791
"""Holds internal configuration for a Dynamo engine."""
796792
...
@@ -799,7 +795,7 @@ async def make_engine(args: EntrypointArgs) -> EngineConfig:
799795
"""Make an engine matching the args"""
800796
...
801797

802-
async def run_input(input: str, runtime: Runtime, engine_config: EngineConfig) -> None:
798+
async def run_input(runtime: DistributedRuntime, input: str, engine_config: EngineConfig) -> None:
803799
"""Start an engine, connect it to an input, and run until stopped."""
804800
...
805801

lib/bindings/python/src/dynamo/llm/__init__.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
3-
#
4-
# Licensed under the Apache License, Version 2.0 (the "License");
5-
# you may not use this file except in compliance with the License.
6-
# You may obtain a copy of the License at
7-
#
8-
# http://www.apache.org/licenses/LICENSE-2.0
9-
#
10-
# Unless required by applicable law or agreed to in writing, software
11-
# distributed under the License is distributed on an "AS IS" BASIS,
12-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
# See the License for the specific language governing permissions and
14-
# limitations under the License.
3+
4+
# flake8: noqa
155

166
import logging
177

0 commit comments

Comments
 (0)