code: def hinge_d_loss_with_exemplar_weights(
      logits_real, logits_fake, weights
  ):
      assert (
          weights.shape[0]
          == logits_real.shape[0]
          == logits_fake.shape[0]
      )
      loss_real = torch.mean(F.relu(1.0 - logits_real), dim=[1, 2, 3])
      loss_fake = torch.mean(F.relu(1.0 + logits_fake), dim=[1, 2, 3])
      loss_real = (weights * loss_real).sum() / weights.sum()
      loss_fake = (weights * loss_fake).sum() / weights.sum()
      d_loss = 0.5 * (loss_real + loss_fake)
      return d_loss
  
file_path: compvis-stable-diffusion/ldm/modules/losses/vqperceptual.py
imports: import torch
  from torch import nn
  import torch.nn.functional
  from einops import repeat
  from taming.modules.discriminator.model import NLayerDiscriminator, weights_init
  from taming.modules.losses.lpips import LPIPS
  from taming.modules.losses.vqperceptual import hinge_d_loss, vanilla_d_loss
label_desc: Use image node_id 1 for calling a global function with example usage: hinge_d_loss_with_exemplar_weights(logits_real, logits_fake, weights) and returns: d_loss