Solved by ptrblck in post #7 
              
              
                Thanks for the code. 
The offending call should be the inplace unsqueeze of prototypes[0]. 
Change it to this and it should work: 
dist = M_2 - self.distance_function(x_in, prototypes[0].unsqueeze(0))