[caffe2] Reimplement RemoveOpsByType with SSA (#40649)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/40649
The original implementation of RemoveOpsByType is pretty buggy and does not remove all instances of the ops that should be removed. It's also quite complicated and hard to modify. I reimplemented it by first converting the graph to its SSA form. The algorithm is quite simple once the graph is in SSA form. It's very similar to constant propagation with a few modifications. The hardest part is to deal with the case of removing an op with the output being an output of the predict net, because that output has to be preserved.
(Note: this ignores all push blocking failures!)
Reviewed By: yinghai, dzhulgakov
Differential Revision: D22220798
fbshipit-source-id: faf6ed5242f1e2f310125d964738c608c6c55c94