Skip to content

Refactor NvFuser transpose API to match eager mode behavior#1746

Merged
rdspring1 merged 8 commits intodevelfrom
rds_transpose_api_refactor
Jun 3, 2022
Merged

Refactor NvFuser transpose API to match eager mode behavior#1746
rdspring1 merged 8 commits intodevelfrom
rds_transpose_api_refactor

Conversation

@rdspring1
Copy link
Copy Markdown
Collaborator

Currently, the NvFuser transpose takes an unordered_map that maps from old to new positions. (Similar to reorder).
This PR refactors transpose to follow the aten::permute and aten::transpose APIs.

@rdspring1 rdspring1 force-pushed the rds_transpose_api_refactor branch from 00880f8 to a4bfc72 Compare June 3, 2022 04:39
@naoyam
Copy link
Copy Markdown
Collaborator

naoyam commented Jun 3, 2022

Is transpose a special case of permute?

@rdspring1
Copy link
Copy Markdown
Collaborator Author

permute freely reorders the tensor's axes. transpose swaps the position of two axes while keeping the rest unchanged.
You can implement transpose using permute.

Comment thread torch/csrc/jit/codegen/cuda/ir_utils.h Outdated
Comment thread torch/csrc/jit/codegen/cuda/ir_utils.cpp Outdated
Comment thread torch/csrc/jit/codegen/cuda/ops/alias.cpp Outdated
Comment thread torch/csrc/jit/codegen/cuda/ops/alias.cpp Outdated
Comment thread torch/csrc/jit/codegen/cuda/ops/alias.h Outdated
Comment thread torch/csrc/jit/codegen/cuda/ops/alias.h Outdated
@rdspring1 rdspring1 force-pushed the rds_transpose_api_refactor branch from a4bfc72 to 91d54b4 Compare June 3, 2022 19:01
Copy link
Copy Markdown
Collaborator

@naoyam naoyam left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for addressing the comments.

Copy link
Copy Markdown
Collaborator

@jjsjann123 jjsjann123 left a comment

Choose a reason for hiding this comment

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

LGTM

}

// returns transpose map to achieve permutation on non-permuted tensor
// note: used for codegen transpose API
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.

Nice~~


TORCH_CHECK(
dim1 >= 0 && dim1 <= ndims, "Invalid transpose dimension 1: ", dim1);

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.

nitpick: wasn't the negative dim handling done in ir_utils::normalizeNew2Old already, this feels like redundant checks, but does give us nice error message.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Dimension canonicalization only wraps around once.
If you had a 3D tensor but specified dim0 = -4, then the check will fail.

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.

Not saying that we need to change the behavior, both pytorch & numpy only wraps once and errors out for out of range.

Dimension canonicalization and the check in transpose does exactly the same thing, so it's a redundant check.

@rdspring1 rdspring1 merged commit 8a69aa3 into devel Jun 3, 2022
@rdspring1 rdspring1 deleted the rds_transpose_api_refactor branch June 3, 2022 21:26
jjsjann123 added a commit that referenced this pull request Jun 22, 2022
Syncing nvfuser devel branch to upstream master. https://github.com/csarofeen/pytorch/

Bug fixes and minor refactor

Squashed commits to WAR github API
Commits that's actually in this PR from the devel branch:

```
4c60e7d Add examples infrastructure for using nvFuser in a standalone program (#1725)
02a05d9 Fix issue #1751 (#1753)
8a69aa3 Refactor NvFuser transpose API to match eager mode behavior (#1746)
ffdf6b7 Remove BroadcastWithoutStride. (#1738)
02bab16 Fix flipping of a boolean flag (#1745)
465d668 cleanup (#1744)
26d354e fixing noncontig broadcast (#1742)
856b6b2 Add IterDomainBuilder (#1736)
1fd974f fixing warning for gcc7 (#1732)
de2740a disabling complex in python tests for #1730 (#1733)
fbbbe0a fixing MSVC build (#1728)
b5feee5 Fix the fused reduction runtime kernel (#1729)
5247682 Re-entrant GroupedGridReduction (#1727)
```

RUN_TORCHBENCH: nvfuser
Pull Request resolved: pytorch#79147
Approved by: https://github.com/davidberard98
jjsjann123 added a commit that referenced this pull request Jun 22, 2022
…h#79406)

Landing reverted PR pytorch#79147.

Syncing nvfuser devel branch to upstream master. https://github.com/csarofeen/pytorch/

Bug fixes and minor refactor

Squashed commits to WAR github API
Commits that's actually in this PR from the devel branch:

```
4c60e7d Add examples infrastructure for using nvFuser in a standalone program (#1725)
02a05d9 Fix issue #1751 (#1753)
8a69aa3 Refactor NvFuser transpose API to match eager mode behavior (#1746)
ffdf6b7 Remove BroadcastWithoutStride. (#1738)
02bab16 Fix flipping of a boolean flag (#1745)
465d668 cleanup (#1744)
26d354e fixing noncontig broadcast (#1742)
856b6b2 Add IterDomainBuilder (#1736)
1fd974f fixing warning for gcc7 (#1732)
de2740a disabling complex in python tests for #1730 (#1733)
fbbbe0a fixing MSVC build (#1728)
b5feee5 Fix the fused reduction runtime kernel (#1729)
5247682 Re-entrant GroupedGridReduction (#1727)
```

RUN_TORCHBENCH: nvfuser
Pull Request resolved: pytorch#79406
Approved by: https://github.com/davidberard98
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