You can implement your own loss function by overriding an existing loss function class like what is done in the loss module 6, as long as you use only torch operations that are differentiable. I suspect all of the “numpy” operations needed in your custom lost function are implemented in PyTorch.