Skip to content

Commit 4e882ac

Browse files
committed
fix: Feedback from Code Rabbit. Excellent as usual.
1 parent 9def849 commit 4e882ac

File tree

6 files changed

+32
-27
lines changed

6 files changed

+32
-27
lines changed

examples/cli/cli.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
# Must be in a virtualenv with the bindings (or wheel) installed.
88

99
import argparse
10+
import asyncio
1011
import sys
1112
from pathlib import Path
1213

1314
import uvloop
1415

1516
from dynamo.llm import EngineType, EntrypointArgs, make_engine, run_input
16-
from dynamo.runtime import DistributedRuntime, dynamo_worker
17+
from dynamo.runtime import DistributedRuntime
1718

1819

1920
def parse_args():
@@ -72,22 +73,23 @@ def parse_args():
7273
return args
7374

7475

75-
@dynamo_worker(static=False)
76-
async def run(runtime: DistributedRuntime):
76+
async def run():
77+
loop = asyncio.get_running_loop()
78+
runtime = DistributedRuntime(loop, False)
79+
7780
args = parse_args()
7881

7982
input = args.input_source
8083
output = args.output_type
8184

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:
85+
engine_type_map = {
86+
"echo": EngineType.Echo,
87+
"mistralrs": EngineType.MistralRs,
88+
"llamacpp": EngineType.LlamaCpp,
89+
"dyn": EngineType.Dynamic,
90+
}
91+
engine_type = engine_type_map.get(output)
92+
if engine_type is None:
9193
print(f"Unsupported output type: {output}")
9294
sys.exit(1)
9395

lib/bindings/python/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,16 @@ impl EntrypointArgs {
5252
//router_config: Option<RouterConfig>,
5353
kv_cache_block_size: Option<u32>,
5454
http_port: Option<u16>,
55-
) -> Self {
56-
let endpoint_id_obj: Option<EndpointId> = endpoint_id.and_then(|eid| eid.parse().ok());
57-
EntrypointArgs {
55+
) -> PyResult<Self> {
56+
let endpoint_id_obj: Option<EndpointId> = match endpoint_id {
57+
Some(eid) => Some(eid.parse().map_err(|_| {
58+
PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
59+
"Invalid endpoint_id format: {eid}"
60+
))
61+
})?),
62+
None => None,
63+
};
64+
Ok(EntrypointArgs {
5865
engine_type,
5966
model_path,
6067
model_name,
@@ -65,7 +72,7 @@ impl EntrypointArgs {
6572
//router_config,
6673
kv_cache_block_size,
6774
http_port,
68-
}
75+
})
6976
}
7077
}
7178

@@ -154,7 +161,6 @@ async fn select_engine(
154161
Ok(inner)
155162
}
156163

157-
// TODO input should be an enum
158164
#[pyfunction]
159165
#[pyo3(signature = (distributed_runtime, input, engine_config))]
160166
pub fn run_input<'p>(

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

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

842-
class EngineType:
843-
"""Enum saying which backend to us: Echo, MistralRs, Dyn, etc."""
844-
...
845-
846842
class EngineConfig:
847843
"""Holds internal configuration for a Dynamo engine."""
848844
...
@@ -851,7 +847,7 @@ async def make_engine(args: EntrypointArgs) -> EngineConfig:
851847
"""Make an engine matching the args"""
852848
...
853849

854-
async def run_input(input: str, runtime: Runtime, engine_config: EngineConfig) -> None:
850+
async def run_input(runtime: DistributedRuntime, input: str, engine_config: EngineConfig) -> None:
855851
"""Start an engine, connect it to an input, and run until stopped."""
856852
...
857853

@@ -1168,4 +1164,3 @@ class EntrypointArgs:
11681164
"""
11691165

11701166
...
1171-

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
# flake8: noqa
5+
46
import logging
57

68
from dynamo._core import AggregatedMetrics as AggregatedMetrics

0 commit comments

Comments
 (0)