-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[NPU]Support GPT-OSS for NPU #14197
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
[NPU]Support GPT-OSS for NPU #14197
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1d307a1
adapt gpt-oss-120b
Todobe fde8ed1
move sinks_attention to sgl-kernel-npu
Todobe 621f137
Merge branch 'main' into gpt-oss
Todobe 9212884
fix silu
Todobe d215df7
move swiglu_oai to sgl-kernel-npu
Todobe 19a130e
fix swiglu_oai
Todobe 7bdb2c2
Merge branch 'main' into gpt-oss
Todobe d6a45b9
Merge remote-tracking branch 'shequ/main' into gpt-oss
Todobe f148f9f
Merge branch 'main' into gpt-oss
Todobe a87d4e4
Merge branch 'main' into gpt-oss
Todobe 240e0ec
Merge branch 'sgl-project:main' into gpt-oss
Todobe 17a0309
gptoss adpat prefix cache
Todobe 3a8e0a1
modify swiglu activation
Todobe 703dd42
Merge branch 'main' into gpt-oss
iforgetmyname d46f1f5
fix bias
Todobe 23af5c4
Merge branch 'gpt-oss' of https://github.com/Todobe/sgl-sglang into g…
Todobe 30a7bd2
rm extra file
Todobe 8e9f5fe
Merge branch 'main' into gpt-oss
iforgetmyname 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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
|
|
@@ -71,9 +71,10 @@ | |
| enable_fused_set_kv_buffer, | ||
| ) | ||
| from sglang.srt.server_args import get_global_server_args | ||
| from sglang.srt.utils import LazyValue, add_prefix, is_cuda, make_layers | ||
| from sglang.srt.utils import LazyValue, add_prefix, is_cuda, is_npu, make_layers | ||
|
|
||
| _is_cuda = is_cuda() | ||
| _is_npu = is_npu() | ||
|
|
||
|
|
||
| if _is_cuda: | ||
|
|
@@ -129,6 +130,7 @@ def __init__( | |
| "use_weight_loader_fused": quant_config_name | ||
| != "mxfp4" | ||
| } | ||
|
|
||
| self.experts = experts_type( | ||
| num_experts=config.num_local_experts | ||
| + get_global_server_args().ep_num_redundant_experts, | ||
|
|
@@ -305,20 +307,20 @@ def forward_prepare( | |
| qkv, _ = self.qkv_proj(hidden_states) | ||
| q, k, v = qkv.split([self.q_size, self.kv_size, self.kv_size], dim=-1) | ||
|
|
||
| q, k = self.rotary_emb( | ||
| positions, | ||
| q, | ||
| k, | ||
| fused_set_kv_buffer_arg=( | ||
| create_fused_set_kv_buffer_arg( | ||
| value=v, | ||
| layer=self.attn, | ||
| forward_batch=forward_batch, | ||
| ) | ||
| if enable_fused_set_kv_buffer(forward_batch) | ||
| else None | ||
| ), | ||
| ) | ||
| extra_args = {} | ||
| if not _is_npu: | ||
| extra_args = { | ||
| "fused_set_kv_buffer_arg": ( | ||
| create_fused_set_kv_buffer_arg( | ||
| value=v, | ||
| layer=self.attn, | ||
| forward_batch=forward_batch, | ||
| ) | ||
| if enable_fused_set_kv_buffer(forward_batch) | ||
| else None | ||
| ), | ||
| } | ||
| q, k = self.rotary_emb(positions, q, k, **extra_args) | ||
| inner_state = q, k, v, forward_batch | ||
| return None, forward_batch, inner_state | ||
|
|
||
|
|
@@ -490,6 +492,9 @@ def __init__( | |
| self.vocab_size = config.vocab_size | ||
| self.pp_group = get_pp_group() | ||
|
|
||
| if is_npu: | ||
|
Contributor
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. This should be _is_npu, otherwise this condition will always be True and will hinder running on other backends. |
||
| config.hidden_act = "npu_swiglu_oai" | ||
|
|
||
| if self.pp_group.is_first_rank: | ||
| self.embed_tokens = VocabParallelEmbedding( | ||
| config.vocab_size, | ||
|
|
||
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
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.