forked from sgl-project/sglang
-
Notifications
You must be signed in to change notification settings - Fork 1
Patch NPU序列化以及减少update idle 检查 #7
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
lbk-sys
merged 2 commits into
lbk-sys:verl_sglang_0915
from
1StepForever:verl_sglang_0915
Sep 25, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,22 +19,33 @@ | |
|
|
||
| from sglang.srt.utils import is_npu | ||
|
|
||
| if is_npu(): | ||
|
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. ditto |
||
| from torch_npu.multiprocessing import reductions as npu_reductions | ||
|
|
||
| SGLANG_TP_RANK = None | ||
|
|
||
|
|
||
| def monkey_patch_torch_reductions(): | ||
| """Monkey patching before Torch https://github.com/pytorch/pytorch/pull/149248 is fixed""" | ||
|
|
||
| # Currently, NPU does not support UUID. This has been temporarily commented out, with support expected in the fourth quarter. | ||
| # Currently, NPU does not support UUID. This is a temporary fix, with support expected in the fourth quarter. | ||
| if is_npu(): | ||
|
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. _is_npu |
||
| return | ||
|
|
||
| if hasattr(reductions, "_reduce_tensor_original"): | ||
| return | ||
|
|
||
| reductions._reduce_tensor_original = reductions.reduce_tensor | ||
| reductions._rebuild_cuda_tensor_original = reductions.rebuild_cuda_tensor | ||
|
|
||
| reductions.reduce_tensor = _reduce_tensor_modified | ||
| reductions.rebuild_cuda_tensor = _rebuild_cuda_tensor_modified | ||
| ''' | ||
| This is a temp patch for npu as HDK does not support device uuid for now | ||
| ''' | ||
| if hasattr(npu_reductions, "_rebuild_npu_tensor_original"): | ||
| return | ||
|
|
||
| npu_reductions._rebuild_npu_tensor_original = npu_reductions.rebuild_npu_tensor | ||
| npu_reductions.rebuild_npu_tensor = _rebuild_npu_tensor_modified | ||
|
|
||
| else: | ||
| if hasattr(reductions, "_reduce_tensor_original"): | ||
| return | ||
| reductions._reduce_tensor_original = reductions.reduce_tensor | ||
| reductions._rebuild_cuda_tensor_original = reductions.rebuild_cuda_tensor | ||
| reductions.reduce_tensor = _reduce_tensor_modified | ||
| reductions.rebuild_cuda_tensor = _rebuild_cuda_tensor_modified | ||
|
|
||
| reductions.init_reductions() | ||
|
|
||
|
|
@@ -44,6 +55,21 @@ def monkey_patch_torch_reductions(): | |
| _REDUCE_TENSOR_ARG_DEVICE_INDEX = 6 | ||
|
|
||
|
|
||
| def _rebuild_npu_tensor_modified(*args): | ||
| args = _modify_tuple(args, _REDUCE_TENSOR_ARG_DEVICE_INDEX, npu_verl_to_sglang) | ||
| return npu_reductions._rebuild_npu_tensor_original(*args) | ||
|
|
||
|
|
||
| def register_sgl_tp_rank(rank: int): | ||
| global SGLANG_TP_RANK | ||
| SGLANG_TP_RANK = rank | ||
|
|
||
|
|
||
| def npu_verl_to_sglang(device: int): | ||
| assert SGLANG_TP_RANK is not None | ||
| return SGLANG_TP_RANK | ||
|
|
||
|
|
||
| def _reduce_tensor_modified(*args, **kwargs): | ||
| output_fn, output_args = reductions._reduce_tensor_original(*args, **kwargs) | ||
| output_args = _modify_tuple( | ||
|
|
@@ -85,4 +111,4 @@ def monkey_patch_torch_compile(): | |
| import torch._higher_order_ops.auto_functionalize as af | ||
|
|
||
| af.auto_functionalized_v2._cacheable = True | ||
| af.auto_functionalized._cacheable = True | ||
| af.auto_functionalized._cacheable = True | ||
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.
_is_npu = is_npu()