Hey alban, thank you for replying! 
I may have solved the problem, torch seems already able to process mini-batches for this kind of computation without any further effort! 
The only thing is to make sure you have in input a tensor of size [mini_batch, variable_to_optimise.shape].