Skip to content

feat: add Rust TurboMind API server - #4794

Draft
lvhan028 wants to merge 1 commit into
InternLM:mainfrom
lvhan028:feat/rust-api-server
Draft

feat: add Rust TurboMind API server#4794
lvhan028 wants to merge 1 commit into
InternLM:mainfrom
lvhan028:feat/rust-api-server

Conversation

@lvhan028

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings July 28, 2026 07:04
@lvhan028
lvhan028 marked this pull request as draft July 28, 2026 07:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an in-process Rust (Axum) HTTP API server for the TurboMind backend, with a new C/C++ ABI layer and a Python bootstrap/CLI entrypoint so LMDeploy can serve OpenAI-compatible endpoints while running tokenization, templating, parsing, and streaming in Rust.

Changes:

  • Introduces a TurboMind-serving C ABI (tm_*) plus a Rust runtime wrapper and an embedded Rust API server exposed via the _turbomind Python extension.
  • Adds a Python lmdeploy serve rust_api_server command and bootstrap module that validates model artifacts and launches the Rust server in-process.
  • Adds Rust workspace crates (parser/serving/runtime/sys), plus docs and tests for the new server.

Reviewed changes

Copilot reviewed 34 out of 35 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_lmdeploy/serve/test_rust_api_server.py Adds Python tests for model validation, parser validation, and logging bootstrap behavior.
src/turbomind/rust/server_api.h Declares the C ABI entrypoint for running the Rust API server.
src/turbomind/rust/c_api.h Defines a C ABI for engine/request lifecycle, request submission, outputs, and metrics.
src/turbomind/rust/c_api.cc Implements the TurboMind C ABI wrapper over TurboMind and ModelRequest.
src/turbomind/python/CMakeLists.txt Links Rust server staticlib into the Python extension when enabled.
src/turbomind/python/bind.cpp Adds GIL acquisition at callback boundary and exposes a rust_api_server pybind entrypoint.
src/turbomind/CMakeLists.txt Builds Rust server via Cargo (optional) and always compiles the C ABI wrapper into turbomind.
rust/crates/turbomind-sys/src/lib.rs Raw Rust FFI declarations matching the TurboMind C ABI.
rust/crates/turbomind-sys/Cargo.toml Declares the turbomind-sys crate.
rust/crates/turbomind-runtime/src/lib.rs Safe async Rust wrapper around the TurboMind C ABI (engine/request abstractions).
rust/crates/turbomind-runtime/Cargo.toml Declares the turbomind-runtime crate.
rust/crates/rust-api-server/src/lib.rs Implements Axum router, OpenAI-ish endpoints, streaming (SSE), and metrics.
rust/crates/rust-api-server/src/ffi.rs Provides the exported lmdeploy_rust_api_server_run C ABI to start the server.
rust/crates/rust-api-server/Cargo.toml Declares the Rust API server crate and dependencies/features.
rust/crates/lmdeploy-serving/src/tokenizer.rs Implements Rust-side tokenizer loading/encode/decode and EOS id discovery.
rust/crates/lmdeploy-serving/src/template.rs Implements Rust-side Hugging Face chat template rendering via MiniJinja.
rust/crates/lmdeploy-serving/src/protocol.rs Defines request/response protocol structs used by the Rust server.
rust/crates/lmdeploy-serving/src/lib.rs Exposes the serving modules and key types.
rust/crates/lmdeploy-serving/src/engine.rs Defines an Engine trait and wires NativeEngine into streaming generation + PPL.
rust/crates/lmdeploy-serving/Cargo.toml Declares the lmdeploy-serving crate.
rust/crates/lmdeploy-parser/src/response.rs Adds an incremental reasoning/tool-call response parser plus supported parser list.
rust/crates/lmdeploy-parser/src/lib.rs Exposes the parser API from the crate.
rust/crates/lmdeploy-parser/Cargo.toml Declares the lmdeploy-parser crate.
rust/Cargo.toml Introduces the Rust workspace and shared dependency versions/profiles.
rust/Cargo.lock Locks Rust dependency graph for reproducible builds.
rust/.gitignore Ignores Rust target output directory.
rust-toolchain.toml Pins Rust toolchain channel/profile/components for contributors/CI.
lmdeploy/turbomind/turbomind.py Adds load_tokenizer flag to avoid Python tokenizer load in Rust-server bootstrap path.
lmdeploy/serve/rust_api_server.py Adds Python bootstrap that validates HF files, configures logging, and calls the Rust entrypoint.
lmdeploy/cli/serve.py Adds lmdeploy serve rust_api_server CLI subcommand and arguments.
docs/zh_cn/llm/rust_api_server.md Adds Chinese user guide for building and running the Rust API server.
docs/zh_cn/index.rst Links the new Rust API server guide in the Chinese docs index.
docs/en/llm/rust_api_server.md Adds English user guide for building and running the Rust API server.
docs/en/index.rst Links the new Rust API server guide in the English docs index.
CMakeLists.txt Adds BUILD_RUST_API_SERVER option and disables LTO for xgrammar when Rust server is enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +74 to +77
supported_tool_parsers = {
'qwen', 'qwen2d5', 'qwen3', 'qwen3coder', 'llama3', 'internlm', 'intern-s1',
'interns2-preview', 'glm47', 'deepseek-v32', 'deepseek-v3.2', 'deepseek-v4'
}
Comment on lines +201 to +206
.route("/metrics", get(metrics))
.route("/v1/chat/completions", post(chat_completions))
.route("/v1/completions", post(completions))
.route("/get_ppl", post(get_ppl))
.layer(CorsLayer::permissive())
.with_state(state)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants