glow icon indicating copy to clipboard operation
glow copied to clipboard

SGDNode deletion

Open skc7 opened this issue 6 years ago • 3 comments

Hi,

https://github.com/pytorch/glow/blob/master/lib/Optimizer/GraphOptimizer/Lower.cpp#L51

SGDNode is getting erased by default in GraphOptimizer, lower() call. Can this deletion be dependent on whether backend supports SGDNode or not?

Thanks.

skc7 avatar Apr 15 '20 16:04 skc7

Hi @skc7, good catch, yes we should not erase if the backend prevents lowering for SGDNode. The fix should be pretty simple (adding something like if (B && !B->shouldLower(&N)) to the loop here should do it). Would you like to contribute this fix?

jfix71 avatar Apr 21 '20 01:04 jfix71

Hi @jfix71, Sure, I can contribute.

Few more observations: SGDnode has .setHasSideEffects(true). What is the reason behind this? Also there is no corresponding low level IR for SGD(like SGDInst). So, if backend doesn't want to lower this node, and uses Low level IR, it fails at IRGen stage. Also, if backend has its corresponding backend specific SGD node and instruction, and want to replace original SGDnode in Transform-post-lowering call in backend, it fails because Dead code elimination pass doesn't remove the original SGD node since it has sideEffects field set to true.

skc7 avatar Apr 21 '20 12:04 skc7

SGDnode has .setHasSideEffects(true). What is the reason behind this?

When we lower SGDNode, if momentum > 0.0 then we include a Gsum Placeholder here which we save to, hence it has side effects: https://github.com/pytorch/glow/blob/86c53167b24865b649fd72d550ade2183f1f2a39/lib/Optimizer/Lower/Lower.cpp#L396-L412

Also there is no corresponding low level IR for SGD(like SGDInst).

Right -- none of our open source backends support this Node unlowered, hence we do not have an instruction for it. If you have a backend which needs an SGDInst then you could add one in open source, or add a backed-specific Instruction for it and override Backend::generateInst() to do correct IRGen.

Also, if backend has its corresponding backend specific SGD node and instruction, and want to replace original SGDnode in Transform-post-lowering call in backend, it fails because Dead code elimination pass doesn't remove the original SGD node since it has sideEffects field set to true.

Yes, in transformPostLowering() you would need to keep track of any nodes with side effects you replace, and remove them explicitly just like we do in that loop in your original post.

jfix71 avatar Apr 23 '20 08:04 jfix71