Skip to content

Add Op (instance_norm) | feat(torchlib)#1284

Merged
BowenBao merged 2 commits intomainfrom
gh/BowenBao/16/head
Feb 29, 2024
Merged

Add Op (instance_norm) | feat(torchlib)#1284
BowenBao merged 2 commits intomainfrom
gh/BowenBao/16/head

Conversation

@BowenBao
Copy link
Copy Markdown
Contributor

@BowenBao BowenBao commented Feb 29, 2024

Stack from ghstack (oldest at bottom):

- Fixes #1280, #1262. Avoid exporting as onnx::BatchNormalization with training=True.
- Fixes mismatch in unittest.

[ghstack-poisoned]
BowenBao added a commit that referenced this pull request Feb 29, 2024
- Fixes #1280, #1262. Avoid exporting as onnx::BatchNormalization with training=True.
- Fixes mismatch in unittest.

ghstack-source-id: ad17e9e
Pull Request resolved: #1284
@BowenBao BowenBao added the module: torchlib Related to the torch/aten function lib in development label Feb 29, 2024
BowenBao added a commit to pytorch/pytorch that referenced this pull request Feb 29, 2024
Otherwise, instance_norm is decomposed into batch_norm with training set to True.
Downstream exporter has no way to figure out that training is actually not needed.
On the other hand, ONNX does have InstanceNormalization operator defined, however
due to decomp, it unnecessarily exports as batch norm and glue code.

Depends on microsoft/onnxscript#1284

[ghstack-poisoned]
BowenBao added a commit to pytorch/pytorch that referenced this pull request Feb 29, 2024
…or export"

Otherwise, instance_norm is decomposed into batch_norm with training set to True.
Downstream exporter has no way to figure out that training is actually not needed.
On the other hand, ONNX does have InstanceNormalization operator defined, however
due to decomp, it unnecessarily exports as batch norm and glue code.

Depends on microsoft/onnxscript#1284

[ghstack-poisoned]
BowenBao added a commit to pytorch/pytorch that referenced this pull request Feb 29, 2024
Otherwise, instance_norm is decomposed into batch_norm with training set to True.
Downstream exporter has no way to figure out that training is actually not needed.
On the other hand, ONNX does have InstanceNormalization operator defined, however
due to decomp, it unnecessarily exports as batch norm and glue code.

Depends on microsoft/onnxscript#1284

ghstack-source-id: 11cdbae
Pull Request resolved: #120866
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 29, 2024

Test Results

     24 files  ±     0      24 suites  ±0   1h 35m 3s ⏱️ - 9m 18s
 11 404 tests +     5   8 439 ✅ +    7    2 952 💤 ±     0   13 ❌  - 2 
257 938 runs   - 16 733  58 851 ✅  - 4 157  198 882 💤  - 12 574  205 ❌  - 2 

For more details on these failures, see this check.

Results for commit c4e1912. ± Comparison against base commit 457e52e.

♻️ This comment has been updated with latest results.

@BowenBao BowenBao requested a review from titaiwangms February 29, 2024 01:16
Copy link
Copy Markdown
Contributor

@titaiwangms titaiwangms left a comment

Choose a reason for hiding this comment

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

LG w/ non-blockings

Comment thread onnxscript/tests/function_libs/torch_lib/ops_test_common.py
Comment thread onnxscript/function_libs/torch_lib/ops/core.py
- Fixes #1280, #1262. Avoid exporting as onnx::BatchNormalization with training=True.
- Fixes mismatch in unittest.

[ghstack-poisoned]
BowenBao added a commit that referenced this pull request Feb 29, 2024
- Fixes #1280, #1262. Avoid exporting as onnx::BatchNormalization with training=True.
- Fixes mismatch in unittest.

ghstack-source-id: db69c95
Pull Request resolved: #1284
BowenBao added a commit to pytorch/pytorch that referenced this pull request Feb 29, 2024
…p instance_norm decomp for export"

Otherwise, instance_norm is decomposed into batch_norm with training set to True.
Downstream exporter has no way to figure out that training is actually not needed.
On the other hand, ONNX does have InstanceNormalization operator defined, however
due to decomp, it unnecessarily exports as batch norm and glue code.

Depends on microsoft/onnxscript#1284

