Skip to content

Conversation

@vkuzo
Copy link
Contributor

@vkuzo vkuzo commented Jul 24, 2020

Stack from ghstack:

Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: D22801605

Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
@vkuzo vkuzo requested a review from apaszke as a code owner July 24, 2020 22:28
vkuzo added a commit that referenced this pull request Jul 24, 2020
Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 09de2e1
Pull Request resolved: #42041
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Jul 24, 2020

for (Node* n : b->nodes()) {

// TODO before land: also check for n->inputs()[0]->node()->kind() == {ConvNd}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

would love some tips on best way to do this

Copy link
Contributor

Choose a reason for hiding this comment

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

@dr-ci
Copy link

dr-ci bot commented Jul 25, 2020

💊 CI failures summary and remediations

As of commit 145f9fb (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)

ci.pytorch.org: 1 failed


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 42 times.

Copy link
Contributor

@kimishpatel kimishpatel left a comment

Choose a reason for hiding this comment

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

Looks pretty good. Left one comment.


# generic case

m = Parent()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can you put these two test cases in a loop?

Copy link
Contributor

Choose a reason for hiding this comment

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

and conv module attribute is removed

Comment on lines 46 to 55
std::vector<Node*> getAttrNodes;
Node* curNode = getConvPackedParamsNode->inputs()[0]->node();
while (!(curNode->outputs()[0]->type() == graph->inputs()[0]->type())) {
TORCH_CHECK(
curNode->kind() == prim::GetAttr,
"Attempted to add a non-prim::GetAttr node to a chain of prim::getAttr nodes.");
getAttrNodes.insert(getAttrNodes.begin(), curNode);
curNode = curNode->inputs()[0]->node();
}
TORCH_CHECK(getAttrNodes.size() > 0, "Did not find a chain of prim::getAttr nodes");
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

std::string newName = prefix + "." + suffix + "_packed_params";

// make sure the attribute does not already exist
TORCH_CHECK(
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would imagine if we hit a duplicate it would be more likely that this code has a bug, compared to the user having something named _jit_pass_hoist_conv_packed_params.{foo}.{bar}.{conv_foobar} before this pass.

Copy link
Contributor

Choose a reason for hiding this comment

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

if . can appear in attribute names then we might hit duplicate in extreme cases, although it is very unlikely
e.g. consider {foo}.{bar} is also an attribute itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, thx, will update

// traverse the chain to get packed params value
std::string curName = getAttrNodes[0]->s(attr::name);
Module curConvModule = rootModule.attr(curName).toModule();
for (int idx = 1; idx < getAttrNodes.size(); idx++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

lint

Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Jul 28, 2020
Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 444a54a
Pull Request resolved: #42041
Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
@vkuzo vkuzo requested a review from kimishpatel July 28, 2020 20:48
Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Jul 28, 2020
Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: c83039b
Pull Request resolved: #42041
Copy link
Contributor

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

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

LGTM, please fix the failing tests.

Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Jul 30, 2020
Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 4efe840
Pull Request resolved: #42041
@vkuzo
Copy link
Contributor Author

vkuzo commented Aug 3, 2020

we should wait for #42462 to be resolved before landing this

Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Aug 6, 2020
Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: e2aad66
Pull Request resolved: #42041
// %n =
// prim::GetAttr[name="{prefix}.name1{...}.name(n-1)._packed_params"][%self]
//
void hoistConvPackedParams(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also add a pass for linear? Is there value in doing this for linear modules too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see why not, although I'd defer to the mobile team on the priority.

model_optim = optimize_for_mobile(model)
self.assertFalse(hasattr(model_optim.conv1, "bias"))
self.assertFalse(hasattr(model_optim.child.conv2, "bias"))

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the understanding that one cannot serialize/deserialize a model after optimize_for_mobile is called?

…t module"

Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Aug 6, 2020
Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: fd8104b
Pull Request resolved: #42041
…ms to root module"

Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Aug 6, 2020
Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 7e3ba82
Pull Request resolved: #42041
Copy link
Contributor

@kimishpatel kimishpatel left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks.

Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Aug 7, 2020
Summary:

Adds a pass to hoist conv packed params to root module.
The benefit is that if there is nothing else in the conv module,
subsequent passes will delete it, which will reduce module size.

For context, freezing does not handle this because conv packed
params is a custom object.

Test Plan:

```
PYTORCH_JIT_LOG_LEVEL=">hoist_conv_packed_params.cpp" python test/test_mobile_optimizer.py TestOptimizer.test_hoist_conv_packed_params
```

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: b2ce0fc
Pull Request resolved: #42041
@vkuzo
Copy link
Contributor Author

vkuzo commented Aug 7, 2020

resubmitted as #42740 due to a ghstack snafu

@vkuzo vkuzo closed this Aug 7, 2020
@facebook-github-bot facebook-github-bot deleted the gh/vkuzo/108/head branch September 7, 2020 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants