I’m kind of embarrassed to say the answer is just to call .float() directly. As in torch.gt(cos_sim, self.margin).float(). Thanks for your help on this though!
I also realised that the paper has the sign wrong and you want greater than rather than less than for the non-match loss.