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

[ONNX]Mod operator, bug fix #6160

Merged
merged 2 commits into from
Aug 7, 2020
Merged

Conversation

siju-samuel
Copy link
Member

#6106
Reference Onnx mod
@jwfromm Please help to review this PR. TIA

@@ -2374,17 +2374,11 @@ def test_pooling():
auto_pad='SAME_UPPER')


def verify_mod(x_shape, y_shape, fmod, dtype='float32'):
def verify_mod(x_shape, y_shape, fmod, out_shape, dtype='float32'):
x_np = np.random.uniform(size=x_shape).astype(dtype)
y_np = np.random.uniform(size=y_shape).astype(dtype)
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests are only passing because np.random.uniform is always positive. If you use negative numbers, the behavior of mod changes based on the value of fmod. We should use a different random input generator than uniform anyway since values between 0 and 1 dont make sense for mod testing anyway.

op_name = "floor_mod"
else:
op_name = "mod"
op_name = "mod"
Copy link
Contributor

Choose a reason for hiding this comment

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

Some handling for fmod=1 will need to be added here. From the onnx operator definition, fmod=1 implies that the sign of the dividend should be kept in the output. When the dividend is negative, this differs from default relay behavior. We'll probably have to multiply the output by relay.sign(inputs[0]) when fmod=1 to make this work.

@siju-samuel siju-samuel force-pushed the onnx_fmod_flaky_test branch from cf38f8a to 6751c29 Compare July 28, 2020 16:51
@jwfromm
Copy link
Contributor

jwfromm commented Jul 28, 2020

Thanks for the changes, this looks good to me now.

@jwfromm
Copy link
Contributor

jwfromm commented Aug 5, 2020

@masahi, this PR made me realize that relay.mod has the functionality of np.fmod and relay.floor_mod is equivalent to np.mod, which seems kind of backwards. Do you know if that's a bug or intentional? If it's on purpose, we should get this PR merged.

@masahi
Copy link
Member

masahi commented Aug 5, 2020

I don't know if this is intentional or not, but since we cannot change Relay definition easily, having workaround in the frontend side seems a better alternative.

@@ -530,10 +530,11 @@ class Mod(OnnxOpConverter):
@classmethod
def _impl_v1(cls, inputs, attr, params):
assert len(inputs) == 2, "Mod op take 2 inputs, {} given".format(len(inputs))
if attr['fmod'] == 1:
if attr['fmod'] == 0:
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a comment here to avoid confusion?

@masahi masahi self-assigned this Aug 5, 2020
@masahi masahi merged commit 87f9010 into apache:master Aug 7, 2020
@masahi
Copy link
Member

masahi commented Aug 7, 2020

Thanks @siju-samuel @jwfromm

wjliu1998 pushed a commit to wjliu1998/incubator-tvm that referenced this pull request Aug 13, 2020
* Onnx mod, bug fix

* Added comment for the mod/floor_mod behaviour difference between numpy & relay
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Aug 26, 2020
* Onnx mod, bug fix

* Added comment for the mod/floor_mod behaviour difference between numpy & relay
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Aug 26, 2020
* Onnx mod, bug fix

* Added comment for the mod/floor_mod behaviour difference between numpy & relay
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Aug 26, 2020
* Onnx mod, bug fix

* Added comment for the mod/floor_mod behaviour difference between numpy & relay
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Sep 2, 2020
* Onnx mod, bug fix

* Added comment for the mod/floor_mod behaviour difference between numpy & relay
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Sep 3, 2020
* Onnx mod, bug fix

* Added comment for the mod/floor_mod behaviour difference between numpy & relay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants