Skip to content

Fake Tensor Part 1#77969

Closed
eellison wants to merge 13 commits intogh/eellison/292/basefrom
gh/eellison/292/head
Closed

Fake Tensor Part 1#77969
eellison wants to merge 13 commits intogh/eellison/292/basefrom
gh/eellison/292/head

Conversation

@eellison
Copy link
Contributor

@eellison eellison commented May 20, 2022

Stack from ghstack (oldest at bottom):

This is just copying over the PR from albanD/subclass_zoo#32, and pulling in BaseTensor, plus adding one test based on invariants about schemas.

From code comments

Meta tensors give you the ability to run PyTorch code without having to
actually do computation through tensors allocated on a meta device.
Because the device is meta, meta tensors do not model device propagation.
FakeTensor extends MetaTensors to also carry an additional fake_device
which tracks devices that would have been used.

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

facebook-github-bot commented May 20, 2022

🔗 Helpful links

✅ No Failures (0 Pending)

As of commit c8e78db (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.

This is just copying over the PR from albanD/subclass_zoo#32, and pulling in `BaseTensor`, plus adding one test based on invariants about schemas. 

From code comments
>  Meta tensors give you the ability to run PyTorch code without having to
 actually do computation through tensors allocated on a `meta` device.
 Because the device is `meta`, meta tensors do not model device propagation.
 FakeTensor extends MetaTensors to also carry an additional `fake_device`
 which tracks devices that would have been used.



[ghstack-poisoned]
@eellison eellison requested review from Chillee, ezyang and zou3519 and removed request for Chillee and zou3519 May 20, 2022 16:17
Elias Ellison added 3 commits May 20, 2022 11:23
This is just copying over the PR from albanD/subclass_zoo#32, and pulling in `BaseTensor`, plus adding one test based on invariants about schemas. 

From code comments
>  Meta tensors give you the ability to run PyTorch code without having to
 actually do computation through tensors allocated on a `meta` device.
 Because the device is `meta`, meta tensors do not model device propagation.
 FakeTensor extends MetaTensors to also carry an additional `fake_device`
 which tracks devices that would have been used.



[ghstack-poisoned]
This is just copying over the PR from albanD/subclass_zoo#32, and pulling in `BaseTensor`, plus adding one test based on invariants about schemas. 

From code comments
>  Meta tensors give you the ability to run PyTorch code without having to
 actually do computation through tensors allocated on a `meta` device.
 Because the device is `meta`, meta tensors do not model device propagation.
 FakeTensor extends MetaTensors to also carry an additional `fake_device`
 which tracks devices that would have been used.



[ghstack-poisoned]
This is just copying over the PR from albanD/subclass_zoo#32, and pulling in `BaseTensor`, plus adding one test based on invariants about schemas. 

From code comments
>  Meta tensors give you the ability to run PyTorch code without having to
 actually do computation through tensors allocated on a `meta` device.
 Because the device is `meta`, meta tensors do not model device propagation.
 FakeTensor extends MetaTensors to also carry an additional `fake_device`
 which tracks devices that would have been used.



[ghstack-poisoned]
@@ -0,0 +1,80 @@
# Owner(s): ["module: unknown"]
Copy link
Contributor

Choose a reason for hiding this comment

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

well, could always chuck it in module: meta tensors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test_meta is under module: primTorch.. I dont think there is a meta module

Copy link
Contributor

Choose a reason for hiding this comment

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

there is haha module: meta tensors

# To ensure constructors can cooperate with one another, must accept and
# ignore element tensor (TODO: is this right???)
def __init__(self, elem):
super().__init__()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty confident we can dump this constructor, it never actually got used for anything

# typically must be disabled
__torch_function__ = torch._C._disabled_torch_function_impl

__all__ = ["BaseTensor"]
Copy link
Contributor

Choose a reason for hiding this comment

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

My preference is to not add this class, and inline the only thing you need (in this case, __torch_function__ = torch._C._disabled_torch_function_impl)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding from talking to various folks was the

    @staticmethod
    def __new__(cls, elem, *, requires_grad=None):
        if requires_grad is None:
            return super().__new__(cls, elem)  # type: ignore
        else:
            return cls._make_subclass(cls, elem, requires_grad)

part was necessary.. I think I'll file issue for removal of this in future PR and leave for now

Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, that's surprising.

aten.is_pinned.default,
aten.to.device,
aten.to.prim_Device,
aten._pin_memory.default,
Copy link
Contributor

Choose a reason for hiding this comment

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

@anjali411 Would this be a good operator tag? (Or maybe we should be able to figure this out from schema?)

Copy link
Contributor

Choose a reason for hiding this comment

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

We can already infer this information from the FunctionSchema by iterating through the inputs

>>> torch.ops.aten.to.device._schema.arguments
[const Tensor& self, Device device, int dtype, bool non_blocking, bool copy, int? memory_format]
>>> torch.ops.aten.to.device._schema.arguments[1]
Device device
>>> torch.ops.aten.to.device._schema.arguments[1].kwarg_only
False

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeaaa I have a test for that. Maybe I just should just get rid of the list and move over the checking logic

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah we should have one source of truth

# elem does not need to be recorded, because FakeTensor *is a* elem
assert elem.device.type == "meta"
device = device if isinstance(device, torch.device) else torch.device(device)
assert device.type != "meta"
Copy link
Contributor

Choose a reason for hiding this comment

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

You know... it might be ok for the inner device to be meta lol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems like something has gone wrong (lost what the actual device is)... maybe if it proves to be needed in the future we can change

Elias Ellison added 2 commits May 23, 2022 13:28
This is just copying over the PR from albanD/subclass_zoo#32, and pulling in `BaseTensor`, plus adding one test based on invariants about schemas. 

From code comments
>  Meta tensors give you the ability to run PyTorch code without having to
 actually do computation through tensors allocated on a `meta` device.
 Because the device is `meta`, meta tensors do not model device propagation.
 FakeTensor extends MetaTensors to also carry an additional `fake_device`
 which tracks devices that would have been used.



[ghstack-poisoned]
This is just copying over the PR from albanD/subclass_zoo#32, and pulling in `BaseTensor`, plus adding one test based on invariants about schemas. 

From code comments
>  Meta tensors give you the ability to run PyTorch code without having to
 actually do computation through tensors allocated on a `meta` device.
 Because the device is `meta`, meta tensors do not model device propagation.
 FakeTensor extends MetaTensors to also carry an additional `fake_device`
 which tracks devices that would have been used.



[ghstack-poisoned]
@eellison
Copy link
Contributor Author

@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

This is just copying over the PR from albanD/subclass_zoo#32, and pulling in `BaseTensor`, plus adding one test based on invariants about schemas. 

From code comments
>  Meta tensors give you the ability to run PyTorch code without having to
 actually do computation through tensors allocated on a `meta` device.
 Because the device is `meta`, meta tensors do not model device propagation.
 FakeTensor extends MetaTensors to also carry an additional `fake_device`
 which tracks devices that would have been used.

Differential Revision: [D36618467](https://our.internmc.facebook.com/intern/diff/D36618467)

[ghstack-poisoned]
@eellison
Copy link
Contributor Author

@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Elias Ellison added 3 commits May 24, 2022 15:59
This is just copying over the PR from albanD/subclass_zoo#32, and pulling in `BaseTensor`, plus adding one test based on invariants about schemas. 

From code comments
>  Meta tensors give you the ability to run PyTorch code without having to
 actually do computation through tensors allocated on a `meta` device.
 Because the device is `meta`, meta tensors do not model device propagation.
 FakeTensor extends MetaTensors to also carry an additional `fake_device`
 which tracks devices that would have been used.

Differential Revision: [D36618467](https://our.internmc.facebook.com/intern/diff/D36618467)

[ghstack-poisoned]
This is just copying over the PR from albanD/subclass_zoo#32, and pulling in `BaseTensor`, plus adding one test based on invariants about schemas. 

From code comments
>  Meta tensors give you the ability to run PyTorch code without having to
 actually do computation through tensors allocated on a `meta` device.
 Because the device is `meta`, meta tensors do not model device propagation.
 FakeTensor extends MetaTensors to also carry an additional `fake_device`
 which tracks devices that would have been used.

Differential Revision: [D36618467](https://our.internmc.facebook.com/intern/diff/D36618467)

[ghstack-poisoned]
This is just copying over the PR from albanD/subclass_zoo#32, and pulling in `BaseTensor`, plus adding one test based on invariants about schemas. 

From code comments
>  Meta tensors give you the ability to run PyTorch code without having to
 actually do computation through tensors allocated on a `meta` device.
 Because the device is `meta`, meta tensors do not model device propagation.
 FakeTensor extends MetaTensors to also carry an additional `fake_device`
 which tracks devices that would have been used.

Differential Revision: [D36618467](https://our.internmc.facebook.com/intern/diff/D36618467)

[ghstack-poisoned]
This is just copying over the PR from albanD/subclass_zoo#32, and pulling in `BaseTensor`, plus adding one test based on invariants about schemas. 

From code comments
>  Meta tensors give you the ability to run PyTorch code without having to
 actually do computation through tensors allocated on a `meta` device.
 Because the device is `meta`, meta tensors do not model device propagation.
 FakeTensor extends MetaTensors to also carry an additional `fake_device`
 which tracks devices that would have been used.

Differential Revision: [D36618467](https://our.internmc.facebook.com/intern/diff/D36618467)

[ghstack-poisoned]
This is just copying over the PR from albanD/subclass_zoo#32, and pulling in `BaseTensor`, plus adding one test based on invariants about schemas. 

From code comments
>  Meta tensors give you the ability to run PyTorch code without having to
 actually do computation through tensors allocated on a `meta` device.
 Because the device is `meta`, meta tensors do not model device propagation.
 FakeTensor extends MetaTensors to also carry an additional `fake_device`
 which tracks devices that would have been used.



[ghstack-poisoned]
@eellison eellison mentioned this pull request May 31, 2022
@eellison
Copy link
Contributor Author

@pytorchbot merge this please

@github-actions
Copy link
Contributor

Hey @eellison.
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 that referenced this pull request Jun 1, 2022
Summary:
Pull Request resolved: #77969

Approved by: https://github.com/ezyang

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

Reviewed By: seemethere

Differential Revision: D36784747

Pulled By: seemethere

fbshipit-source-id: 85a75483d4a0bf7247368cd1bca0576a31173c62
@facebook-github-bot facebook-github-bot deleted the gh/eellison/292/head branch June 4, 2022 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed Merged module: fx oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants