Skip to content

[Torch] Support bincount and scatter_add ops - #6740

Merged
tqchen merged 4 commits into
apache:mainfrom
masahi:bincount-scatter_add
Oct 24, 2020
Merged

[Torch] Support bincount and scatter_add ops#6740
tqchen merged 4 commits into
apache:mainfrom
masahi:bincount-scatter_add

Conversation

@masahi

@masahi masahi commented Oct 23, 2020

Copy link
Copy Markdown
Member

Add numpy style bincount op converter by combinations of existing ops.
https://pytorch.org/docs/stable/generated/torch.bincount.html

This is a part of supporting hummingbird project. Also add a scatter_add op conversion, as requested.

I hope performance would not be too bad, so that we don't have to implement a native bincount op.

please review @siju-samuel @t-vi
cc @interesaaat

@t-vi t-vi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the type for bincount would be good to improve, otherwise LGTM. Thank you @masahi

Comment thread python/tvm/relay/frontend/pytorch.py Outdated
Comment thread tests/python/frontend/pytorch/test_forward.py

@t-vi t-vi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @masahi.

@masahi
masahi force-pushed the bincount-scatter_add branch from decb436 to c3e042f Compare October 23, 2020 21:53
@tqchen
tqchen merged commit efe3a79 into apache:main Oct 24, 2020
@tqchen

tqchen commented Oct 24, 2020

Copy link
Copy Markdown
Member

Thanks @masahi for contributing! Thanks @t-vi for reviewing!

trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Oct 29, 2020
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Dec 2, 2020
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Dec 4, 2020
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Dec 4, 2020
@apivovarov

apivovarov commented Sep 7, 2022

Copy link
Copy Markdown
Contributor

Does the following code in _bincount() require relay.vm.compile()? Because _op.zeros() is called for a shape which is not known at the compilation

data = inputs[0]
maximum = _op.max(data)
dim = maximum + _expr.const(1, dtype="int64")
counts = _op.zeros(_op.reshape(dim, [1]), out_dtype)

@masahi

masahi commented Sep 7, 2022

Copy link
Copy Markdown
Member Author

Yes, bincount requires VM compile.

@apivovarov

apivovarov commented Sep 9, 2022

Copy link
Copy Markdown
Contributor

I'm working on adding TF bincount support. I found thattf.bincount internally uses tf.shape. But looks like tf.shape is not compatible with relay.vm. Instead of determining the shape at the runtime vm.compiler just creates new parameter which should be provided by user when calling vm.run(). https://discuss.tvm.apache.org/t/tf-shape-and-relay-vm-strange-result/13505

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.

4 participants