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

[Cherry-pick 2.5][Zero-Dim] paddle.static.data, squeeze, unbind, unstack, gather_nd and einsum support 0D #53602

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
22ea1ce
add test cases, test=allcase
zhengqiwen1997 Apr 21, 2023
a0e3ad3
fix test cases, test=allcase
zhengqiwen1997 Apr 21, 2023
b9b1c00
fix test cases, test=allcase
zhengqiwen1997 Apr 23, 2023
b4cdbda
assert_allclose, test=allcase
zhengqiwen1997 Apr 23, 2023
7547df9
1e-5 to 1e-4, test=allcase
zhengqiwen1997 Apr 24, 2023
112acc8
change rtol from 1e-4 to 1e-3, test=allcase
zhengqiwen1997 Apr 24, 2023
060930a
test=allcase
zhengqiwen1997 Apr 12, 2023
799b247
test=allcase
zhengqiwen1997 Apr 13, 2023
477d0a9
test=allcase
zhengqiwen1997 Apr 13, 2023
4913c91
test=allcase
zhengqiwen1997 Apr 13, 2023
30812f9
test=allcase
zhengqiwen1997 Apr 17, 2023
53cc56a
fix test cases, test=allcase
zhengqiwen1997 Apr 23, 2023
e0aa371
fix test cases, test=allcase
zhengqiwen1997 Apr 23, 2023
322a8af
modify the test_squeeze to not use Tensor type axis, test=allcase
zhengqiwen1997 Apr 24, 2023
1d7ee5f
add grad check for unbind and unstack, test=allcase
zhengqiwen1997 Apr 24, 2023
a367e3c
check for squeeze axis tensor type, test=allcase
zhengqiwen1997 Apr 24, 2023
a66ea6d
fix bug, test=allcase
zhengqiwen1997 Apr 27, 2023
47270d2
test=allcase
zhengqiwen1997 Apr 11, 2023
9c3f76c
test=allcase
zhengqiwen1997 Apr 11, 2023
5dd52d6
test=allcase
zhengqiwen1997 Apr 12, 2023
1b66e5b
test=allcase
zhengqiwen1997 Apr 12, 2023
2f4966a
test=allcase
zhengqiwen1997 Apr 12, 2023
d663661
test=allcase
zhengqiwen1997 Apr 12, 2023
2a8c93a
test=allcase
zhengqiwen1997 Apr 12, 2023
5a3ae83
test=allcase
zhengqiwen1997 Apr 13, 2023
40b1ae7
test=allcase
zhengqiwen1997 Apr 13, 2023
a166df9
test=allcase
zhengqiwen1997 Apr 14, 2023
c7c5307
test=allcase
zhengqiwen1997 Apr 14, 2023
9f3a5dc
test=allcase
zhengqiwen1997 Apr 18, 2023
14f0718
test=allcase
zhengqiwen1997 Apr 18, 2023
f80c8d3
test=allcase
zhengqiwen1997 Apr 19, 2023
662baab
test=allcase
zhengqiwen1997 Apr 19, 2023
2106c26
test=allcase
zhengqiwen1997 Apr 19, 2023
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
3 changes: 3 additions & 0 deletions paddle/phi/infermeta/unary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3761,6 +3761,9 @@ void SqueezeInferMeta(const MetaTensor& x,
if (!config.is_runtime && axes.FromTensor()) {
// compile time infershape, set all elements to -1.
int output_size = x.dims().size() - axes.GetData().size();
if (x.dims().size() == 0 && output_size == -1) {
output_size = 0;
}
std::vector<int64_t> vec_out_dims(output_size, -1);
out->set_dims(phi::make_ddim(vec_out_dims));
} else {
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def _as_lodtensor(data, place, dtype=None):
else dtype
)
if np.isscalar(data):
data = np.array([data]).astype(dtype)
data = np.array(data).astype(dtype)
elif isinstance(data, (list, tuple)):
data = np.array(data)
if data.dtype == np.object_:
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_compare_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_api_float(self):
paddle.enable_static()
with program_guard(Program(), Program()):
x = paddle.static.data(name='x', shape=[4], dtype='int64')
y = paddle.static.data(name='y', shape=[1], dtype='int64')
y = paddle.static.data(name='y', shape=[], dtype='int64')
op = eval("paddle.%s" % (self.op_type))
out = op(x, y)
exe = fluid.Executor(self.place)
Expand Down
7 changes: 7 additions & 0 deletions python/paddle/fluid/tests/unittests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ def test_dtype(self):
x3 = paddle.static.data(name="x3", shape=[2, 25])
self.assertEqual(x3.dtype, core.VarDesc.VarType.FP64)

def test_0D(self):
with program_guard(Program(), Program()):
x1 = paddle.static.data(name="x1_0D", shape=[])
self.assertEqual(x1.dtype, core.VarDesc.VarType.FP32)
x2 = paddle.static.data(name="x2_0D", shape=(), dtype="bool")
self.assertEqual(x2.dtype, core.VarDesc.VarType.BOOL)

def test_error(self):
with program_guard(Program(), Program()):

Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_deg2rad.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_dygraph(self):
class TestDeg2radAPI2(TestDeg2radAPI):
# Test input data type is int
def setUp(self):
self.x_np = 180
self.x_np = [180]
self.x_shape = [1]
self.out_np = np.pi
self.x_dtype = 'int64'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class TestExecutor(unittest.TestCase):
def net(self):
lr = paddle.static.data(name="lr", shape=[1], dtype='float32')
lr = paddle.static.data(name="lr", shape=[], dtype='float32')
x = paddle.static.data(name="x", shape=[None, 1], dtype='float32')
y = paddle.static.data(name="y", shape=[None, 1], dtype='float32')
y_predict = paddle.static.nn.fc(x, size=1)
Expand Down
16 changes: 8 additions & 8 deletions python/paddle/fluid/tests/unittests/test_gcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

class TestGcdAPI(unittest.TestCase):
def setUp(self):
self.x_np = 12
self.y_np = 20
self.x_np = [12]
self.y_np = [20]
self.x_shape = [1]
self.y_shape = [1]

Expand Down Expand Up @@ -81,14 +81,14 @@ class TestGcdAPI3(TestGcdAPI):
def setUp(self):
self.x_np = 0
self.y_np = 20
self.x_shape = [1]
self.y_shape = [1]
self.x_shape = []
self.y_shape = []


class TestGcdAPI4(TestGcdAPI):
def setUp(self):
self.x_np = 0
self.y_np = 0
self.x_np = [0]
self.y_np = [0]
self.x_shape = [1]
self.y_shape = [1]

Expand All @@ -97,5 +97,5 @@ class TestGcdAPI5(TestGcdAPI):
def setUp(self):
self.x_np = 12
self.y_np = -20
self.x_shape = [1]
self.y_shape = [1]
self.x_shape = []
self.y_shape = []
16 changes: 8 additions & 8 deletions python/paddle/fluid/tests/unittests/test_lcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class TestLcmAPI(unittest.TestCase):
def setUp(self):
self.x_np = 12
self.y_np = 20
self.x_shape = [1]
self.y_shape = [1]
self.x_shape = []
self.y_shape = []

def test_static_graph(self):
startup_program = fluid.Program()
Expand Down Expand Up @@ -81,14 +81,14 @@ class TestLcmAPI3(TestLcmAPI):
def setUp(self):
self.x_np = 0
self.y_np = 20
self.x_shape = [1]
self.y_shape = [1]
self.x_shape = []
self.y_shape = []


class TestLcmAPI4(TestLcmAPI):
def setUp(self):
self.x_np = 0
self.y_np = 0
self.x_np = [0]
self.y_np = [0]
self.x_shape = [1]
self.y_shape = [1]

Expand All @@ -97,5 +97,5 @@ class TestLcmAPI5(TestLcmAPI):
def setUp(self):
self.x_np = 12
self.y_np = -20
self.x_shape = [1]
self.y_shape = [1]
self.x_shape = []
self.y_shape = []
6 changes: 3 additions & 3 deletions python/paddle/fluid/tests/unittests/test_put_along_axis_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def setUp(self):
self.place = [paddle.CPUPlace()]
self.axis = 0
self.value_np = 99.0
self.value_shape = [1]
self.value_shape = []
self.x_feed = copy.deepcopy(self.x_np)
if core.is_compiled_with_cuda():
self.place.append(paddle.CUDAPlace(0))
Expand Down Expand Up @@ -240,7 +240,7 @@ def setUp(self):
self.place = [paddle.CPUPlace()]
self.axis = 0
self.value_np = 99.0
self.value_shape = [1]
self.value_shape = []
self.x_feed = copy.deepcopy(self.x_np)
if core.is_compiled_with_cuda():
self.place.append(paddle.CUDAPlace(0))
Expand All @@ -258,7 +258,7 @@ def setUp(self):
self.place = [paddle.CPUPlace()]
self.axis = 0
self.value_np = 99.0
self.value_shape = [1]
self.value_shape = []
self.x_feed = copy.deepcopy(self.x_np)
if core.is_compiled_with_cuda():
self.place.append(paddle.CUDAPlace(0))
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/fluid/tests/unittests/test_rad2deg.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_dygraph(self):

class TestRad2degAPI2(TestRad2degAPI):
def setUp(self):
self.x_np = np.pi / 2
self.x_np = [np.pi / 2]
self.x_shape = [1]
self.out_np = 90
self.x_dtype = 'float32'
Expand All @@ -83,7 +83,7 @@ def test_dygraph(self):
class TestRad2degAPI3(TestRad2degAPI):
# Test input data type is int
def setUp(self):
self.x_np = 1
self.x_np = [1]
self.x_shape = [1]
self.out_np = 180 / np.pi
self.x_dtype = 'int64'
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_trapezoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_static(self):
)
if self.dx is not None:
dx = paddle.static.data(
name="dx", shape=[1], dtype='float32'
name="dx", shape=[], dtype='float32'
)

exe = paddle.static.Executor(place)
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/fluid/tests/unittests/test_unbind_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_unbind(self):
x_1 = paddle.static.data(shape=[2, 3], dtype='float32', name='x_1')
[out_0, out_1] = tensor.unbind(input=x_1, axis=0)
input_1 = np.random.random([2, 3]).astype("float32")
axis = paddle.static.data(shape=[1], dtype='int32', name='axis')
axis = paddle.static.data(shape=[], dtype='int32', name='axis')
exe = fluid.Executor(place=fluid.CPUPlace())

[res_1, res_2] = exe.run(
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_layers_unbind(self):
x_1 = paddle.static.data(shape=[2, 3], dtype='float32', name='x_1')
[out_0, out_1] = paddle.unbind(input=x_1, axis=0)
input_1 = np.random.random([2, 3]).astype("float32")
axis = paddle.static.data(shape=[1], dtype='int32', name='axis')
axis = paddle.static.data(shape=[], dtype='int32', name='axis')
exe = fluid.Executor(place=fluid.CPUPlace())

[res_1, res_2] = exe.run(
Expand Down
Loading