class_docstr: Contrastive Model, currently mainly focused on memory bank and CSC.
class_docstr_tok: ["Contrastive","Model",",","currently","mainly","focused","on","memory","bank","and","CSC","."]
code: def sinkhorn(self, Q, iters):
      with torch.no_grad():
          Q = Q.t()  # KxB
          sum_Q = torch.sum(Q)
          Q /= sum_Q
  
          r = (
              torch.ones(Q.shape[0]).cuda(non_blocking=True)
              / Q.shape[0]
          )
          c = (
              torch.ones(Q.shape[1]).cuda(non_blocking=True)
              / Q.shape[1]
          )
  
          for _ in range(iters):
              Q *= (r / torch.sum(Q, dim=1)).unsqueeze(1)
              Q *= (c / torch.sum(Q, dim=0)).unsqueeze(0)
  
          Q = Q / torch.sum(Q, dim=0, keepdim=True)
          return Q.t().float()
  
imports: import math
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import slowfast.models.losses
  import slowfast.utils.distributed
  import slowfast.utils.logging
  from slowfast.models.video_model_builder import X3D, MViT, ResNet, SlowFast
  from .build import MODEL_REGISTRY
label_desc: Use image node_id 18 for calling the ContrastiveModel obj's underlying member method code with example usage: obj.sinkhorn(Q, iters) and returns: Q