-
Notifications
You must be signed in to change notification settings - Fork 91
feat: support single-node multi-NPUs offline inference. #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
liutongxuan
merged 1 commit into
jd-opensource:main
from
yq33victor:dev/support_offline_multi_xpu3
Oct 24, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
24 changes: 24 additions & 0 deletions
24
xllm/core/distributed_runtime/spawn_worker_server/CMakeLists.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| include(cc_binary) | ||
|
|
||
| cc_binary( | ||
| NAME | ||
| spawn_worker | ||
| HDRS | ||
| spawn_worker_server.h | ||
| SRCS | ||
| spawn_worker_server.cpp | ||
| spawn_worker_server_process.cpp | ||
| DEPS | ||
| :models | ||
| :model | ||
| :distributed_runtime | ||
| absl::strings | ||
| xllm_kernels | ||
| ascendcl | ||
| nnopbase | ||
| atb | ||
| c_sec | ||
| spdlog::spdlog | ||
| ) | ||
|
|
||
| add_dependencies(export_module spawn_worker) |
84 changes: 84 additions & 0 deletions
84
xllm/core/distributed_runtime/spawn_worker_server/spawn_worker_server.cpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* Copyright 2025 The xLLM Authors. All Rights Reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| https://github.com/jd-opensource/xllm/blob/main/LICENSE | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| ==============================================================================*/ | ||
|
|
||
| #include "spawn_worker_server.h" | ||
|
|
||
| #include <absl/strings/str_split.h> | ||
| #if defined(USE_NPU) | ||
| #include <acl/acl.h> | ||
| #endif | ||
| #include <signal.h> | ||
| #include <sys/prctl.h> | ||
|
|
||
| #include <cstdlib> | ||
|
|
||
| #include "core/distributed_runtime/worker_server.h" | ||
| #include "core/platform/device.h" | ||
| #include "core/runtime/options.h" | ||
|
|
||
| namespace xllm { | ||
|
|
||
| bool xllm::SpawnWorkerServer::g_running_ = true; | ||
|
|
||
| SpawnWorkerServer::SpawnWorkerServer(const std::string& master_node_addr, | ||
| int local_rank, | ||
| int global_rank, | ||
| int world_size, | ||
| int device_idx, | ||
| int num_decoding_tokens, | ||
| int block_size) { | ||
| // TODO: pass whole xllm::runtime::Options here from main process. | ||
| xllm::runtime::Options runner_options; | ||
| runner_options.block_size(block_size) | ||
| .num_decoding_tokens(num_decoding_tokens) | ||
| .enable_schedule_overlap(false) | ||
| .enable_offline_inference(true) | ||
| .master_node_addr(master_node_addr); | ||
| FLAGS_enable_schedule_overlap = false; | ||
| FLAGS_master_node_addr = master_node_addr; | ||
| FLAGS_block_size = block_size; | ||
|
|
||
| std::atomic<bool> done(false); | ||
| #if defined(USE_NPU) | ||
| xllm::Device device("npu:" + std::to_string(device_idx)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we can add another construction function for class Device::Device(int32_t device_id){
std::string device_name = type() + ":" + std::to_string(device_id);
device_ = torch::Device(device_name);
}and move |
||
| device.set_device(); | ||
| device.init_device_context(); | ||
| FLAGS_enable_atb_comm_multiprocess = true; | ||
| #endif | ||
|
|
||
| ParallelArgs parallel_args(global_rank, world_size, 1, nullptr, 1); | ||
| WorkerServer worker_server(local_rank, | ||
| master_node_addr, | ||
| done, | ||
| parallel_args, | ||
| device, | ||
| runner_options, | ||
| WorkerType::LLM, | ||
| false); | ||
| } | ||
|
|
||
| void SpawnWorkerServer::handle_signal(int signum) { g_running_ = false; } | ||
|
|
||
| void SpawnWorkerServer::run() { | ||
| signal(SIGINT, SpawnWorkerServer::handle_signal); | ||
| signal(SIGTERM, SpawnWorkerServer::handle_signal); | ||
|
|
||
| // main thread waiting here | ||
| while (SpawnWorkerServer::g_running_) { | ||
| sleep(5); | ||
| } | ||
| } | ||
|
|
||
| } // namespace xllm | ||
41 changes: 41 additions & 0 deletions
41
xllm/core/distributed_runtime/spawn_worker_server/spawn_worker_server.h
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* Copyright 2025 The xLLM Authors. All Rights Reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| https://github.com/jd-opensource/xllm/blob/main/LICENSE | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| ==============================================================================*/ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace xllm { | ||
|
|
||
| class SpawnWorkerServer final { | ||
| public: | ||
| explicit SpawnWorkerServer(const std::string& master_node_addr, | ||
| int local_rank, | ||
| int global_rank, | ||
| int world_size, | ||
| int device_idx, | ||
| int num_decoding_tokens, | ||
| int block_size); | ||
|
|
||
| ~SpawnWorkerServer() = default; | ||
|
|
||
| void run(); | ||
|
|
||
| static void handle_signal(int signum); | ||
|
|
||
| static bool g_running_; | ||
| }; | ||
|
|
||
| } // namespace xllm |
73 changes: 73 additions & 0 deletions
73
xllm/core/distributed_runtime/spawn_worker_server/spawn_worker_server_process.cpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* Copyright 2025 The xLLM Authors. All Rights Reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| https://github.com/jd-opensource/xllm/blob/main/LICENSE | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| ==============================================================================*/ | ||
|
|
||
| #include <gflags/gflags.h> | ||
| #include <glog/logging.h> | ||
| #include <signal.h> | ||
| #include <sys/prctl.h> | ||
|
|
||
| #include "spawn_worker_server.h" | ||
|
|
||
| // Worker argv from engine process: | ||
| // @master_node_addr | ||
| // @local_rank | ||
| // @global_rank | ||
| // @world_size | ||
| // @device_idx | ||
| // @num_decoding_tokens | ||
| // @block_size | ||
| int main(int argc, char* argv[]) { | ||
| if (argc < 7) { | ||
| LOG(ERROR) | ||
| << "Spwan worker process receive wrong args. Need 7 args, receive " | ||
| << argc; | ||
| return 1; | ||
| } | ||
|
|
||
| // set PR_SET_PDEATHSIG flag that child should exit | ||
| // when parent process exit | ||
| if (prctl(PR_SET_PDEATHSIG, SIGHUP) == -1) { | ||
| perror("prctl"); | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| std::string master_node_addr = std::string(argv[1]); | ||
| int local_rank = atoi(argv[2]); | ||
| int global_rank = atoi(argv[3]); | ||
| int world_size = atoi(argv[4]); | ||
| int device_idx = atoi(argv[5]); | ||
| int num_decoding_tokens = atoi(argv[6]); | ||
| int block_size = atoi(argv[7]); | ||
|
|
||
| LOG(INFO) << "Spwan worker: " | ||
| << "master_node_addr = " << master_node_addr | ||
| << ", local_rank = " << local_rank | ||
| << ", world_size = " << world_size | ||
| << ", device_idx = " << device_idx | ||
| << ", num_decoding_tokens = " << num_decoding_tokens | ||
| << ", block_size = " << block_size << "\n"; | ||
|
|
||
| xllm::SpawnWorkerServer worker(master_node_addr, | ||
| local_rank, | ||
| global_rank, | ||
| world_size, | ||
| device_idx, | ||
| num_decoding_tokens, | ||
| block_size); | ||
|
|
||
| worker.run(); | ||
|
|
||
| return 0; | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.