Glow: [GraphOptimizer] graph optimizer doesn't optimize away non-inverses consecutive Tranposes

Created on 13 Nov 2018  路  9Comments  路  Source: pytorch/glow

Two tranposes next to each other in the graph could be collapsed into a single tranpose but this isn't done by the GraphOptimizer. I haven't seen this in any network and maybe it's not a situation that is likely to arise from any real network.

good first issue

Most helpful comment

@jackm321 Can I work on this?

All 9 comments

I doubt someone would intentionally write a network like this, but could this sequence appear as a by-product of existing optimisations?

@SplitInfinity one of the things that GraphOptimizer does is try to sink transposes below other nodes so that those transposes are more likely end up next to each other in the graph so that they can be eliminated. So two transposes that may not have initially been next to one another often end up next to each other after some graph optimization passes.

@jackm321 Can I work on this?

We'd love contributions @Squadrick

@rdzhabarov I've read the CONTRIBUTING.md, and about the template for PRs. Anything else I need to know before I start off?

Also, could one of you give me an elaborate explanation of the optimization? In docs/Optimizations.md it's mentioned:

Elimination of transpose operations reversing each other

How is what's mentioned here any different?

How is what's mentioned here any different?

@Squadrick Right now we eliminate two consecutive transposes when they are the inverse of each other -- that is, we eliminate both of them, because when combined they are a noop. Here's the check for this:

https://github.com/pytorch/glow/blob/8b08395796eb4ae564f20a9ca840cbf0701f00e7/lib/Optimizer/GraphOptimizer.cpp#L120-L124

The new optimization would be to merge two consecutive transposes that aren't the inverse of each other into a single transpose. E.g.:

y = transpose(x, {1, 0 ,2}) // x is 3 dimensional; this swaps the first two dimensions
z = transpose(y, {0, 2, 1}) // this swaps the last two dimensions

This could be done with a single transpose:

z = transpose(x, {1, 2, 0})

I've read the CONTRIBUTING.md, and about the template for PRs. Anything else I need to know before I start off?

Yup, that's good. Also look https://github.com/pytorch/glow/blob/master/docs/CodingStandards.md.

Got it, I'll make a PR in a couple of hours, just started working on it.

Sorry about the delay. Submitted the PR.

Was this page helpful?
0 / 5 - 0 ratings