Skip to content

Merge torchdim into functorch build#82454

Closed
zdevito wants to merge 14 commits intogh/zdevito/185/basefrom
gh/zdevito/185/head
Closed

Merge torchdim into functorch build#82454
zdevito wants to merge 14 commits intogh/zdevito/185/basefrom
gh/zdevito/185/head

Conversation

@zdevito
Copy link
Copy Markdown
Contributor

@zdevito zdevito commented Jul 29, 2022

Stack from ghstack (oldest at bottom):

This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

[ghstack-poisoned]
@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Jul 29, 2022

🔗 Helpful links

✅ No Failures (0 Pending)

As of commit 5fa0348 (more details on the Dr. CI page):

Expand to see more

💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

zdevito added a commit that referenced this pull request Jul 29, 2022
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

ghstack-source-id: 88db6ec
Pull Request resolved: #82454
@zdevito zdevito requested a review from ezyang July 29, 2022 05:49
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

[ghstack-poisoned]
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

[ghstack-poisoned]
zdevito added a commit that referenced this pull request Jul 29, 2022
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

ghstack-source-id: b49f2b7
Pull Request resolved: #82454
@ezyang ezyang requested a review from zou3519 July 30, 2022 03:27
from .tree_map import tree_flatten, tree_map
from .wrap_type import wrap_type
from functorch._C import dim as _C
_C._patch_tensor_class()
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.

To check my understanding: the monkey patching for torchdim happens on import functorch.dim or from functorch.dim import ... and does not happen if someone just calls import functorch, right?

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.

Correct, I was careful that no patching happens unless the dim package is imported. A follow up is to either write a more in-depth __torch_function__ for getitem/setitem, or to simply merge dim handling into getitem/setitem code.

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.

(y) thanks for confirming

@zou3519
Copy link
Copy Markdown
Contributor

zou3519 commented Aug 1, 2022

Test failures are legit

print(name, elapsed / r)
return elapsed / r

class TestMin(TestCase):
Copy link
Copy Markdown
Contributor

@zou3519 zou3519 Aug 1, 2022

Choose a reason for hiding this comment

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

For a test to be runnable via the pytorch testing infrastructure (i.e. run_test.py), it needs to extend from torch.testing._internal.common_utils.TestCase. That might just be a drop-in replacement for unittest.TestCase here. This is what the cause of the test failures are

This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

[ghstack-poisoned]
zdevito added a commit that referenced this pull request Aug 1, 2022
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

ghstack-source-id: 7d08c57
Pull Request resolved: #82454
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

[ghstack-poisoned]
zdevito added a commit that referenced this pull request Aug 1, 2022
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

ghstack-source-id: 0cf9bad
Pull Request resolved: #82454
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

[ghstack-poisoned]
zdevito added a commit that referenced this pull request Aug 2, 2022
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

ghstack-source-id: 1a3daf1
Pull Request resolved: #82454
@zdevito
Copy link
Copy Markdown
Contributor Author

zdevito commented Aug 2, 2022

@pytorchbot merge

@zou3519
Copy link
Copy Markdown
Contributor

zou3519 commented Aug 2, 2022

@pytorchbot merge

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a merge and created land time checks. See merge status here and land check progress here

pytorchmergebot pushed a commit that referenced this pull request Aug 2, 2022
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.
Pull Request resolved: #82454
Approved by: https://github.com/ezyang, https://github.com/zou3519
@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented Aug 2, 2022

@pytorchbot rebase

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a rebase job. Check the current status here

This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

