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 8th No.2】为 Paddle 新增 baddbmm API #70757

Open
wants to merge 38 commits into
base: develop
Choose a base branch
from

Conversation

Qin-sx added 12 commits December 5, 2024 06:36
	modified:   paddle/fluid/pybind/pybind.cc
	modified:   paddle/phi/core/memory/stats.cc
	modified:   paddle/phi/core/memory/stats.h
	modified:   python/paddle/device/cuda/__init__.py
	modified:   paddle/fluid/pybind/pybind.cc
	modified:   python/paddle/device/cuda/__init__.py
	modified:   paddle/fluid/pybind/pybind.cc
	modified:   paddle/phi/core/memory/stats.cc
	modified:   paddle/phi/core/memory/stats.h
	modified:   test/cpp/fluid/memory/stats_test.cc
	new file:   test/legacy_test/test_cuda_memory_stats.py
	new file:   test/legacy_test/test_cuda_reset_peak_memory_stats.py
	new file:   test/legacy_test/test_cuda_reset_max_memory_allocated.py
	modified:   python/paddle/device/cuda/__init__.py
	modified:   test/legacy_test/test_cuda_memory_stats.py
	modified:   test/legacy_test/test_cuda_reset_max_memory_allocated.py
	modified:   test/legacy_test/test_cuda_reset_peak_memory_stats.py
	modified:   paddle/fluid/pybind/pybind.cc
	modified:   paddle/phi/core/memory/stats.cc
	modified:   paddle/phi/core/memory/stats.h
	modified:   test/cpp/fluid/memory/stats_test.cc
	modified:   python/paddle/device/cuda/__init__.py
	modified:   test/legacy_test/test_cuda_reset_max_memory_allocated.py
	new file:   test/legacy_test/test_cuda_reset_max_memory_reserved.py
	modified:   paddle/fluid/pybind/pybind.cc
	modified:   python/paddle/device/cuda/__init__.py
	deleted:    test/legacy_test/test_cuda_memory_stats.py
	deleted:    test/legacy_test/test_cuda_reset_peak_memory_stats.py
	modified:   paddle/phi/infermeta/ternary.cc
	modified:   paddle/phi/infermeta/ternary.h
	new file:   paddle/phi/kernels/baddbmm_grad_kernel.h
	new file:   paddle/phi/kernels/baddbmm_kernel.h
	new file:   paddle/phi/kernels/cpu/baddbmm_grad_kernel.cc
	new file:   paddle/phi/kernels/cpu/baddbmm_kernel.cc
	modified:   paddle/phi/kernels/funcs/blas/blas.h
	modified:   paddle/phi/kernels/funcs/blas/blas_impl.cu.h
	modified:   paddle/phi/kernels/funcs/blas/blas_impl.h
	new file:   paddle/phi/kernels/gpu/baddbmm_grad_kernel.cu
	new file:   paddle/phi/kernels/gpu/baddbmm_kernel.cu
	new file:   paddle/phi/kernels/impl/baddbmm_grad_kernel_impl.h
	new file:   paddle/phi/kernels/impl/baddbmm_kernel_impl.h
	modified:   paddle/phi/ops/yaml/backward.yaml
	modified:   paddle/phi/ops/yaml/ops.yaml
	modified:   python/paddle/__init__.py
	modified:   python/paddle/tensor/__init__.py
	modified:   python/paddle/tensor/math.py
	modified:   paddle/fluid/pir/dialect/op_generator/decomp_interface_gen_op_list.py
	modified:   paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/multiary_infer_sym.cc
	modified:   paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/multiary_infer_sym.h
	modified:   paddle/fluid/primitive/decomp_rule/decomp_rule/composite.h
	modified:   paddle/phi/api/ext/tensor_compat.h
	modified:   paddle/phi/kernels/impl/baddbmm_grad_kernel_impl.h
	modified:   paddle/phi/ops/yaml/op_compat.yaml
	new file:   test/legacy_test/test_baddbmm_op.py
Copy link

paddle-bot bot commented Jan 9, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Jan 9, 2025
@luotao1 luotao1 self-assigned this Jan 10, 2025
Qin-sx and others added 14 commits January 10, 2025 14:35
	modified:   ../paddle/phi/kernels/funcs/blas/blas_impl.cu.h
	modified:   ../paddle/phi/kernels/impl/baddbmm_kernel_impl.h
	modified:   ../paddle/phi/ops/yaml/ops.yaml
	modified:   ../test/legacy_test/test_baddbmm_op.py
	modified:   ../test/legacy_test/test_baddbmm_op.py
	modified:   ../test/legacy_test/test_baddbmm_op.py
	modified:   ../test/legacy_test/test_baddbmm_op.py
	modified:   ../test/legacy_test/test_baddbmm_op.py
	modified:   ../test/legacy_test/test_baddbmm_op.py
	new file:   ../test/legacy_test/test_baddbmm_op1.py
	new file:   ../test/legacy_test/test_baddbmm_op2.py
	new file:   ../test/legacy_test/test_baddbmm_op3.py
	modified:   ../test/legacy_test/test_baddbmm_op1.py
	modified:   ../paddle/phi/api/ext/tensor_compat.h
	modified:   ../paddle/phi/kernels/funcs/blas/blas_impl.hip.h
	modified:   ../paddle/phi/kernels/funcs/blas/blas_impl.hip.h
	modified:   ../test/legacy_test/test_baddbmm_op3.py
	new file:   ../test/legacy_test/test_baddbmm_op4.py
@@ -163,6 +163,67 @@ bool Addmm_OpInferSymbolicShape(pir::Operation *op,
return AddmmOpInferSymbolicShape(op, infer_context);
}

