-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Prim] Add prod backward composite rule #51238
Changes from 16 commits
a320174
65642d1
0495719
b88ca25
d08874f
fee42de
bc6282e
e22b142
6d59c31
d7a432a
6978193
e5960aa
0d6e248
e9a952a
4b859d3
8605ea2
d460ef8
ef883ed
89f3c74
0c0ef21
905eb55
af03ba4
13812dd
c2deb9d
5f15bf0
97a5074
5ab58b9
8456de7
fefccc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -352,6 +352,8 @@ class TestProdOp(OpTest): | |
def setUp(self): | ||
self.op_type = "reduce_prod" | ||
self.python_api = raw_reduce_prod | ||
self.prim_op_type = "prim" | ||
|
||
self.init_data_type() | ||
self.inputs = {'X': np.random.random((5, 6, 10)).astype(self.data_type)} | ||
self.outputs = {'Out': self.inputs['X'].prod(axis=0)} | ||
|
@@ -365,16 +367,20 @@ def test_check_output(self): | |
self.check_output(check_eager=True) | ||
|
||
def test_check_grad(self): | ||
self.check_grad(['X'], 'Out', check_eager=True) | ||
self.check_grad(['X'], 'Out', check_eager=True, check_prim=True) | ||
|
||
|
||
class TestProdOp_ZeroDim(OpTest): | ||
def setUp(self): | ||
self.python_api = paddle.prod | ||
self.op_type = "reduce_prod" | ||
self.prim_op_type = "prim" | ||
self.inputs = {'X': np.random.random([]).astype("float64")} | ||
self.outputs = {'Out': self.inputs['X'].prod()} | ||
self.attrs = {'dim': [], 'reduce_all': True} | ||
# reduce doesn't support float64 in cinn. | ||
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. will it raise error when test fp64 with other test(not 0D tensor) in cinn? 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. fp64 added in test |
||
# 0-D tensor doesn't support in cinn | ||
self.enable_cinn = False | ||
|
||
def test_check_output(self): | ||
self.check_output(check_eager=True) | ||
|
@@ -387,6 +393,7 @@ class TestProd6DOp(OpTest): | |
def setUp(self): | ||
self.op_type = "reduce_prod" | ||
self.python_api = raw_reduce_prod | ||
self.prim_op_type = "prim" | ||
self.init_data_type() | ||
self.inputs = { | ||
'X': np.random.random((5, 6, 2, 3, 4, 2)).astype(self.data_type) | ||
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. confirm all dtypes has been tested (FP16, FP32,Fp64) 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. FP16 is not supported, Fp64 has been added 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. |
||
|
@@ -405,13 +412,14 @@ def test_check_output(self): | |
self.check_output(check_eager=True) | ||
|
||
def test_check_grad(self): | ||
self.check_grad(['X'], 'Out', check_eager=True) | ||
self.check_grad(['X'], 'Out', check_eager=True, check_prim=True) | ||
|
||
|
||
class TestProd8DOp(OpTest): | ||
def setUp(self): | ||
self.op_type = "reduce_prod" | ||
self.python_api = raw_reduce_prod | ||
self.prim_op_type = "prim" | ||
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. if don't test prim delete this 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. done |
||
self.init_data_type() | ||
self.inputs = { | ||
'X': np.random.random((2, 5, 3, 2, 2, 3, 4, 2)).astype( | ||
|
@@ -1036,15 +1044,16 @@ def test_check_grad(self): | |
|
||
class TestReduceSumOpError(unittest.TestCase): | ||
def test_errors(self): | ||
with program_guard(Program(), Program()): | ||
# The input type of reduce_sum_op must be Variable. | ||
x1 = fluid.create_lod_tensor( | ||
np.array([[-1]]), [[1]], fluid.CPUPlace() | ||
) | ||
self.assertRaises(TypeError, paddle.sum, x1) | ||
# The input dtype of reduce_sum_op must be float32 or float64 or int32 or int64. | ||
x2 = paddle.static.data(name='x2', shape=[-1, 4], dtype="uint8") | ||
self.assertRaises(TypeError, paddle.sum, x2) | ||
with paddle.fluid.framework._static_guard(): | ||
with program_guard(Program(), Program()): | ||
# The input type of reduce_sum_op must be Variable. | ||
x1 = fluid.create_lod_tensor( | ||
np.array([[-1]]), [[1]], fluid.CPUPlace() | ||
) | ||
self.assertRaises(TypeError, paddle.sum, x1) | ||
# The input dtype of reduce_sum_op must be float32 or float64 or int32 or int64. | ||
x2 = paddle.static.data(name='x2', shape=[-1, 4], dtype="uint8") | ||
self.assertRaises(TypeError, paddle.sum, x2) | ||
|
||
|
||
class API_TestSumOp(unittest.TestCase): | ||
|
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.
use unsqueezeapi replace
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.
done