Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/codeowners/areas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ areas:
github_team: '@ai-dynamo/dynamo-backend-sglang-codeowners'
path_globs:
- components/src/dynamo/sglang/
- components/src/dynamo/sglang_sidecar/
- components/src/dynamo/sglang/request_handlers/
- components/src/dynamo/sglang/tests/
- examples/backends/sglang/
Expand Down
1 change: 0 additions & 1 deletion .github/filters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ sglang:
- 'container/deps/sglang/**'
- 'examples/backends/sglang/**'
- 'components/src/dynamo/sglang/**'
- 'components/src/dynamo/sglang_sidecar/**'
- 'container/templates/sglang_*'
- 'container/deps/sglang/**'
- '!**/*.md'
Expand Down
1 change: 0 additions & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
/examples/backends/sglang/ @ai-dynamo/dynamo-backend-sglang-codeowners
/components/src/dynamo/sglang/ @ai-dynamo/dynamo-backend-sglang-codeowners
/components/src/dynamo/sglang/tests/ @ai-dynamo/dynamo-backend-sglang-codeowners
/components/src/dynamo/sglang_sidecar/ @ai-dynamo/dynamo-backend-sglang-codeowners
/components/src/dynamo/sglang/request_handlers/ @ai-dynamo/dynamo-backend-sglang-codeowners

# === kv-memory (@ai-dynamo/dynamo-kv-memory-codeowners) ===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def test_module_exposes_expected_classes():
assert hasattr(backend, name), f"missing {name} on dynamo._core.backend"


def test_module_exposes_sglang_sidecar_launcher():
assert callable(backend._run_sglang_sidecar)


def test_runtime_config_accepts_optional_fields():
"""RuntimeConfig must construct with no args and with each field."""
backend.RuntimeConfig()
Expand Down
21 changes: 21 additions & 0 deletions components/src/dynamo/sglang/sidecar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""SGLang-managed launcher for Dynamo's native sidecar."""

import sys

from dynamo._core import backend as _backend
from dynamo.runtime.logging import configure_dynamo_logging

_run_sglang_sidecar = _backend._run_sglang_sidecar


def main(argv: list[str] | None = None) -> None:
"""Run the Dynamo sidecar against SGLang's injected gRPC endpoint."""
configure_dynamo_logging(service_name="dynamo.sglang.sidecar")
_run_sglang_sidecar(sys.argv[1:] if argv is None else argv)


