Skip to content

Commit 3edeb00

Browse files
authored
【UnitTestFix No.19】Fix test_fused_dot_product_attention_op_static.py (#76405)
- 移除了 `list(REMOVE_ITEM TEST_OPS test_fused_dot_product_attention_op_static)` - 在Windows上使用如下cmake命令 `cmake .. -GNinja -DWITH_GPU=ON -DWITH_UNITY_BUILD=ON -DCUDA_ARCH_NAME=Auto -DWITH_TENSORRT=ON -DTENSORRT_ROOT=D:\TensorRT-10.13.3.9 -DWITH_TESTING=ON` ,编译成功 测试用例报错如下: ```shell Start testing: Nov 05 21:48 中国标准时间 ---------------------------------------------------------- 1488/2270 Testing: test_fused_dot_product_attention_op_static 1488/2270 Test: test_fused_dot_product_attention_op_static Command: "D:/Program Files/CMake/bin/cmake.exe" "-E" "env" "PYTHONPATH=D:/Lenovo/Paddle/build/python" "D:/Users/Lenovo/AppData/Local/Programs/Python/Python310/python.exe" "D:/Lenovo/Paddle/tools/test_runner.py" "test_fused_dot_product_attention_op_static" Directory: D:/Lenovo/Paddle/build/test/legacy_test "test_fused_dot_product_attention_op_static" start time: Nov 05 21:48 中国标准时间 Output: ---------------------------------------------------------- test_fused_dot_product_attention_op_static failed E ====================================================================== ERROR: test_static_op (test_fused_dot_product_attention_op_static.TestFusedDotProductAttentionStatic) ---------------------------------------------------------------------- Traceback (most recent call last): File "D:\Lenovo\Paddle\build\test\legacy_test\test_fused_dot_product_attention_op_static.py", line 74, in test_static_op out0 = fused_dot_product_attention(q, k, v, mask) File "D:\Lenovo\Paddle\build\python\paddle\incubate\nn\functional\fused_dot_product_attention.py", line 202, in fused_dot_product_attention out, _, _ = _C_ops.fused_dot_product_attention( RuntimeError: (NotFound) The kernel `fused_dot_product_attention` is not registered. [Hint: Expected iter != kernels_.end(), but received iter == kernels_.end().] (at D:\Lenovo\Paddle\paddle\phi\core\kernel_factory.cc:276) ---------------------------------------------------------------------- Ran 1 test in 0.135s FAILED (errors=1) <end of output> Test time = 4.86 sec ---------------------------------------------------------- Test Failed. "test_fused_dot_product_attention_op_static" end time: Nov 05 21:48 中国标准时间 "test_fused_dot_product_attention_op_static" time elapsed: 00:00:04 ---------------------------------------------------------- End testing: Nov 05 21:48 中国标准时间 ``` - 添加 `-DWITH_CUDNN_FRONTEND=ON` 后,出现以下编译错误: ```shell [1675/3580] Linking CXX shared library paddle\phi\phi.dll FAILED: paddle/phi/phi.dll paddle/phi/phi.lib C:\WINDOWS\system32\cmd.exe /C "cd . && "D:\Program Files\CMake\bin\cmake.exe" -E vs_link_dll --msvc-ver=1944 --intdir=paddle\phi\CMakeFiles\phi.dir --rc="D:\Windows Kits\10\bin\10.0.26100.0\x64\rc.exe" --mt="D:\Windows Kits\10\bin\10.0.26100.0\x64\mt.exe" --manifests -- "D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64\link.exe" /nologo @CMakeFiles\phi.rsp /out:paddle\phi\phi.dll /implib:paddle\phi\phi.lib /pdb:paddle\phi\phi.pdb /dll /version:0.0 /machine:x64 /ignore:4049 /ignore:4217 /ignore:4006 /ignore:4221 /NODEFAULTLIB:MSVCRT.LIB /INCREMENTAL:NO && cd ." LINK: command "D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\phi.rsp /out:paddle\phi\phi.dll /implib:paddle\phi\phi.lib /pdb:paddle\phi\phi.pdb /dll /version:0.0 /machine:x64 /ignore:4049 /ignore:4217 /ignore:4006 /ignore:4221 /NODEFAULTLIB:MSVCRT.LIB /INCREMENTAL:NO /MANIFEST:EMBED,ID=2" failed (exit code 1120) with the following output: 正在创建库 paddle\phi\phi.lib 和对象 paddle\phi\phi.exp fused_dconv_drelu_dbn_kernel.cu.obj : error LNK2019: 无法解析的外部符号 "bool paddle_flags::FLAGS_cudnn_deterministic" (?FLAGS_cudnn_deterministic@paddle_flags@@3_NA),函数 "void __cdecl phi::fusion::FusedDconvDreluDbnKernel<struct phi::dtype::float16,class phi::GPUContext>(class phi::GPUContext const &,class phi::DenseTensor const &,class phi::DenseTensor const &,class paddle::optional<class phi::DenseTensor> const &,class paddle::optional<class phi::DenseTensor> const &,class paddle::optional<class phi::DenseTensor> const &,class paddle::optional<class phi::DenseTensor> const &,class paddle::optional<class phi::DenseTensor> const &,class phi::DenseTensor const &,class phi::DenseTensor const &,class phi::DenseTensor const &,class phi::DenseTensor const &,class phi::DenseTensor const &,class paddle::optional<class phi::DenseTensor> const &,class paddle::optional<class phi::DenseTensor> const &,class paddle::optional<class phi::DenseTensor> const &,class paddle::optional<class phi::DenseTensor> const &,class paddle::optional<class phi::DenseTensor> const &,class std::vector<int,class std::allocator<int> > const &,class std::vector<int,class std::allocator<int> > const &,class std::vector<int,class std::allocator<int> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool,bool,bool,bool,class phi::DenseTensor *,class phi::DenseTensor *,class phi::DenseTensor *,class phi::DenseTensor *,class phi::DenseTensor *,class phi::DenseTensor *,class phi::DenseTensor *)" (??$FusedDconvDreluDbnKernel@Ufloat16@dtype@phi@@VGPUContext@3@@Fusion@phi@@YAXAEBVGPUContext@1@AEBVDenseTensor@1@1AEBV?$optional@VDenseTensor@phi@@@paddle@@22221111122222AEBV?$vector@HV?$allocator@H@std@@@std@@33AEBV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@7@H4_N555PEAV31@666666@Z) 中引用了该符号 fused_dot_product_attention_op.cu.obj : error LNK2001: 无法解析的外部符号 "bool paddle_flags::FLAGS_cudnn_deterministic" (?FLAGS_cudnn_deterministic@paddle_flags@@3_NA) fused_scale_bias_add_relu_kernel.cu.obj : error LNK2001: 无法解析的外部符号 "bool paddle_flags::FLAGS_cudnn_deterministic" (?FLAGS_cudnn_deterministic@paddle_flags@@3_NA) fused_scale_bias_relu_conv_bn_kernel.cu.obj : error LNK2001: 无法解析的外部符号 "bool paddle_flags::FLAGS_cudnn_deterministic" (?FLAGS_cudnn_deterministic@paddle_flags@@3_NA) paddle\phi\phi.dll : fatal error LNK1120: 1 个无法解析的外部命令 [1682/3580] Building CXX object paddle\fluid\framework\ir\...s.dir\conv2d_trans_filter_dilations_nxn_to_1x1_pass.cc.obj ninja: build stopped: subcommand failed. ``` 在以下四个GPU融合算子内核文件中: - fused_dconv_drelu_dbn_kernel.cu - fused_dot_product_attention_op.cu - fused_scale_bias_add_relu_kernel.cu - fused_scale_bias_relu_conv_bn_kernel.cu 将 `PHI_DECLARE_bool(cudnn_deterministic)` 修改为 `COMMON_DECLARE_bool(cudnn_deterministic)`, 应当是上次进行大规模重构过程中遗漏的修改。 编译成功后运行测试用例,报错如下: ```shell Start testing: Nov 13 18:02 中国标准时间 ---------------------------------------------------------- 1491/2280 Testing: test_fused_dot_product_attention_op_static 1491/2280 Test: test_fused_dot_product_attention_op_static Command: "D:/Program Files/CMake/bin/cmake.exe" "-E" "env" "PYTHONPATH=D:/Lenovo/Paddle/build/python" "D:/Users/Lenovo/AppData/Local/Programs/Python/Python310/python.exe" "D:/Lenovo/Paddle/tools/test_runner.py" "test_fused_dot_product_attention_op_static" Directory: D:/Lenovo/Paddle/build/test/legacy_test "test_fused_dot_product_attention_op_static" start time: Nov 13 18:02 中国标准时间 Output: ---------------------------------------------------------- WARNING: Logging before InitGoogleLogging() is written to STDERR W1113 18:02:59.023836 18612 gpu_resources.cc:116] Please NOTE: device: 0, GPU Compute Capability: 8.6, Driver API Version: 13.0, Runtime API Version: 13.0 test_fused_dot_product_attention_op_static failed E ====================================================================== ERROR: test_static_op (test_fused_dot_product_attention_op_static.TestFusedDotProductAttentionStatic) ---------------------------------------------------------------------- Traceback (most recent call last): File "D:\Lenovo\Paddle\build\test\legacy_test\test_fused_dot_product_attention_op_static.py", line 106, in test_static_op outs = fused_dot_product_attention(q, k, v, mask) File "D:\Lenovo\Paddle\build\python\paddle\incubate\nn\functional\fused_dot_product_attention.py", line 202, in fused_dot_product_attention out, _, _ = _C_ops.fused_dot_product_attention( ValueError: (InvalidArgument) fused_dot_product_attention(): argument 'q' (position 0) must be Tensor, but got paddle.base.libpaddle.pir.Value (at D:\Lenovo\Paddle\paddle\fluid\pybind\eager_utils.cc:1531) ---------------------------------------------------------------------- Ran 1 test in 0.787s FAILED (errors=1) <end of output> Test time = 5.86 sec ---------------------------------------------------------- Test Failed. "test_fused_dot_product_attention_op_static" end time: Nov 13 18:03 中国标准时间 "test_fused_dot_product_attention_op_static" time elapsed: 00:00:05 ---------------------------------------------------------- End testing: Nov 13 18:03 中国标准时间 ``` - 添加了 `OldIrGuard` 上下文管理器来禁用PIR(Program Intermediate Representation)模式 - 修改了静态图测试的结构,使用独立的 `main_program` 和 `startup_program` - 明确调用 `exe.run(startup_program)` 进行初始化 **作用:** - **兼容新旧IR系统**: 确保测试在传统静态图模式下运行,而不是新的PIR模式 - **修复测试问题**: 提高测试的稳定性和正确性
1 parent 49cb7d9 commit 3edeb00

File tree

6 files changed

+62
-51
lines changed

6 files changed

+62
-51
lines changed

paddle/phi/kernels/fusion/gpu/fused_dconv_drelu_dbn_kernel.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ limitations under the License. */
2525
#include "paddle/phi/kernels/funcs/batch_norm_utils.h"
2626
#include "paddle/phi/kernels/gpudnn/conv_cudnn_frontend.h"
2727

28-
PHI_DECLARE_bool(cudnn_deterministic);
28+
COMMON_DECLARE_bool(cudnn_deterministic);
2929
COMMON_DECLARE_bool(cudnn_exhaustive_search);
3030

3131
namespace phi {

paddle/phi/kernels/fusion/gpu/fused_dot_product_attention_op.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "paddle/phi/kernels/expand_kernel.h"
2424
#include "paddle/phi/kernels/gpudnn/mha_cudnn_frontend.h"
2525

26-
PHI_DECLARE_bool(cudnn_deterministic);
26+
COMMON_DECLARE_bool(cudnn_deterministic);
2727

2828
namespace phi {
2929
namespace fusion {

paddle/phi/kernels/fusion/gpu/fused_scale_bias_add_relu_kernel.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ limitations under the License. */
2525
#include "paddle/phi/kernels/funcs/batch_norm_utils.h"
2626
#include "paddle/phi/kernels/gpudnn/conv_cudnn_frontend.h"
2727

28-
PHI_DECLARE_bool(cudnn_deterministic);
28+
COMMON_DECLARE_bool(cudnn_deterministic);
2929
COMMON_DECLARE_bool(cudnn_exhaustive_search);
3030

3131
namespace phi {

paddle/phi/kernels/fusion/gpu/fused_scale_bias_relu_conv_bn_kernel.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ limitations under the License. */
2525
#include "paddle/phi/kernels/funcs/batch_norm_utils.h"
2626
#include "paddle/phi/kernels/gpudnn/conv_cudnn_frontend.h"
2727

28-
PHI_DECLARE_bool(cudnn_deterministic);
28+
COMMON_DECLARE_bool(cudnn_deterministic);
2929
COMMON_DECLARE_bool(cudnn_exhaustive_search);
3030

3131
namespace phi {

test/legacy_test/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ list(REMOVE_ITEM TEST_OPS test_audio_logmel_feature test_audio_mel_feature)
127127
list(REMOVE_ITEM TEST_OPS test_fused_gemm_epilogue_op)
128128
list(REMOVE_ITEM TEST_OPS test_fused_gemm_epilogue_grad_op)
129129
list(REMOVE_ITEM TEST_OPS test_fused_dot_product_attention_op)
130-
list(REMOVE_ITEM TEST_OPS test_fused_dot_product_attention_op_static)
131130
list(REMOVE_ITEM TEST_OPS test_fuse_dot_product_attention_pass)
132131

133132
if(((NOT WITH_ROCM) AND (NOT WITH_GPU)) OR WIN32)

test/legacy_test/test_fused_dot_product_attention_op_static.py

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,32 @@ def test_static_op(self):
8989
paddle.seed(312)
9090

9191
# call fused_dot_product_attention in static mode
92-
with paddle.static.program_guard(paddle.static.Program()):
93-
q = paddle.static.data(
94-
name="q", shape=self.q_shape, dtype=self.dtype
95-
)
96-
k = paddle.static.data(
97-
name="k", shape=self.kv_shape, dtype=self.dtype
98-
)
99-
v = paddle.static.data(
100-
name="v", shape=self.kv_shape, dtype=self.dtype
101-
)
102-
mask = paddle.static.data(
103-
name="mask", shape=self.mask_shape, dtype=self.dtype
104-
)
105-
106-
outs = fused_dot_product_attention(q, k, v, mask)
92+
# Use OldIrGuard to disable PIR mode for legacy static graph test
93+
from paddle.pir_utils import OldIrGuard
94+
95+
with OldIrGuard():
96+
main_program = paddle.static.Program()
97+
startup_program = paddle.static.Program()
98+
with paddle.static.program_guard(main_program, startup_program):
99+
q = paddle.static.data(
100+
name="q", shape=self.q_shape, dtype=self.dtype
101+
)
102+
k = paddle.static.data(
103+
name="k", shape=self.kv_shape, dtype=self.dtype
104+
)
105+
v = paddle.static.data(
106+
name="v", shape=self.kv_shape, dtype=self.dtype
107+
)
108+
mask = paddle.static.data(
109+
name="mask", shape=self.mask_shape, dtype=self.dtype
110+
)
111+
112+
outs = fused_dot_product_attention(q, k, v, mask)
107113

108114
exe = paddle.static.Executor(self.place)
115+
exe.run(startup_program)
109116
out_s = exe.run(
117+
main_program,
110118
feed={
111119
"q": q_data.astype('float16'),
112120
"k": k_data.astype('float16'),
@@ -117,37 +125,41 @@ def test_static_op(self):
117125
)
118126
np.testing.assert_allclose(out_s[0], out0)
119127

120-
# call cudnn_flash_attention in static mode
121-
with paddle.static.program_guard(paddle.static.Program()):
122-
q = paddle.static.data(
123-
name="q", shape=self.q_shape, dtype=self.dtype
124-
)
125-
k = paddle.static.data(
126-
name="k", shape=self.kv_shape, dtype=self.dtype
127-
)
128-
v = paddle.static.data(
129-
name="v", shape=self.kv_shape, dtype=self.dtype
130-
)
131-
mask = paddle.static.data(
132-
name="mask", shape=self.mask_shape, dtype=self.dtype
133-
)
134-
135-
outs = cudnn_flash_attention(
136-
q,
137-
k,
138-
v,
139-
mask,
140-
None,
141-
None,
142-
1.0,
143-
0.0,
144-
True,
145-
None,
146-
"post_scale_bias",
147-
)
148-
149-
exe = paddle.static.Executor(self.place)
150-
out_s = exe.run(
128+
# call cudnn_flash_attention in static mode
129+
main_program2 = paddle.static.Program()
130+
startup_program2 = paddle.static.Program()
131+
with paddle.static.program_guard(main_program2, startup_program2):
132+
q = paddle.static.data(
133+
name="q", shape=self.q_shape, dtype=self.dtype
134+
)
135+
k = paddle.static.data(
136+
name="k", shape=self.kv_shape, dtype=self.dtype
137+
)
138+
v = paddle.static.data(
139+
name="v", shape=self.kv_shape, dtype=self.dtype
140+
)
141+
mask = paddle.static.data(
142+
name="mask", shape=self.mask_shape, dtype=self.dtype
143+
)
144+
145+
outs = cudnn_flash_attention(
146+
q,
147+
k,
148+
v,
149+
mask,
150+
None,
151+
None,
152+
1.0,
153+
0.0,
154+
True,
155+
None,
156+
"post_scale_bias",
157+
)
158+
159+
exe2 = paddle.static.Executor(self.place)
160+
exe2.run(startup_program2)
161+
out_s = exe2.run(
162+
main_program2,
151163
feed={
152164
"q": q_data.astype('float16'),
153165
"k": k_data.astype('float16'),

0 commit comments

Comments
 (0)