code: def knowledge_distillation_kl_div_loss(
      pred: Tensor,
      soft_label: Tensor,
      T: int,
      detach_target: bool = True,
  ) -> Tensor:
      r"""Loss function for knowledge distilling using KL divergence.
  
      Args:
          pred (Tensor): Predicted logits with shape (N, n + 1).
          soft_label (Tensor): Target logits with shape (N, N + 1).
          T (int): Temperature for distillation.
          detach_target (bool): Remove soft_label from automatic differentiation
  
      Returns:
          Tensor: Loss tensor with shape (N,).
      """
      assert pred.size() == soft_label.size()
      target = F.softmax(soft_label / T, dim=1)
      if detach_target:
          target = target.detach()
  
      kd_loss = F.kl_div(
          F.log_softmax(pred / T, dim=1), target, reduction="none"
      ).mean(1) * (T * T)
  
      return kd_loss
  
file_path: mmdetection/mmdet/models/losses/kd_loss.py
imports: from typing import Optional
  import torch.nn
  import torch.nn.functional
  from torch import Tensor
  from mmdet.registry import MODELS
  from .utils import weighted_loss
label_desc: Use image node_id 1 for calling a global function with example usage: knowledge_distillation_kl_div_loss(pred, soft_label, T, detach_target) and returns: kd_loss