if __name__ == "__main__":
main()
77 changes: 77 additions & 0 deletions components/src/dynamo/sglang/tests/test_sidecar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Tests for the SGLang-managed native sidecar launcher."""

import importlib
import sys
from unittest.mock import MagicMock, call

import pytest

pytest.importorskip(
"dynamo._core.backend",
reason="dynamo._core.backend not built — run `maturin develop` first",
)

from dynamo import sglang as sglang_package # noqa: E402
from dynamo.runtime import logging as runtime_logging # noqa: E402
from dynamo.sglang import sidecar # noqa: E402

pytestmark = [
pytest.mark.unit,
pytest.mark.sglang,
pytest.mark.core,
pytest.mark.gpu_0,
pytest.mark.pre_merge,
]


def test_main_forwards_sglang_argv(monkeypatch):
lifecycle = MagicMock()
monkeypatch.setattr(
sidecar, "configure_dynamo_logging", lifecycle.configure_logging
)
monkeypatch.setattr(sidecar, "_run_sglang_sidecar", lifecycle.run_sidecar)

sidecar.main(["--sglang-endpoint", "http://127.0.0.1:30001"])

assert lifecycle.mock_calls == [
call.configure_logging(service_name="dynamo.sglang.sidecar"),
call.run_sidecar(["--sglang-endpoint", "http://127.0.0.1:30001"]),
]


def test_main_uses_process_argv_by_default(monkeypatch):
logging_config = MagicMock()
native_launcher = MagicMock()
monkeypatch.setattr(sidecar, "configure_dynamo_logging", logging_config)
monkeypatch.setattr(sidecar, "_run_sglang_sidecar", native_launcher)
monkeypatch.setattr(
sys,
"argv",
[
"dynamo.sglang.sidecar",
"--sglang-endpoint",
"http://127.0.0.1:30001",
],
)

sidecar.main()

logging_config.assert_called_once_with(service_name="dynamo.sglang.sidecar")
native_launcher.assert_called_once_with(
["--sglang-endpoint", "http://127.0.0.1:30001"]
)


def test_import_does_not_configure_logging(monkeypatch):
logging_config = MagicMock()

with monkeypatch.context() as context:
context.setattr(runtime_logging, "configure_dynamo_logging", logging_config)
context.setattr(sglang_package, "sidecar", sidecar)
context.delitem(sys.modules, "dynamo.sglang.sidecar")
importlib.import_module("dynamo.sglang.sidecar")

logging_config.assert_not_called()
3 changes: 0 additions & 3 deletions components/src/dynamo/sglang_sidecar/__init__.py

This file was deleted.

7 changes: 0 additions & 7 deletions components/src/dynamo/sglang_sidecar/__main__.py

This file was deleted.

13 changes: 0 additions & 13 deletions components/src/dynamo/sglang_sidecar/main.py

This file was deleted.

49 changes: 49 additions & 0 deletions lib/bindings/python/rust/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ use crate::to_pyerr;
pub fn add_to_module(parent: &Bound<'_, PyModule>) -> PyResult<()> {
let py = parent.py();
let m = PyModule::new(py, "backend")?;
m.add_function(wrap_pyfunction!(_run_sglang_sidecar, &m)?)?;
m.add_class::<DisaggregationMode>()?;
m.add_class::<EngineConfig>()?;
m.add_class::<LlmRegistration>()?;
Expand All @@ -67,6 +68,34 @@ pub fn add_to_module(parent: &Bound<'_, PyModule>) -> PyResult<()> {
Ok(())
}

const SGLANG_SIDECAR_PROGRAM_NAME: &str = "dynamo-sglang-sidecar";

fn sglang_sidecar_argv(argv: Vec<String>) -> Vec<String> {
let mut cli_argv = Vec::with_capacity(argv.len() + 1);
cli_argv.push(SGLANG_SIDECAR_PROGRAM_NAME.to_string());
cli_argv.extend(argv);
cli_argv
}

/// Run the native SGLang sidecar in the current process.
///
/// SGLang's sidecar module contract passes only option arguments, while clap's
/// `try_parse_from` expects the program name at index zero. Add that stable
/// name here so Python callers use ordinary `sys.argv[1:]` semantics.
#[pyfunction]
#[pyo3(signature = (argv=None))]
fn _run_sglang_sidecar(py: Python<'_>, argv: Option<Vec<String>>) -> PyResult<()> {
let cli_argv = sglang_sidecar_argv(argv.unwrap_or_default());
let (engine, config) = py
.allow_threads(move || {
dynamo_sglang_sidecar::SglangSidecarEngine::from_args(Some(cli_argv))
})
.map_err(|err| pyo3::exceptions::PyValueError::new_err(err.to_string()))?;

py.allow_threads(move || dynamo_backend_common::run(Arc::new(engine), config))
.map_err(|err| pyo3::exceptions::PyRuntimeError::new_err(err.to_string()))
}

// ---------------------------------------------------------------------------
// DisaggregationMode — mirror of `dynamo_backend_common::DisaggregationMode`.
//
Expand Down Expand Up @@ -1634,3 +1663,23 @@ fn py_err_to_dynamo(err: PyErr) -> DynamoError {
.message(message)
.build()
}

#[cfg(test)]
mod tests {
use super::{SGLANG_SIDECAR_PROGRAM_NAME, sglang_sidecar_argv};

#[test]
fn sglang_sidecar_argv_prepends_program_name() {
assert_eq!(
sglang_sidecar_argv(vec![
"--sglang-endpoint".to_string(),
"http://127.0.0.1:30001".to_string(),
]),
vec![
SGLANG_SIDECAR_PROGRAM_NAME.to_string(),
"--sglang-endpoint".to_string(),
"http://127.0.0.1:30001".to_string(),
]
);
}
}
1 change: 0 additions & 1 deletion lib/bindings/python/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ fn _core(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(run_kv_indexer, m)?)?;
m.add_function(wrap_pyfunction!(run_slot_tracker, m)?)?;
m.add_function(wrap_pyfunction!(run_select_service, m)?)?;
m.add_function(wrap_pyfunction!(llm::entrypoint::run_sglang_sidecar, m)?)?;
m.add_function(wrap_pyfunction!(llm::entrypoint::make_engine, m)?)?;
m.add_function(wrap_pyfunction!(llm::replay::run_mocker_trace_replay, m)?)?;
m.add_function(wrap_pyfunction!(
Expand Down
18 changes: 1 addition & 17 deletions lib/bindings/python/rust/llm/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::pin::Pin;
use std::sync::Arc;

use pyo3::{
exceptions::{PyException, PyRuntimeError, PyValueError},
exceptions::{PyException, PyValueError},
prelude::*,
};
use pyo3_async_runtimes::TaskLocals;
Expand Down Expand Up @@ -948,22 +948,6 @@ pub fn run_input<'p>(
})
}

#[pyfunction]
pub fn run_sglang_sidecar(py: Python<'_>, args: Vec<String>) -> PyResult<()> {
let mut argv = Vec::with_capacity(args.len() + 1);
argv.push("python -m dynamo.sglang_sidecar".to_string());
argv.extend(args);

let (engine, config) = py
.allow_threads(|| dynamo_sglang_sidecar::SglangSidecarEngine::from_args(Some(argv)))
.map_err(|err| PyValueError::new_err(err.to_string()))?;

py.allow_threads(|| {
dynamo_backend_common::run(Arc::new(engine), config)
.map_err(|err| PyRuntimeError::new_err(err.to_string()))
})
}

pub fn to_pyerr<E>(err: E) -> PyErr
where
E: Display,
Expand Down
9 changes: 5 additions & 4 deletions lib/bindings/python/src/dynamo/_core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ def run_select_service(args: List[str]) -> None:
"""Run the Dynamo selection service with the given arguments."""
...

def run_sglang_sidecar(args: List[str]) -> None:
"""Run the SGLang gRPC sidecar with the given arguments."""
...

# Any Python object that can be serialized to JSON (dict, list, str, int, etc.)
JsonLike = Any

Expand Down Expand Up @@ -3276,6 +3272,11 @@ class SelectionServiceError(DynamoException):
# ---------------------------------------------------------------------------

class backend:
@staticmethod
def _run_sglang_sidecar(argv: Optional[List[str]] = None) -> None:
"""Run the native SGLang sidecar with CLI-style arguments."""
...

class DisaggregationMode:
# Mirrors `dynamo_backend_common::DisaggregationMode`. Engines consult
# this on the WorkerConfig to switch their per-mode protocol behavior;
Expand Down
Loading