feat: add Rust TurboMind API server - #4794
Draft
lvhan028 wants to merge 1 commit into
Draft
Conversation
Contributor
There was a problem hiding this comment.
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_turbomindPython extension. - Adds a Python
lmdeploy serve rust_api_servercommand 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.