I feel the same , but dimension after cosine similarity is causing the error I guess.
Even program starts running but stops at the last step of epoch when
Dimension are as follows:
Representation:  torch.Size([672, 128])
Similarity Matrix torch.Size([672, 672])
Before the last step of a epoch ,dimension is as follow
Representation: torch.Size([1024, 128])
Similarity Matrix torch.Size([1024, 1024])
672 is causing problem