[ghstack-poisoned]
BowenBao added a commit to pytorch/pytorch that referenced this pull request Feb 29, 2024
Otherwise, instance_norm is decomposed into batch_norm with training set to True.
Downstream exporter has no way to figure out that training is actually not needed.
On the other hand, ONNX does have InstanceNormalization operator defined, however
due to decomp, it unnecessarily exports as batch norm and glue code.

Depends on microsoft/onnxscript#1284

ghstack-source-id: 9f7c15d
Pull Request resolved: #120866
@BowenBao BowenBao changed the base branch from gh/BowenBao/16/base to main February 29, 2024 20:01
@BowenBao BowenBao merged commit bbb9584 into main Feb 29, 2024
@BowenBao BowenBao deleted the gh/BowenBao/16/head branch February 29, 2024 20:01
BowenBao added a commit to pytorch/pytorch that referenced this pull request Feb 29, 2024
…tance_norm decomp for export"

Otherwise, instance_norm is decomposed into batch_norm with training set to True.
Downstream exporter has no way to figure out that training is actually not needed.
On the other hand, ONNX does have InstanceNormalization operator defined, however
due to decomp, it unnecessarily exports as batch norm and glue code.

Depends on microsoft/onnxscript#1284

[ghstack-poisoned]
BowenBao added a commit to pytorch/pytorch that referenced this pull request Feb 29, 2024
Otherwise, instance_norm is decomposed into batch_norm with training set to True.
Downstream exporter has no way to figure out that training is actually not needed.
On the other hand, ONNX does have InstanceNormalization operator defined, however
due to decomp, it unnecessarily exports as batch norm and glue code.

Depends on microsoft/onnxscript#1284

ghstack-source-id: 91812c4
Pull Request resolved: #120866
BowenBao added a commit to pytorch/pytorch that referenced this pull request Mar 1, 2024
Otherwise, instance_norm is decomposed into batch_norm with training set to True.
Downstream exporter has no way to figure out that training is actually not needed.
On the other hand, ONNX does have InstanceNormalization operator defined, however
due to decomp, it unnecessarily exports as batch norm and glue code.

Depends on microsoft/onnxscript#1284

ghstack-source-id: f60eead
Pull Request resolved: #120866
BowenBao added a commit to pytorch/pytorch that referenced this pull request Mar 1, 2024
…xport] Skip instance_norm decomp for export"

Otherwise, instance_norm is decomposed into batch_norm with training set to True.
Downstream exporter has no way to figure out that training is actually not needed.
On the other hand, ONNX does have InstanceNormalization operator defined, however
due to decomp, it unnecessarily exports as batch norm and glue code.

Depends on microsoft/onnxscript#1284

[ghstack-poisoned]
BowenBao added a commit to pytorch/pytorch that referenced this pull request Mar 1, 2024
…ance_norm decomp for export"

Otherwise, instance_norm is decomposed into batch_norm with training set to True.
Downstream exporter has no way to figure out that training is actually not needed.
On the other hand, ONNX does have InstanceNormalization operator defined, however
due to decomp, it unnecessarily exports as batch norm and glue code.

Depends on microsoft/onnxscript#1284

[ghstack-poisoned]
pytorchmergebot pushed a commit to pytorch/pytorch that referenced this pull request Mar 1, 2024
Otherwise, instance_norm is decomposed into batch_norm with training set to True.
Downstream exporter has no way to figure out that training is actually not needed.
On the other hand, ONNX does have InstanceNormalization operator defined, however
due to decomp, it unnecessarily exports as batch norm and glue code.

Depends on microsoft/onnxscript#1284
Pull Request resolved: #120866
Approved by: https://github.com/thiagocrepaldi, https://github.com/titaiwangms

batch_size = op.Shape(input, start=0, end=1)
bn_input = op.Reshape(input, op.Concat([1, -1], op.Shape(input, start=2), axis=0))
weight = op.Tile(weight, batch_size)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Curious: When should we use Tile vs Expand? Is there a difference here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Expand only works when source dimension size is either 1 or equal to target dimension size.

Tile on the other hand is like repeat. Tile and Expand are only equivalent when source dimension size is 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: torchlib Related to the torch/aten function lib in development

Projects

Development

Successfully merging this pull request may close these issues.

[torchlib] aten.instance_norm

3 participants