code: def cost_matrix_cosine(
      x: Tensor, y: Tensor, eps: float = 1e-5
  ) -> Tensor:
      """Compute cosine distance across every pairs of x, y (batched)
      [B, L_x, D] [B, L_y, D] -> [B, Lx, Ly]"""
      assert x.dim() == y.dim()
      assert x.size(0) == y.size(0)
      assert x.size(2) == y.size(2)
      x_norm = F.normalize(x, p=2, dim=-1, eps=eps)
      y_norm = F.normalize(y, p=2, dim=-1, eps=eps)
      cosine_sim = x_norm.matmul(y_norm.transpose(1, 2))
      cosine_dist = 1 - cosine_sim
      return cosine_dist
  
imports: import torch
  from torch import Tensor
  from torch.nn import functional
label_desc: Use image node_id 1 for calling a global function with example usage: cost_matrix_cosine(x, y, eps) and returns: cosine_dist