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

[Op][Manip] collapse_sum_like, collapse_sum_to #87

Merged
merged 11 commits into from
Jan 8, 2023

Conversation

SiriusNEO
Copy link
Contributor

This PR introduces two operators collapse_sum_like and collapse_sum_to which are mainly used in automatic differentiation.

The shape inference rule of collapse_sum can be described as below:

  • We have a data_shape and target_shape. collapse_sum collapses data_shape to target_shape.
  • Scan their shapes from right to left. There are only three cases which are permitted:
  • Case 1: axes in target_shape but not in data_shape. E.g. data_shape=(2, 3, 4, 5), target_shape=(4, 5). Here 2, 3 are these axes.
  • Case 2: Axes are equal. E.g. 4, 5 in the above case.
  • Case 3: Axes are not equal but the axis in target_shape is 1. E.g. data_shape=(2, 4, 5), target_shape=(2, 1, 5) is legal.

In fact just the reversed rule of broadcasting.

Copy link
Contributor

@Ubospica Ubospica left a comment

Choose a reason for hiding this comment

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

Overall looks great, just wanna update comments

src/relax/op/tensor/manipulate.h Outdated Show resolved Hide resolved
tests/python/relax/test_op_manipulate.py Outdated Show resolved Hide resolved
python/tvm/relax/op/manipulate.py Outdated Show resolved Hide resolved
python/tvm/relax/op/manipulate.py Outdated Show resolved Hide resolved
python/tvm/relax/op/manipulate.py Outdated Show resolved Hide resolved
src/relax/op/tensor/manipulate.cc Outdated Show resolved Hide resolved
tests/python/relax/test_op_manipulate.py Show resolved Hide resolved
src/relax/op/tensor/manipulate.cc Outdated Show resolved Hide resolved
src/relax/op/tensor/manipulate.cc Outdated Show resolved Hide resolved
src/relax/op/tensor/manipulate.cc Outdated Show resolved Hide resolved
@MasterJH5574
Copy link
Member

I noted some style issue for Python function signatures in this PR. Please format them properly.

@SiriusNEO SiriusNEO changed the title [Op] collapse_sum_like, collapse_sum_to [Op][Manip] collapse_sum_like, collapse_sum_to Jan 7, 2023
tests/python/relax/test_op_manipulate.py Outdated Show resolved Hide resolved
tests/python/relax/test_op_manipulate.py Outdated Show resolved Hide resolved
src/relax/op/tensor/manipulate.cc Outdated Show resolved Hide resolved
src/relax/op/tensor/manipulate.cc Outdated Show resolved Hide resolved
tests/python/relax/test_tvmscript_parser_manipulate_ops.py Outdated Show resolved Hide resolved
@MasterJH5574
Copy link
Member

For another thing, don’t forget to check CI and fix the issues if there’s any. https://ci.mlc.ai/blue/organizations/jenkins/mlc-ai-relax/detail/PR-87/9/pipeline

@MasterJH5574 MasterJH5574 merged commit 8286580 into mlc-ai:structinfo Jan 8, 2023
MasterJH5574 pushed a commit that referenced this pull request Jan 9, 2023
* collapse_sum_like & collapse_sum_to

* address comments

* test coverage

* fix some tests

* collapse_sum_to tgt shape var test

* format

* format

* reformat

* reformat

* type: ignore

* handle shape var cases and add regression tests
MasterJH5574 pushed a commit that referenced this pull request Jan 12, 2023
* collapse_sum_like & collapse_sum_to

* address comments

* test coverage

* fix some tests

* collapse_sum_to tgt shape var test

* format

* format

* reformat

* reformat

* type: ignore

* handle shape var cases and add regression tests
MasterJH5574 pushed a commit that referenced this pull request Jan 16, 2023
* collapse_sum_like & collapse_sum_to

* address comments

* test coverage

* fix some tests

* collapse_sum_to tgt shape var test

* format

* format

* reformat

* reformat

* type: ignore

* handle shape var cases and add regression tests
MasterJH5574 pushed a commit that referenced this pull request Jan 28, 2023
* collapse_sum_like & collapse_sum_to

* address comments

* test coverage

* fix some tests

* collapse_sum_to tgt shape var test

* format

* format

* reformat

* reformat

* type: ignore

* handle shape var cases and add regression tests
MasterJH5574 pushed a commit that referenced this pull request Jan 31, 2023
* collapse_sum_like & collapse_sum_to

* address comments

* test coverage

* fix some tests

* collapse_sum_to tgt shape var test

* format

* format

* reformat

* reformat

* type: ignore

* handle shape var cases and add regression tests
MasterJH5574 pushed a commit that referenced this pull request Feb 8, 2023
* collapse_sum_like & collapse_sum_to

* address comments

* test coverage

* fix some tests

* collapse_sum_to tgt shape var test

* format

* format

* reformat

* reformat

* type: ignore

* handle shape var cases and add regression tests
MasterJH5574 pushed a commit that referenced this pull request Feb 12, 2023
* collapse_sum_like & collapse_sum_to

* address comments

* test coverage

* fix some tests

* collapse_sum_to tgt shape var test

* format

* format

* reformat

* reformat

* type: ignore

* handle shape var cases and add regression tests
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.

4 participants