code: def test_cross_entropy(metric_name, class_num):
      preds = []
      targets = []
      random.seed(123)
      torch.manual_seed(123)
  
      for i in range(100):
          bs = random.randint(1, 16)
          preds.append(torch.randn(bs, class_num))
          targets.append(torch.randint(0, class_num, (bs,)))
  
      _, custom_metric_func = get_metric(metric_name=metric_name)
      mean_metric = MeanMetric()
  
      for per_pred, per_target in zip(preds, targets):
          mean_metric.update(custom_metric_func(per_pred, per_target))
  
      score1 = mean_metric.compute()
      preds = torch.cat(preds).softmax(dim=1)
      targets = torch.cat(targets)
      score2 = log_loss(
          y_true=targets,
          y_pred=preds,
      )
      assert pytest.approx(score1, 1e-6) == score2
  
imports: import os
  import random
  import shutil
  import tempfile
  import pytest
  import torch
  from sklearn.metrics import f1_score, log_loss
  from torchmetrics import MeanMetric, RetrievalHitRate
  import autogluon.core.metrics
  from autogluon.multimodal import MultiModalPredictor
  from autogluon.multimodal.constants import MULTICLASS, Y_PRED, Y_TRUE
  from autogluon.multimodal.optimization.utils import compute_hit_rate, get_loss_func, get_metric
  from autogluon.multimodal.utils import compute_score, infer_metrics
  from ..utils.unittest_datasets import HatefulMeMesDataset, PetFinderDataset
  from ..utils.utils import get_home_dir
label_desc: Use image node_id 1 for calling a global function with example usage: test_cross_entropy(metric_name, class_num) without return types