code: def create_metric(model):
      def G(z):
          return torch.inverse(
              (
                  model.M_tens.unsqueeze(0).to(z.device)
                  * torch.exp(
                      -torch.norm(
                          model.centroids_tens.unsqueeze(0).to(z.device)
                          - z.unsqueeze(1),
                          dim=-1,
                      )
                      ** 2
                      / (model.temperature**2)
                  )
                  .unsqueeze(-1)
                  .unsqueeze(-1)
              ).sum(dim=1)
              + model.lbd * torch.eye(model.latent_dim).to(z.device)
          )
  
      return G
  
label_desc: Use image node_id 1 for calling a global function with example usage: create_metric(model) and returns: G, torch