-
Notifications
You must be signed in to change notification settings - Fork 38
feat: support expert dynamic load balancing for DeepSeek. #26
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
17962bd
feat: support expert dynamic load balancing for DeepSeek.
DongheJin b8553b9
bugfix: fix compile issuse for EPLB.
DongheJin 25b0d5f
bugfix: fix coredump issue when both EPLB and schedule overlap are en…
DongheJin 906d13b
feat: support variable number of redundant expert.
DongheJin 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
include(cc_binary) | ||
include(cc_library) | ||
include(cc_test) | ||
|
||
include_directories( | ||
${CMAKE_SOURCE_DIR}/xllm/core/kernels/ascend | ||
${CMAKE_SOURCE_DIR}/xllm/core/kernels/ascend/core/include | ||
) | ||
|
||
cc_library( | ||
NAME | ||
eplb | ||
HDRS | ||
eplb_executor.h | ||
eplb_manager.h | ||
eplb_policy.h | ||
expert_weight_buffer_shm.h | ||
shared_memory_manager.h | ||
expert_buffer_manager.h | ||
SRCS | ||
eplb_executor.cpp | ||
eplb_manager.cpp | ||
eplb_policy.cpp | ||
expert_weight_buffer_shm.cpp | ||
shared_memory_manager.cpp | ||
expert_buffer_manager.cpp | ||
DEPS | ||
torch_npu | ||
llm_engine | ||
:request | ||
:common | ||
glog::glog | ||
torch | ||
) | ||
|
||
set(TEST_SRCS | ||
eplb_policy_test.cpp | ||
) | ||
|
||
cc_test( | ||
NAME | ||
eplb_policy_test | ||
SRCS | ||
${TEST_SRCS} | ||
DEPS | ||
torch | ||
:eplb | ||
GTest::gtest_main | ||
) | ||
|
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,114 @@ | ||
#include "eplb_executor.h" | ||
|
||
#include <c10/core/Device.h> | ||
#include <c10/core/TensorOptions.h> | ||
#include <glog/logging.h> | ||
#if defined(USE_NPU) | ||
#include <torch_npu/csrc/core/npu/NPUFormat.h> | ||
#include <torch_npu/csrc/core/npu/NPUFunctions.h> | ||
#include <torch_npu/csrc/framework/OpCommand.h> | ||
#include <torch_npu/torch_npu.h> | ||
#endif | ||
#include <condition_variable> | ||
#include <functional> | ||
#include <memory> | ||
#include <mutex> | ||
#include <queue> | ||
#include <thread> | ||
|
||
#include "runtime/forward_params.h" | ||
|
||
namespace xllm { | ||
#if defined(USE_NPU) | ||
struct EplbExecutor::EplbStream { | ||
c10_npu::NPUStream eplb_stream; | ||
EplbStream() : eplb_stream(c10_npu::getNPUStreamFromPool()) {} | ||
}; | ||
#endif | ||
EplbExecutor::EplbExecutor(CausalLM* model) | ||
: model_(model), eplb_worker_(&EplbExecutor::eplb_worker_loop, this) { | ||
#if defined(USE_NPU) | ||
eplb_stream_ = std::make_unique<EplbStream>(); | ||
#endif | ||
} | ||
|
||
EplbExecutor::~EplbExecutor() { | ||
{ | ||
std::unique_lock<std::mutex> lock(queue_mutex_); | ||
stop_ = true; | ||
} | ||
condition_.notify_one(); | ||
if (eplb_worker_.joinable()) { | ||
eplb_worker_.join(); | ||
} | ||
} | ||
|
||
void EplbExecutor::eplb_execute(const EplbInfo& eplb_info) { | ||
if (eplb_info.update_layer_id != -1) { | ||
model_->update_expert_weight(eplb_info.update_layer_id); | ||
}; | ||
if (eplb_info.prepare_layer_id != -1) { | ||
prepare_expert_weight_async( | ||
eplb_info.prepare_layer_id, | ||
eplb_info.expert_ids, | ||
[eplb_info](int32_t id) { | ||
LOG(INFO) << "prepare expert weight complete, layer: " | ||
<< eplb_info.prepare_layer_id << std::endl; | ||
}); | ||
}; | ||
} | ||
|
||
void EplbExecutor::prepare_expert_weight_async( | ||
int32_t layer_id, | ||
const std::vector<int32_t>& expert_ids, | ||
Callback callback) { | ||
{ | ||
std::unique_lock<std::mutex> lock(queue_mutex_); | ||
tasks_.emplace(Task{layer_id, expert_ids, callback}); | ||
} | ||
condition_.notify_one(); | ||
} | ||
|
||
int32_t EplbExecutor::get_ready_layer_id() const { | ||
std::lock_guard<std::mutex> lock(ready_mutex_); | ||
return ready_layer_id_; | ||
} | ||
|
||
void EplbExecutor::reset_ready_layer_id() { | ||
std::lock_guard<std::mutex> lock(ready_mutex_); | ||
ready_layer_id_ = -1; | ||
} | ||
|
||
void EplbExecutor::eplb_worker_loop() { | ||
while (true) { | ||
Task task; | ||
{ | ||
std::unique_lock<std::mutex> lock(queue_mutex_); | ||
condition_.wait(lock, [this] { return !tasks_.empty() || stop_; }); | ||
if (stop_) return; | ||
task = std::move(tasks_.front()); | ||
tasks_.pop(); | ||
} | ||
auto prepare_start = std::chrono::high_resolution_clock::now(); | ||
|
||
c10::StreamGuard streamGuard(eplb_stream_->eplb_stream.unwrap()); | ||
model_->prepare_expert_weight(task.layer_id, task.expert_ids); | ||
aclrtSynchronizeStream(eplb_stream_->eplb_stream.stream()); | ||
auto prepare_end = std::chrono::high_resolution_clock::now(); | ||
auto prepare_duration = | ||
std::chrono::duration_cast<std::chrono::milliseconds>(prepare_end - | ||
prepare_start) | ||
.count(); | ||
LOG(INFO) << "prepare_expert_weight | layer=" << task.layer_id | ||
<< " | experts=" << task.expert_ids.size() | ||
<< " | duration=" << prepare_duration << "ms"; | ||
{ | ||
std::lock_guard<std::mutex> lock(ready_mutex_); | ||
ready_layer_id_ = task.layer_id; | ||
} | ||
if (task.callback) { | ||
task.callback(task.layer_id); | ||
} | ||
} | ||
} | ||
} // namespace xllm |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comments for struct / class and its public fields / methods please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Added detailed comments.