[ghstack-poisoned]
@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Successfully rebased gh/zdevito/185/orig onto refs/remotes/origin/master, please pull locally before adding more changes (for example, via ghstack checkout https://github.com/pytorch/pytorch/pull/82454)

@zdevito
Copy link
Copy Markdown
Contributor Author

zdevito commented Aug 4, 2022

@pytorchbot rebase

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a rebase job. Check the current status here

This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

[ghstack-poisoned]
@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Successfully rebased gh/zdevito/185/orig onto refs/remotes/origin/master, please pull locally before adding more changes (for example, via ghstack checkout https://github.com/pytorch/pytorch/pull/82454)

This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

[ghstack-poisoned]
@zdevito
Copy link
Copy Markdown
Contributor Author

zdevito commented Aug 5, 2022

@pytorchbot rebase

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a rebase job. Check the current status here

This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

[ghstack-poisoned]
@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Successfully rebased gh/zdevito/185/orig onto refs/remotes/origin/master, please pull locally before adding more changes (for example, via ghstack checkout https://github.com/pytorch/pytorch/pull/82454)

This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

[ghstack-poisoned]
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

[ghstack-poisoned]
zdevito added a commit that referenced this pull request Aug 5, 2022
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

ghstack-source-id: f5cd294
Pull Request resolved: #82454
@zdevito
Copy link
Copy Markdown
Contributor Author

zdevito commented Aug 8, 2022

@pytorchbot merge

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a merge job. Check the current status here

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 8, 2022

Hey @zdevito.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

facebook-github-bot pushed a commit to pytorch/functorch that referenced this pull request Aug 9, 2022
Summary:
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

X-link: pytorch/pytorch#82454
Approved by: https://github.com/ezyang, https://github.com/zou3519

Reviewed By: seemethere

Differential Revision: D38542272

Pulled By: zdevito

fbshipit-source-id: 549eedf7aa0d3461774a1755235501d94bb5cc4b
facebook-github-bot pushed a commit that referenced this pull request Aug 9, 2022
Summary:
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.

Pull Request resolved: #82454
Approved by: https://github.com/ezyang, https://github.com/zou3519

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/d7cebab7d8ff4e5c5af271dc71b5181d368ad3f9

Reviewed By: seemethere

Differential Revision: D38542272

Pulled By: zdevito

fbshipit-source-id: 549eedf7aa0d3461774a1755235501d94bb5cc4b
facebook-github-bot pushed a commit that referenced this pull request Aug 10, 2022
Test Plan: revert-hammer

Differential Revision:
D38542272

Original commit changeset: 549eedf7aa0d

Original Phabricator Diff: D38542272

fbshipit-source-id: 82cd1e373c2adb80445fd5da1ccc35f8fdfa96b7
facebook-github-bot pushed a commit that referenced this pull request Aug 10, 2022
…)"

Summary:
Original commit changeset: 82cd1e373c2a

Original Phabricator Diff: D38542272

bypass-github-export-checks

This diff didn't actually get reverted in Github so we can bypass the github export checks

Test Plan: sandcastle

Reviewed By: malfet, bigfootjon

Differential Revision: D38583607

fbshipit-source-id: a674e0471e308d0bc90a0425f0ce8f09d764de5c
@facebook-github-bot facebook-github-bot deleted the gh/zdevito/185/head branch August 12, 2022 14:19
Comment on lines +200 to +205
const at::Tensor& operator*() const {
return *(at::Tensor*)this;
}
at::Tensor* operator->() const {
return (at::Tensor*)this;
}
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.

these casts have undefined behavior, and because of TBAA I wouldn't be surprised at all if you were actually bitten by this in practice.

see the aliasing rules at https://en.cppreference.com/w/cpp/language/reinterpret_cast and note that C-style casts are interpreted as whichever fancy_cast matches, which will be reinterpret_cast in this case https://en.cppreference.com/w/cpp/language/explicit_cast

laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 25, 2026
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.
Pull Request resolved: pytorch#82454
Approved by: https://github.com/ezyang, https://github.com/zou3519
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 25, 2026
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 25, 2026
This moves first-class dimensions, as prototyped in https://github.com/facebookresearch/torchdim
into the functorch build. This makes them availiable for use in PrimTorch more easily.
Pull Request resolved: pytorch#82454
Approved by: https://github.com/ezyang, https://github.com/zou3519
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request cla signed Merged Reverted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants