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

enable 1-D axis in cumsum #17650

Merged
merged 2 commits into from
Jul 12, 2023
Merged

Conversation

xczhai
Copy link
Contributor

@xczhai xczhai commented May 22, 2023

Details:

  • enable 1-D axis in cumsum, which is aligned with ort

Tickets:

  • 111483

@xczhai xczhai requested a review from a team as a code owner May 22, 2023 07:57
@github-actions github-actions bot added the category: ONNX FE OpenVINO ONNX FrontEnd label May 22, 2023
tomdol
tomdol previously requested changes Jun 2, 2023
axis = inputs.at(1); // optional input, 0-D tensor
// optional input, 0-D or 1-D tensor
const auto& axis_shape = inputs.at(1).get_partial_shape();
NGRAPH_CHECK(axis_shape.rank().get_length() == 0 || axis_shape.rank().get_length() == 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no axis input check in the core operator intentionally so I'd rather not add it here either https://github.com/openvinotoolkit/openvino/blob/master/src/core/src/op/cum_sum.cpp#L47. @mitruska any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend to use interpret_as_scalar helper as a common solution for such cases. It also has corresponding checks. Example:

if (ng_inputs.size() > 1) {
beta = ngraph::onnx_import::reshape::interpret_as_scalar(ng_inputs.at(1));

const auto& axis_shape = inputs.at(1).get_partial_shape();
NGRAPH_CHECK(axis_shape.rank().get_length() == 0 || axis_shape.rank().get_length() == 1,
"axis shape should be 0-D or 1-D.");
axis =
Copy link
Contributor

Choose a reason for hiding this comment

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

Although ONNX only allows scalar axis input I think this is ok. I'd like to see it demonstrated with even a single test though. Please add it to this file https://github.com/openvinotoolkit/openvino/blob/master/src/frontends/onnx/tests/onnx_import.in.cpp#L621 and use any of the existing CumSum tests as a template.

@tomdol tomdol requested a review from mitruska June 2, 2023 08:44
axis = inputs.at(1); // optional input, 0-D tensor
// optional input, 0-D or 1-D tensor
const auto& axis_shape = inputs.at(1).get_partial_shape();
NGRAPH_CHECK(axis_shape.rank().get_length() == 0 || axis_shape.rank().get_length() == 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend to use interpret_as_scalar helper as a common solution for such cases. It also has corresponding checks. Example:

if (ng_inputs.size() > 1) {
beta = ngraph::onnx_import::reshape::interpret_as_scalar(ng_inputs.at(1));

NGRAPH_CHECK(axis_shape.rank().get_length() == 0 || axis_shape.rank().get_length() == 1,
"axis shape should be 0-D or 1-D.");
axis =
axis_shape.rank().get_length() == 0 ? inputs.at(1) : std::make_shared<default_opset::Squeeze>(inputs.at(1));
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid issues get_legth() shouldn't be called without dynamism check,
my suggestion is to check the shape and call the helper from #include "utils/reshape.hpp":

Suggested change
axis_shape.rank().get_length() == 0 ? inputs.at(1) : std::make_shared<default_opset::Squeeze>(inputs.at(1));
axis_shape.is_dynamic() ? inputs.at(1) : reshape::interpret_as_scalar(inputs.at(1));

@github-actions
Copy link
Contributor

github-actions bot commented Jul 2, 2023

This PR will be closed in a week because of 2 weeks of no activity.

@github-actions github-actions bot added the Stale label Jul 2, 2023
@wenjiew
Copy link

wenjiew commented Jul 4, 2023

@xczhai Can we look into the review feedback and address these? Thanks!

@github-actions github-actions bot removed the Stale label Jul 5, 2023
@xczhai xczhai force-pushed the onnx_fix_cumsum branch from 301a8e9 to 949c553 Compare July 12, 2023 08:03
@xczhai
Copy link
Contributor Author

xczhai commented Jul 12, 2023

fix according to the comments.
new implement can support the pattern below. The axis can be 1-D tensor.
image

@xczhai xczhai requested review from tomdol and mitruska July 12, 2023 08:12
@mitruska mitruska requested a review from mbencer July 12, 2023 08:20
@mitruska mitruska dismissed tomdol’s stale review July 12, 2023 10:51

Comments are applied, dismissed due to absence of the reviewer.

@mitruska mitruska enabled auto-merge (squash) July 12, 2023 11:14
@mitruska mitruska merged commit 5630d3a into openvinotoolkit:master Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: ONNX FE OpenVINO ONNX FrontEnd
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants