Regarding custom layer

Hi,
Can anyone help me how to define addition of two vectors (adding element one by one) with user defined forward and backward propagation using custom layer.
Thanks

Hi,

This section of the doc should contain all the informations you need :slight_smile:

Actually this kind of example is confusing. Is there any simplified examples like addition of two vectors ?
Thanks

There is an example in that tutorial that presents multiplication by a constant (called MulConstant). Isn’t that close enough to adding two vectors?

I tried to run the custom c++ extension code as mentioned in the post (https://pytorch.org/tutorials/advanced/cpp_extension.html) but the time taken for python and cpp versions are entirely different for backward propagation especially.
(test1) gputest@gputest-OptiPlex-745:~/PycharmProjects/test1/extension-cpp-master$ python benchmark.py py
Forward: 524.282/560.827 us | Backward 844.955/890.770 us
(test1) gputest@gputest-OptiPlex-745:~/PycharmProjects/test1/extension-cpp-master$ python benchmark.py cpp
Forward: 473.022/497.065 us | Backward 1243.830/1299.400 us

Because he mentioned that backward propagation time should be similar for both. But here I got different values will that would be an issue?
Thanks

Hi,

A difference of less than 0.4ms for a single run is not really significant I think. This can be caused by any other program running at the same time and competing for the same ressource.