code: def test_dice_loss(naive_dice):
      loss_class = DiceLoss
      pred = torch.rand((10, 4, 4))
      target = torch.rand((10, 4, 4))
      weight = torch.rand((10))
  
      # Test loss forward
      loss = loss_class(naive_dice=naive_dice)(pred, target)
      assert isinstance(loss, torch.Tensor)
  
      # Test loss forward with weight
      loss = loss_class(naive_dice=naive_dice)(pred, target, weight)
      assert isinstance(loss, torch.Tensor)
  
      # Test loss forward with reduction_override
      loss = loss_class(naive_dice=naive_dice)(
          pred, target, reduction_override="mean"
      )
      assert isinstance(loss, torch.Tensor)
  
      # Test loss forward with avg_factor
      loss = loss_class(naive_dice=naive_dice)(
          pred, target, avg_factor=10
      )
      assert isinstance(loss, torch.Tensor)
  
      with pytest.raises(ValueError):
          # loss can evaluate with avg_factor only if
          # reduction is None, 'none' or 'mean'.
          reduction_override = "sum"
          loss_class(naive_dice=naive_dice)(
              pred,
              target,
              avg_factor=10,
              reduction_override=reduction_override,
          )
  
      # Test loss forward with avg_factor and reduction
      for reduction_override in [None, "none", "mean"]:
          loss_class(naive_dice=naive_dice)(
              pred,
              target,
              avg_factor=10,
              reduction_override=reduction_override,
          )
          assert isinstance(loss, torch.Tensor)
  
      # Test loss forward with has_acted=False and use_sigmoid=False
      with pytest.raises(NotImplementedError):
          loss_class(
              use_sigmoid=False, activate=True, naive_dice=naive_dice
          )(pred, target)
  
      # Test loss forward with weight.ndim != loss.ndim
      with pytest.raises(AssertionError):
          weight = torch.rand((2, 8))
          loss_class(naive_dice=naive_dice)(pred, target, weight)
  
      # Test loss forward with len(weight) != len(pred)
      with pytest.raises(AssertionError):
          weight = torch.rand((8))
          loss_class(naive_dice=naive_dice)(pred, target, weight)
  
file_path: mmdetection/tests/test_models/test_losses/test_loss.py
imports: import json
  import pytest
  import torch
  import torch.nn.functional
  from mmengine.utils import digit_version
  from mmdet.models.losses import BalancedL1Loss, CrossEntropyLoss, DDQAuxLoss, DiceLoss, DistributionFocalLoss, EQLV2Loss, FocalLoss, GaussianFocalLoss, KnowledgeDistillationKLDivLoss, L1Loss, MarginL2Loss, MSELoss, QualityFocalLoss, SeesawLoss, SmoothL1Loss, VarifocalLoss
  from mmdet.models.losses.ghm_loss import GHMC, GHMR
  from mmdet.models.losses.iou_loss import BoundedIoULoss, CIoULoss, DIoULoss, EIoULoss, GIoULoss, IoULoss, SIoULoss
label_desc: Use image node_id 9 for calling a global function with example usage: test_dice_loss(naive_dice) without return types