Skip to content
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

【Hackathon 5th No.104】move self_dp_attention to phi -part #58715

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions paddle/fluid/operators/fused/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ register_operators(
fused_bn_activation_op
conv_fusion_op
fusion_conv_inception_op
self_dp_attention_op
skip_layernorm_op
yolo_box_head_op
yolo_box_post_op
Expand All @@ -27,15 +26,6 @@ register_operators(
resnet_basic_block_op)

op_library(fusion_lstm_op)
if(WITH_AVX
AND AVX512F_FOUND
AND AVX512F_FLAG
AND WITH_MKL)
op_library(self_dp_attention_op)
set_target_properties(
self_dp_attention_op
PROPERTIES COMPILE_FLAGS "-Wno-maybe-uninitialized -mfma ${AVX512F_FLAG}")
endif()

if(WITH_XPU)
op_library(resnet_basic_block_op)
Expand Down
117 changes: 0 additions & 117 deletions paddle/fluid/operators/fused/self_dp_attention_op.cc

This file was deleted.

41 changes: 0 additions & 41 deletions paddle/fluid/operators/fused/self_dp_attention_op.h

This file was deleted.

1 change: 1 addition & 0 deletions paddle/fluid/pir/dialect/op_generator/ops_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
'fusion_seqexpand_concat_fc',
'fused_attention',
'fused_feedforward',
'self_dp_attention',
]

NO_NEED_GEN_STATIC_ONLY_APIS = [
Expand Down
9 changes: 9 additions & 0 deletions paddle/phi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ else()
CACHE INTERNAL "" FORCE)
endif()

if(WITH_AVX
AND AVX512F_FOUND
AND AVX512F_FLAG
AND WITH_MKL)
set_source_files_properties(
kernels/fusion/cpu/self_dp_attention_kernel.cc
PROPERTIES COMPILE_FLAGS "-Wno-maybe-uninitialized -mfma ${AVX512F_FLAG}")
endif()

if(WITH_GPU)
set_source_files_properties(
backends/gpu/gpu_resources.cc
Expand Down
9 changes: 9 additions & 0 deletions paddle/phi/api/yaml/fused_ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@
func : quantize_xpu
data_type : x

- op : self_dp_attention
args : (Tensor x, float alpha = 1.0f, int head_number = 1)
output : Tensor(out)
infer_meta :
func : SelfDPAttenInferMeta
kernel :
func : self_dp_attention
data_type : x

- op : squeeze_excitation_block
args : (Tensor x, Tensor filter, Tensor filter_max, Tensor bias, Tensor branch, int[] act_type, float[] act_param, int[] filter_dims)
output : Tensor(out)
Expand Down
6 changes: 6 additions & 0 deletions paddle/phi/api/yaml/op_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2624,6 +2624,12 @@
outputs :
{out : Out, summed_ids : SummedIds}

- op : self_dp_attention
inputs :
x : X
outputs :
out : Out

- op : selu
backward : selu_grad
inputs :
Expand Down
19 changes: 19 additions & 0 deletions paddle/phi/infermeta/fusion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2463,4 +2463,23 @@ void FusionSeqExpandConcatFCInferMeta(const std::vector<const MetaTensor*>& x,
// explicit share the ref lod
out->share_lod(*x[0]);
}

void SelfDPAttenInferMeta(const MetaTensor& x,
const float alpha,
const int head_number,
MetaTensor* out) {
auto dim_input = x.dims();
PADDLE_ENFORCE_EQ(
dim_input.size(),
5,
phi::errors::InvalidArgument("The size of input X dims should be 5, "
"[batchsize, tokensize, 3, nhead, headsize] "
", but now Input X dim is:[%s] ",
dim_input));
DDim out_dims({dim_input[0], dim_input[1], dim_input[3], dim_input[4]});
out->set_dims(out_dims);
out->share_lod(x);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

设置一下 dtype

out->set_dtype(x.dtype());
}

} // namespace phi
5 changes: 5 additions & 0 deletions paddle/phi/infermeta/fusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,4 +556,9 @@ void FusionSeqExpandConcatFCInferMeta(const std::vector<const MetaTensor*>& x,
const std::string& fc_activation,
MetaTensor* out,
MetaTensor* fc_out);

void SelfDPAttenInferMeta(const MetaTensor& x,
const float alpha,
const int head_number,
MetaTensor* out);
} // namespace phi
8 changes: 8 additions & 0 deletions paddle/phi/kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ if(DEFINED REDUCE_INFERENCE_LIB_SIZE)
list(FILTER kernel_cc EXCLUDE REGEX ".*_grad_kernel\\.cc$")
endif()

if(NOT
(WITH_AVX
AND AVX512F_FOUND
AND AVX512F_FLAG
AND WITH_MKL))
list(REMOVE_ITEM kernel_cc "fusion/cpu/self_dp_attention_kernel.cc")
endif()

file(
GLOB kernel_xpu
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
Expand Down
Loading