Skip to content

Conversation

@eellison
Copy link
Contributor

@eellison eellison commented Oct 17, 2019

Stack from ghstack:

Add support for treating Sequentials, ModuleLists, and ModuleDicts as iterables.

As previously, when emitting a for loop over a Module Container we unroll the for loop over all elements. We require that any Sugared Value in an iterable with a Module Container have a statically - determinable length.

Otherwise, if you zipped over a list of varying length and an nn.Sequential that alternated between returning a Tensor and a Dictionary, the output type would change based on the length of the list.

Fix for #17179
And #27401
and #27506

@eellison eellison requested a review from apaszke as a code owner October 17, 2019 22:12
eellison pushed a commit that referenced this pull request Oct 17, 2019
ghstack-source-id: 704a3cc
Pull Request resolved: #28255
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Oct 17, 2019
@eellison eellison changed the title Add Support For Module Containers as Iterables [JIT] Add Support For Module Containers as Iterables Oct 17, 2019
@eellison eellison requested review from driazati, suo and zdevito October 17, 2019 22:15
Add support for treating Sequentials, ModuleLists, and ModuleDicts as iterables.

As previously, when emitting a for loop over a Module Container we unroll the for loop over all elements. We require that any Sugared Value in an iterable with a Module Container have a statically - determinable length.

Otherwise, if you zipped over a list of varying length and an nn.Sequential that alternated between returning a Tensor and a Dictionary, the output type would change based on the length of the list.

Fix for #17179
And #27790



[ghstack-poisoned]
Add support for treating Sequentials, ModuleLists, and ModuleDicts as iterables.

As previously, when emitting a for loop over a Module Container we unroll the for loop over all elements. We require that any Sugared Value in an iterable with a Module Container have a statically - determinable length.

Otherwise, if you zipped over a list of varying length and an nn.Sequential that alternated between returning a Tensor and a Dictionary, the output type would change based on the length of the list.

Fix for #17179
And #27790



[ghstack-poisoned]
eellison pushed a commit that referenced this pull request Oct 17, 2019
ghstack-source-id: 593302f
Pull Request resolved: #28255
Add support for treating Sequentials, ModuleLists, and ModuleDicts as iterables.

As previously, when emitting a for loop over a Module Container we unroll the for loop over all elements. We require that any Sugared Value in an iterable with a Module Container have a statically - determinable length.

Otherwise, if you zipped over a list of varying length and an nn.Sequential that alternated between returning a Tensor and a Dictionary, the output type would change based on the length of the list.

Fix for #17179
And #27401 
and #27506



[ghstack-poisoned]
Add support for treating Sequentials, ModuleLists, and ModuleDicts as iterables.

As previously, when emitting a for loop over a Module Container we unroll the for loop over all elements. We require that any Sugared Value in an iterable with a Module Container have a statically - determinable length.

Otherwise, if you zipped over a list of varying length and an nn.Sequential that alternated between returning a Tensor and a Dictionary, the output type would change based on the length of the list.

Fix for #17179
And #27401 
and #27506



[ghstack-poisoned]
eellison pushed a commit that referenced this pull request Oct 22, 2019
ghstack-source-id: ac5c8a7
Pull Request resolved: #28255
Copy link
Contributor

@zdevito zdevito left a comment

Choose a reason for hiding this comment

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

This looks pretty good. I have one substantive comment: that we should try just putting the iteration functionality into sugaredvalue, as a way of avoiding having to introduce a new concept.

Add support for treating Sequentials, ModuleLists, and ModuleDicts as iterables.

As previously, when emitting a for loop over a Module Container we unroll the for loop over all elements. We require that any Sugared Value in an iterable with a Module Container have a statically - determinable length.

Otherwise, if you zipped over a list of varying length and an nn.Sequential that alternated between returning a Tensor and a Dictionary, the output type would change based on the length of the list.

Fix for #17179
And #27401 
and #27506



[ghstack-poisoned]
@eellison eellison requested a review from zdevito October 29, 2019 21:59
Add support for treating Sequentials, ModuleLists, and ModuleDicts as iterables.

As previously, when emitting a for loop over a Module Container we unroll the for loop over all elements. We require that any Sugared Value in an iterable with a Module Container have a statically - determinable length.

Otherwise, if you zipped over a list of varying length and an nn.Sequential that alternated between returning a Tensor and a Dictionary, the output type would change based on the length of the list.

