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

[PIR] Align reshape infermeta to legacy IR infershape #62136

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
2 changes: 1 addition & 1 deletion paddle/phi/api/yaml/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@
args : (Tensor x)
output : Tensor(out)
infer_meta :
func : LogicalNotInfermeta
func : LogicalNotInferMeta
kernel :
func : logical_not
data_type : x
Expand Down
21 changes: 19 additions & 2 deletions paddle/phi/infermeta/unary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2188,7 +2188,7 @@ void KthvalueInferMeta(const MetaTensor& x,
indices->set_dtype(x.dtype());
}

void LogicalNotInfermeta(const MetaTensor& x, MetaTensor* out) {
void LogicalNotInferMeta(const MetaTensor& x, MetaTensor* out) {
UnchangedInferMeta(x, out);
if (!(out->is_same_tensor(x))) {
out->set_dtype(DataType::BOOL);
Expand Down Expand Up @@ -3588,11 +3588,28 @@ void ReshapeInferMeta(const MetaTensor& x,
const IntArray& shape,
MetaTensor* out,
MetaConfig config) {
auto& shape_data = shape.GetData();
auto shape_data = shape.GetData();
PADDLE_ENFORCE_NOT_NULL(out,
phi::errors::InvalidArgument(
"Output(Out) of ReshapeOp should not be null."));
if (!config.is_runtime && shape.FromTensor()) {
const int64_t copy_dim_flag = 0;
const auto& in_dims = x.dims();
for (size_t i = 0; i < shape_data.size(); ++i) {
if (shape_data[i] == copy_dim_flag) {
PADDLE_ENFORCE_LT(
static_cast<int>(i),
in_dims.size(),
phi::errors::InvalidArgument(
"The index of 0 in `shape` must be less than "
"the input tensor X's dimensions. But received shape[%d] "
"= 0, X's dimensions = %d, X's shape = [%s].",
i,
in_dims.size(),
in_dims));
shape_data[i] = static_cast<int>(in_dims[static_cast<int>(i)]);
}
}
out->set_dims(common::make_ddim(shape_data));
out->share_lod(x);
out->set_dtype(x.dtype());
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/infermeta/unary.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ void KthvalueInferMeta(const MetaTensor& x,
MetaTensor* indices,
MetaConfig = MetaConfig());

void LogicalNotInfermeta(const MetaTensor& x, MetaTensor* out);
void LogicalNotInferMeta(const MetaTensor& x, MetaTensor* out);

void LogsumexpInferMeta(const MetaTensor& input,
const std::vector<int64_t>& axis,
Expand Down
14 changes: 10 additions & 4 deletions test/legacy_test/test_reshape_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,15 +737,21 @@ def test_static(self):
class TestReshapePirValueListShape(unittest.TestCase):
def test_value_list_shape(self):
with paddle.pir_utils.IrGuard():
x = paddle.static.data(
'x',
[3],
)
x = paddle.static.data('x', [3])
shape = [1, paddle.full([], 3)]
out = paddle.reshape(x, shape)
self.assertEqual(out.shape, [1, -1])


class TestReshapePirTensorWithZeroShape(unittest.TestCase):
def test_tensor_with_zero_shape(self):
with paddle.pir_utils.IrGuard():
x = paddle.static.data('x', [10, -1])
shape = [0, paddle.shape(x)[1]]
out = paddle.reshape(x, shape)
self.assertEqual(out.shape, [10, -1])


if __name__ == "__main__":
paddle.enable_static()
unittest.main()