-
Notifications
You must be signed in to change notification settings - Fork 194
feat: add configurable decode ACL-graph fallback threshold. #1233
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
Open
DongheJin
wants to merge
1
commit into
jd-opensource:main
Choose a base branch
from
DongheJin:bugfix/aclgraph_oom_main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,9 @@ NpuGlm4MoeDecoderImpl::NpuGlm4MoeDecoderImpl(const ModelContext& context, | |
| end_expert_id_ = start_expert_id_ + num_experts_per_partition_ - 1; | ||
|
|
||
| param_from_args(prefill_param_, model_args, parallel_args, true); | ||
| param_from_args(decode_param_, model_args, parallel_args, false); | ||
| param_from_args(decode_graph_param_, model_args, parallel_args, false); | ||
| decode_eager_param_ = decode_graph_param_; | ||
| decode_eager_param_.enableAclGraphPagedAttention = false; | ||
|
Comment on lines
+51
to
+52
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. |
||
| atb_weight_tensors_.resize(WEIGHT_COUNT_PER_LAYER); | ||
| placeholder_vec_ = {1}; | ||
| device_id_ = options.device().index(); | ||
|
|
@@ -300,7 +302,10 @@ int64_t NpuGlm4MoeDecoderImpl::init_layer() { | |
| BaseLayer::name_ = "glm4_moe_decoder_layer " + std::to_string(layer_id_); | ||
| model_name_ = "Glm4_Moe"; | ||
| CHECK_OPERATION_STATUS_RETURN(init_node(prefill_node_, prefill_param_)); | ||
| CHECK_OPERATION_STATUS_RETURN(init_node(decode_node_, decode_param_)); | ||
| CHECK_OPERATION_STATUS_RETURN( | ||
| init_node(decode_graph_node_, decode_graph_param_)); | ||
| CHECK_OPERATION_STATUS_RETURN( | ||
| init_node(decode_eager_node_, decode_eager_param_)); | ||
|
|
||
| return atb::NO_ERROR; | ||
| } | ||
|
|
@@ -356,20 +361,26 @@ torch::Tensor NpuGlm4MoeDecoderImpl::forward( | |
| attn_mask, | ||
| kv_cache, | ||
| input_params, | ||
| true); | ||
| true, | ||
| false); | ||
| st = execute_node(prefill_node_, node_id, event, event_flag); | ||
| LOG_IF(FATAL, st != 0) << model_name_ | ||
| << " excute prefill layer fail, error code: " << st; | ||
| } else { | ||
| build_node_variant_pack(decode_node_, | ||
| const bool use_graph_decode_input = | ||
| FLAGS_enable_graph && input_params.graph_buffer.tiling_data.defined(); | ||
| auto& decode_node = | ||
| use_graph_decode_input ? decode_graph_node_ : decode_eager_node_; | ||
| build_node_variant_pack(decode_node, | ||
| x, | ||
| cos_pos, | ||
| sin_pos, | ||
| /*attn_mask*/ tensor_placeholder_, | ||
| kv_cache, | ||
| input_params, | ||
| false); | ||
| st = execute_node(decode_node_, node_id + 1000, event, event_flag); | ||
| false, | ||
| use_graph_decode_input); | ||
| st = execute_node(decode_node, node_id + 1000, event, event_flag); | ||
| LOG_IF(FATAL, st != 0) << model_name_ | ||
| << " excute decode layer fail, error code: " << st; | ||
| } | ||
|
|
@@ -385,7 +396,8 @@ void NpuGlm4MoeDecoderImpl::build_node_variant_pack( | |
| torch::Tensor& attn_mask, | ||
| KVCache& kv_cache, | ||
| const ModelInputParams& input_params, | ||
| bool is_prefill) { | ||
| bool is_prefill, | ||
| bool use_graph_decode_input) { | ||
| internal_tensor_ = atb_speed::Utils::AtTensor2Tensor(x); | ||
| auto& dp_ep_padding = input_params.dp_ep_padding_data; | ||
|
|
||
|
|
@@ -458,7 +470,7 @@ void NpuGlm4MoeDecoderImpl::build_node_variant_pack( | |
| node.variantPack.inTensors.at(input_idx++) = | ||
| atb_speed::Utils::AtTensor2Tensor(tensor_placeholder_); | ||
|
|
||
| if (FLAGS_enable_graph && !is_prefill && | ||
| if (!is_prefill && use_graph_decode_input && | ||
| input_params.graph_buffer.tiling_data.defined()) { | ||
| node.variantPack.inTensors.at(input_idx++) = | ||
| atb_speed::Utils::AtTensor2Tensor( | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -157,7 +157,9 @@ NpuQwen3DecoderLayerImpl::NpuQwen3DecoderLayerImpl(const ModelContext& context) | |
| auto options = context.get_tensor_options(); | ||
|
|
||
| param_from_args(prefill_param_, model_args, parallel_args, true); | ||
| param_from_args(decode_param_, model_args, parallel_args, false); | ||
| param_from_args(decode_graph_param_, model_args, parallel_args, false); | ||
| decode_eager_param_ = decode_graph_param_; | ||
| decode_eager_param_.enableAclGraphPagedAttention = false; | ||
|
Comment on lines
+161
to
+162
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. |
||
| atb_weight_tensors_.resize(WEIGHT_COUNT_PER_LAYER); | ||
| placeholder_vec_ = {1}; | ||
| dtype_ = c10::typeMetaToScalarType(options.dtype()); | ||
|
|
@@ -188,7 +190,10 @@ int64_t NpuQwen3DecoderLayerImpl::init_layer() { | |
| name_ = "qwen3_decoder_layer"; | ||
| model_name_ = "qwen3"; | ||
| CHECK_OPERATION_STATUS_RETURN(init_node(prefill_node_, prefill_param_)); | ||
| CHECK_OPERATION_STATUS_RETURN(init_node(decode_node_, decode_param_)); | ||
| CHECK_OPERATION_STATUS_RETURN( | ||
| init_node(decode_graph_node_, decode_graph_param_)); | ||
| CHECK_OPERATION_STATUS_RETURN( | ||
| init_node(decode_eager_node_, decode_eager_param_)); | ||
|
|
||
| return atb::NO_ERROR; | ||
| } | ||
|
|
@@ -246,22 +251,28 @@ torch::Tensor NpuQwen3DecoderLayerImpl::forward(torch::Tensor& x, | |
| kv_cache, | ||
| input_params, | ||
| /*is_prefill=*/true, | ||
| node_id); | ||
| node_id, | ||
| /*use_graph_decode_input=*/false); | ||
| // mstxRangeEnd(id); | ||
| st = execute_node(prefill_node_, node_id, event, event_flag); | ||
| LOG_IF(FATAL, st != 0) << model_name_ | ||
| << "excute prefill layer fail, error code: " << st; | ||
| } else { | ||
| build_node_variant_pack(decode_node_, | ||
| const bool use_graph_decode_input = | ||
| FLAGS_enable_graph && input_params.graph_buffer.tiling_data.defined(); | ||
| auto& decode_node = | ||
| use_graph_decode_input ? decode_graph_node_ : decode_eager_node_; | ||
| build_node_variant_pack(decode_node, | ||
| x, | ||
| cos_pos, | ||
| sin_pos, | ||
| decode_attn_mask_, | ||
| kv_cache, | ||
| input_params, | ||
| /*is_prefill=*/false, | ||
| node_id); | ||
| st = execute_node(decode_node_, node_id + 1000, event, event_flag); | ||
| node_id, | ||
| use_graph_decode_input); | ||
| st = execute_node(decode_node, node_id + 1000, event, event_flag); | ||
| LOG_IF(FATAL, st != 0) << model_name_ | ||
| << "excute decode layer fail, error code: " << st; | ||
| } | ||
|
|
@@ -278,7 +289,8 @@ void NpuQwen3DecoderLayerImpl::build_node_variant_pack( | |
| KVCache& kv_cache, | ||
| ModelInputParams& input_params, | ||
| bool is_prefill, | ||
| int node_id) { | ||
| int node_id, | ||
| bool use_graph_decode_input) { | ||
| internal_tensors_ = atb_speed::Utils::AtTensor2Tensor(x); | ||
| node.variantPack.inTensors.at(WEIGHT_COUNT_PER_LAYER) = internal_tensors_; | ||
| node.variantPack.inTensors.at(WEIGHT_COUNT_PER_LAYER + 1) = | ||
|
|
@@ -342,7 +354,7 @@ void NpuQwen3DecoderLayerImpl::build_node_variant_pack( | |
| input_params.q_seq_lens_vec.data(); | ||
| } | ||
|
|
||
| if (FLAGS_enable_graph && !is_prefill && | ||
| if (!is_prefill && use_graph_decode_input && | ||
| input_params.graph_buffer.tiling_data.defined()) { | ||
| node.variantPack.inTensors.at(input_idx++) = | ||
| atb_speed::Utils::AtTensor2Tensor( | ||
|
|
||
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.
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.
Manual assignment of
decode_eager_param_fromdecode_graph_param_followed by a specific member override is error-prone. Consider adding a copy constructor or a dedicated factory method toChatglmLayerParamto handle this initialization safely.