Skip to content

Conversation

@kimishpatel
Copy link
Contributor

@kimishpatel kimishpatel commented Jun 1, 2020

Stack from ghstack:

Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add

  • relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: D21822396

Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
@kimishpatel kimishpatel requested a review from apaszke as a code owner June 1, 2020 18:27
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Jun 1, 2020
@dr-ci
Copy link

dr-ci bot commented Jun 1, 2020

💊 CI failures summary and remediations

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


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


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 53 times.

Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
kimishpatel added a commit that referenced this pull request Jun 1, 2020
Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 8a90fef
Pull Request resolved: #39343
Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
kimishpatel added a commit that referenced this pull request Jun 15, 2020
Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 55d97dc
Pull Request resolved: #39343
Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Comment on lines +559 to +560
a = a * -10
a = a + 5
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

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 think this was out of habit for quantized stuff. I was trying to bias values of tensor rather than uniformly distributed between 0 and 1 to be able to catch error which are not easily canceled out. In this specific instance it may not matter.

test/test_jit.py Outdated
new_res = m(a, b)
FileCheck().check_not("aten::add(") \
.check_not("aten::relu_(") \
.check("aten::add_relu_(") \
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this add_relu_? Shouldn't it be add_relu, since the original operand was not modified? Doesn't the optimized model mutate a, whereas the original did not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so add is not inplace but relu_ is. So it made sense to replace add + relu_ with add_relu_.

test/test_jit.py Outdated
.check_not("aten::relu(") \
.check("aten::add_relu_(") \
.run(m.graph)
torch.testing.assert_allclose(orig_res, new_res)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should also test that both models properly mutate a. Above, should probably test that they both don't mutate.

Comment on lines 32 to 33
// inplace. since in the graph, it does not seem
// that output of add will be really used anywhere else.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't agree with this, since you're now mutating one of the addends, rather than the sum.

Copy link
Contributor Author

@kimishpatel kimishpatel Jun 26, 2020

Choose a reason for hiding this comment

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

Hmm. I think you are right. I need to check a graph like this:

def m(a, b, c):
   tmp = torch.add(a, b)
   x = self.relu_(tmp)
   d = torch.add(a, c)
   return x + d

If add + relu_ is replaced with add_relu_ then a is mutated and if a.add(c) is executed afterwards that is wrong. This transformation adds a new alias. In the original graph tmp = torch.add(a, b) a and tmp dont' alias but replacing that with tmp = torch.add_relu_(a, b) now I have made a and tmp alias each other.
I will test and fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dreiss I fixed this and also added exactly this test that I mentioned above. Without fixing it, the test fails, after the fix it passes.

Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
@kimishpatel kimishpatel requested a review from dreiss June 26, 2020 16:24
Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
kimishpatel added a commit that referenced this pull request Jun 26, 2020
Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: f35fc72
Pull Request resolved: #39343
Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Summary:
Building on top of previous PR that adds fused add_relu op, this PR adds
a JIT pass to transform input graph to find all fusable instancs of add
+ relu and fuses them.

Test Plan:
python test/test_jit.py TestJit.test_add_relu_fusion

Reviewers:

Subscribers:

Tasks:

Tags:

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

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

This pull request has been merged in c5dcf05.

@facebook-github-bot facebook-github-bot deleted the gh/kimishpatel/29/head branch July 13, 2020 14:19
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