Modify the computation graph on-the-fly?

Dear all,
How to achieve the following goal:

  1. Trace (or record) the computation graph (e.x, conv2d, element-wise add)
  2. Modify the "element-wise add " to “whatever op” I want

Please let me know if there is a way to accomplish this? Thank you very much!


We do not provide any way for the user to modify the computational graph.
This is mainly because it is merely an implementation detail of the autograd engine and can (and do) change regularly.

What is the application for which you want to be able to do such things?

Thank you for the reply. Suppose we have z = y + x and we want to do z = f(y) + f(x) (f is a customized nn.Module) everywhere in the network forward. How can we achieve that?

It depends what your original network is. But you most likely only need to modify the .forward() method on the original network and add the appropriate calls to your new module.
If you could share how the original function is defined, that would help.