I think one valid approach would be to add custom C++ ops as described in this tutorial 3. If I’m not mistaken, torchvison also uses this approach and you can take a look at their usage in these files 4.