bool BaddbmmOpInferSymbolicShape(
Copy link
Contributor

Choose a reason for hiding this comment

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

调整代码位置,函数名按照ABC排列

Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到,已修改,谢谢

@@ -21,6 +21,8 @@ namespace paddle::dialect {
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Accuracy)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Addmm)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Addmm_)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Baddbmm)
Copy link
Contributor

Choose a reason for hiding this comment

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

调整代码位置,函数名按照ABC排列

Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到,已修改,谢谢

@@ -0,0 +1,33 @@
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

新增文件注意一下copyright 年份

Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到,新增文件均已修改,谢谢

@@ -1183,6 +1183,152 @@ inline void Blas<phi::GPUContext>::GEMM(CBLAS_TRANSPOSE transA,
#endif // CUDA_VERSION >= 8000
}

template <>
template <typename T, typename U>
Copy link
Contributor

Choose a reason for hiding this comment

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

这里是否需要和.h一致 template <typename T, typename U = T>

Copy link
Contributor

Choose a reason for hiding this comment

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

辛苦检查同级文件

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里在模板偏特化时,应该不能再设置默认的模板参数了。
以下为报错提示:

/Paddle_2_GPU/Paddle/paddle/phi/kernels/funcs/blas/blas_impl.cu.h(1187): error: a default template argument cannot be specified on the declaration of a member of a class template outside of its class

@DrownFish19
Copy link
Contributor

辛苦在PR描述中补充精度验证代码和精度误差

Qin-sx and others added 4 commits January 14, 2025 18:50
	modified:   paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/multiary_infer_sym.cc
	modified:   paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/multiary_infer_sym.h
	modified:   paddle/phi/kernels/baddbmm_grad_kernel.h
	modified:   paddle/phi/kernels/baddbmm_kernel.h
	modified:   paddle/phi/kernels/cpu/baddbmm_grad_kernel.cc
	modified:   paddle/phi/kernels/cpu/baddbmm_kernel.cc
	modified:   paddle/phi/kernels/gpu/baddbmm_grad_kernel.cu
	modified:   paddle/phi/kernels/gpu/baddbmm_kernel.cu
	modified:   paddle/phi/kernels/impl/baddbmm_grad_kernel_impl.h
	modified:   paddle/phi/kernels/impl/baddbmm_kernel_impl.h
	modified:   test/legacy_test/test_baddbmm_op.py
	modified:   test/legacy_test/test_baddbmm_op1.py
	modified:   test/legacy_test/test_baddbmm_op2.py
	modified:   test/legacy_test/test_baddbmm_op3.py
	modified:   test/legacy_test/test_baddbmm_op4.py
	modified:   test/legacy_test/CMakeLists.txt
	modified:   test/legacy_test/test_baddbmm_op.py
	new file:   test/legacy_test/test_baddbmm_op5.py
	modified:   paddle/phi/kernels/funcs/blas/blas_impl.hip.h
@Qin-sx
Copy link
Contributor Author

Qin-sx commented Jan 17, 2025

辛苦在PR描述中补充精度验证代码和精度误差

验证代码添加在了RFC文档中。

以下为测试结果:

  1. float32类型
max diff between paddle matmul and torch baddbmm is 0.0021514892578125
max diff between paddle baddbmm and torch baddbmm is 0.0
max diff between paddle baddbmm and paddle matmul is 0.0021514892578125
  1. float16类型
max diff between paddle matmul and torch baddbmm is 0.25
max diff between paddle baddbmm and torch baddbmm is 0.0
max diff between paddle baddbmm and paddle matmul is 0.25
  1. bfloat16类型
max diff between paddle matmul and torch baddbmm is 2.0
max diff between paddle baddbmm and torch baddbmm is 0.0
max diff between paddle baddbmm and paddle matmul is 2.0

@Qin-sx
Copy link
Contributor Author

Qin-sx commented Jan 17, 2025

	modified:   paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/multiary_infer_sym.cc
	modified:   paddle/phi/infermeta/ternary.cc
	modified:   paddle/phi/kernels/impl/baddbmm_grad_kernel_impl.h
	modified:   paddle/phi/kernels/impl/baddbmm_kernel_impl.h
	modified:   python/paddle/tensor/math.py
	modified:   test/legacy_test/CMakeLists.txt
	new file:   test/legacy_test/test_baddbmm_op6.py
	modified:   ../paddle/phi/infermeta/ternary.cc
	modified:   ../test/legacy_test/test_baddbmm_op3.py
	modified:   ../python/paddle/tensor/math.py
	new file:   ../test/legacy_test/test_baddbmm_op7.py
	modified:   ../test/legacy_test/CMakeLists.txt
	modified:   ../test/legacy_test/test_baddbmm_op7.py
	modified:   paddle/phi/kernels/funcs/blas/blas_impl.cu.h
@Qin-sx
Copy link
Contributor Author

Qin-sx commented Jan 23, 2025

关于PR-CI-Coverage没有覆盖到的两部分的相关issue
#70848
#70888

raise ValueError(
f"If input's dimension[2] is not equal to y's dimension[2], input's dimension[2] must be 1. But received input's dimension[2] = {input_shape[2]}, y's dimension[2] = {y_shape[2]}"
)
# 上面的判断已经包含了这种情况
Copy link
Contributor

Choose a reason for hiding this comment

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

注释如不必要,可以删除

Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到,已修改,谢谢

raise ValueError(
f"If input's dimension[2] is not equal to y's dimension[2], input's dimension[2] must be 1. But received input's dimension[2] = {input_shape[2]}, y's dimension[2] = {y_shape[2]}"
)
# 上面的判断已经包含了这种情况
Copy link
Contributor

Choose a reason for hiding this comment

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

注释问题

Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到,已修改,谢谢

	modified:   ../paddle/phi/api/ext/tensor_compat.h
	modified:   ../python/paddle/tensor/math.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants