Hi,
Why don’t you define a custom autograd function involving CRF?
This way typical pytorch workflow would keep working without “hacks”.
https://pytorch.org/tutorials/beginner/examples_autograd/two_layer_net_custom_function.html 54
forgot to mention you can create c++ modules for pytorch