未验证 提交 a771c1e1 编写于 作者: H HongyuJia 提交者: GitHub

[0D-Tensor] CINN supports reverse, fix infershape (#55337)

上级 f736f151
......@@ -1020,8 +1020,8 @@ std::shared_ptr<OpStrategy> StrategyForReverse(
std::vector<framework::shape_t> InferShapeForReverse(
const std::vector<framework::shape_t> &inputs_shape,
const framework::AttrMapType &attrs) {
CHECK(!inputs_shape.empty() && !inputs_shape[0].empty())
<< "The input's shape size is 0! Please check again.";
CHECK(!inputs_shape.empty())
<< "The input's shape is empty! Please check again.";
std::vector<framework::shape_t> res{inputs_shape[0]};
if (attrs.find("axis") != attrs.end()) {
auto axis = absl::get<std::vector<int>>(attrs.at("axis"));
......
......@@ -776,6 +776,44 @@ class TestBroadcastToOp3D(TestBroadcastToOp1D):
self.broadcast_shape = [3, 3, 3]
@OpTestTool.skip_if(
not is_compiled_with_cuda(), "x86 test will be skipped due to timeout."
)
class TestReverseOp(OpTest):
def setUp(self):
np.random.seed(2023)
self.dtype = "float32"
self.init_input()
def init_input(self):
self.inputs = {
"x": np.random.randint(-10, 10, []).astype(self.dtype),
}
self.target_shape = ()
def build_paddle_program(self, target):
x = paddle.to_tensor(self.inputs["x"], stop_gradient=False)
out = paddle.reverse(x, axis=[])
self.paddle_outputs = [out]
def build_cinn_program(self, target):
builder = NetBuilder("reverse_op")
x = builder.create_input(
cinn_dtype_convert(self.dtype), self.inputs["x"].shape, "x"
)
out = builder.reverse(x, [])
prog = builder.build()
res = self.get_cinn_output(prog, target, [x], [self.inputs["x"]], [out])
self.cinn_outputs = res
self.assertEqual(res[0].shape, self.target_shape)
def test_check_results(self):
self.check_outputs_and_grads()
@OpTestTool.skip_if(
not is_compiled_with_cuda(), "x86 test will be skipped due to timeout."
)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册