Fix for #17179
And #27401 
and #27506



[ghstack-poisoned]
eellison pushed a commit that referenced this pull request Oct 29, 2019
ghstack-source-id: 4dfca73
Pull Request resolved: #28255
Add support for treating Sequentials, ModuleLists, and ModuleDicts as iterables.

As previously, when emitting a for loop over a Module Container we unroll the for loop over all elements. We require that any Sugared Value in an iterable with a Module Container have a statically - determinable length.

Otherwise, if you zipped over a list of varying length and an nn.Sequential that alternated between returning a Tensor and a Dictionary, the output type would change based on the length of the list.

Fix for #17179
And #27401 
and #27506



[ghstack-poisoned]
eellison pushed a commit that referenced this pull request Oct 30, 2019
ghstack-source-id: 0f92de9
Pull Request resolved: #28255
Add support for treating Sequentials, ModuleLists, and ModuleDicts as iterables.

As previously, when emitting a for loop over a Module Container we unroll the for loop over all elements. We require that any Sugared Value in an iterable with a Module Container have a statically - determinable length.

Otherwise, if you zipped over a list of varying length and an nn.Sequential that alternated between returning a Tensor and a Dictionary, the output type would change based on the length of the list.

Fix for #17179
And #27401 
and #27506



[ghstack-poisoned]
eellison pushed a commit that referenced this pull request Oct 30, 2019
ghstack-source-id: e2f014f
Pull Request resolved: #28255
Copy link
Contributor

@zdevito zdevito left a comment

Choose a reason for hiding this comment

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

This looks good. The two substantive comments are: avoid using more constant prop than we were before for ranges, and lets make statically determined lengths also the same as when we unroll loops to avoid introducing an exponential number of cases to handle.

namespace torch {
namespace jit {

c10::optional<Stack> tryConstantPropNode(const Node* node) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is missing all of constant props checks that the node itself can be constant-propagated. Doesn't seem safe to use.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this method is actually use as runNodeIfInputsAreConstant which has a different implicit contract. Should document what this will do. What is Print(4) expected to do here?

Add support for treating Sequentials, ModuleLists, and ModuleDicts as iterables.

As previously, when emitting a for loop over a Module Container we unroll the for loop over all elements. We require that any Sugared Value in an iterable with a Module Container have a statically - determinable length.

Otherwise, if you zipped over a list of varying length and an nn.Sequential that alternated between returning a Tensor and a Dictionary, the output type would change based on the length of the list.

Fix for #17179
And #27401 
and #27506



[ghstack-poisoned]
Add support for treating Sequentials, ModuleLists, and ModuleDicts as iterables.

As previously, when emitting a for loop over a Module Container we unroll the for loop over all elements. We require that any Sugared Value in an iterable with a Module Container have a statically - determinable length.

Otherwise, if you zipped over a list of varying length and an nn.Sequential that alternated between returning a Tensor and a Dictionary, the output type would change based on the length of the list.

Fix for #17179
And #27401 
and #27506



[ghstack-poisoned]
eellison pushed a commit that referenced this pull request Nov 1, 2019
ghstack-source-id: af34dde
Pull Request resolved: #28255
zdevito pushed a commit to zdevito/ATen that referenced this pull request Nov 4, 2019
Summary:
Pull Request resolved: pytorch/pytorch#28255

Add support for treating Sequentials, ModuleLists, and ModuleDicts as iterables.

As previously, when emitting a for loop over a Module Container we unroll the for loop over all elements. We require that any Sugared Value in an iterable with a Module Container have a statically - determinable length.

Otherwise, if you zipped over a list of varying length and an nn.Sequential that alternated between returning a Tensor and a Dictionary, the output type would change based on the length of the list.

Fix for #17179
And pytorch/pytorch#27401
and pytorch/pytorch#27506

Test Plan: Imported from OSS

Reviewed By: ZolotukhinM

Differential Revision: D18278124

Pulled By: eellison

fbshipit-source-id: aca336a5b8da89c756b1f0884883649510cbde3c
@facebook-github-bot
Copy link
Contributor

@eellison merged this pull request in fdeef45.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@eellison merged this pull request in fdeef45.

@facebook-github-bot facebook-github-bot deleted the gh/eellison/24/head branch November 8, 2019 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged 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