Both approaches work fine.
Actually, the nn.Module internally uses the functional interface of PyTorch nn.
I’d say that it depends on the loss and the application, but usually having functions can be quicker to write and more concise.