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

[Relay/TOPI][TFLite] Implemented MATRIX_SET_DIAG Operator for Relay/TOPI and TFLite Frontend. #6303

Merged
merged 4 commits into from
Aug 27, 2020

Conversation

jainris
Copy link
Contributor

@jainris jainris commented Aug 19, 2020

  • Added implementation for MATRIX_SET_DIAG Operator in Relay and TOPI.
  • Added tests for MATRIX_SET_DIAG Operator in Relay and TOPI.
  • Added implementation for MATRIX_SET_DIAG Operator for TFLite Frontend.
  • Added tests for MATRIX_SET_DIAG Operator for TFLite Frontend.

@jainris
Copy link
Contributor Author

jainris commented Aug 19, 2020

Comment on lines +3112 to +3113
auto min_dim = if_then_else(input->shape[d_ndims - 1] >= input->shape[d_ndims],
input->shape[d_ndims], input->shape[d_ndims - 1]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is if_then_else appropriate here? Could a ? x : y not be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing.
if_then_else is needed here because input->shape[i] is a PrimExpr, and so a ? x : y can't be used.

Comment on lines +2662 to +2663
diagonal_shape = list(input_shape[:-2])
diagonal_shape.append(min(input_shape[-2], input_shape[-1]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the broadcasting case be tested here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TFLite MATRIX_SET_DIAG doesn't seem to be a broadcast operator. So, I'll change the registration to be injective.

@mbaret
Copy link
Contributor

mbaret commented Aug 24, 2020

Also cc @siju-samuel

.set_support_level(10)
.add_type_rel("MatrixSetDiag", MatrixSetDiagRel)
.set_attr<FTVMCompute>("FTVMCompute", MatrixSetDiagCompute)
.set_attr<TOpPattern>("TOpPattern", kBroadcast);
Copy link
Member

Choose a reason for hiding this comment

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

Why kBroadcast? i think it shud be injective.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing.
Changed it to be injective.

[out])

def test_forward_matrix_set_diag():
""" MATRIX_SET_DIAG """
Copy link
Member

Choose a reason for hiding this comment

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

add a pkg version check > '1.14.0'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The API docs seem to suggest that matrix_set_diag is present even in version '1.0'.
So, is there some other reason to add this check?

* \param tag output tensor tag.
* \return new tensor with given diagonal values.
*/
inline Tensor matrix_set_diag(const Tensor& input, const Tensor& diagonal,
Copy link
Member

Choose a reason for hiding this comment

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

A suggestion:- may be if we can support alignment and k(offset) similar to MatrixSetDiagV3 in tf, it will be good. we can support directly for tensorflow ops as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That might take some time.
Would it be fine to have that in a follow-up PR?

@FrozenGene FrozenGene merged commit 082f27e into apache:master Aug 27, 2020
@FrozenGene
Copy link
Member

Thanks @jainris @siju-samuel @mbaret it is merged. For the alignment, wish @jainris could follow up, thanks!

kevinthesun pushed a commit to kevinthesun/tvm that referenced this pull request Sep 17, 2020
…OPI and TFLite Frontend. (apache#6303)

* Corrected docstring error.

* Minor changes.

* Changed MATRIX_SET_DIAG registration from broadcast to injective.
kevinthesun pushed a commit to kevinthesun/tvm that referenced this pull request Sep 18, 2020
…OPI and TFLite Frontend. (apache#6303)

* Corrected docstring error.

* Minor changes.

* Changed MATRIX_SET_DIAG registration from broadcast to injective.
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Sep 18, 2020
…OPI and TFLite Frontend. (apache#6303)

* Corrected docstring error.

* Minor changes.

* Changed MATRIX_SET_DIAG registration from broadcast to injective.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants