code: def test_metric_stats(device):
      from speechbrain.utils.metric_stats import MetricStats
      from speechbrain.nnet.losses import l1_loss
  
      l1_stats = MetricStats(metric=l1_loss)
      l1_stats.append(
          ids=["utterance1", "utterance2"],
          predictions=torch.tensor(
              [[0.1, 0.2], [0.1, 0.2]], device=device
          ),
          targets=torch.tensor([[0.1, 0.3], [0.2, 0.3]], device=device),
          length=torch.ones(2, device=device),
          reduction="batch",
      )
      summary = l1_stats.summarize()
      assert math.isclose(summary["average"], 0.075, rel_tol=1e-5)
      assert math.isclose(summary["min_score"], 0.05, rel_tol=1e-5)
      assert summary["min_id"] == "utterance1"
      assert math.isclose(summary["max_score"], 0.1, rel_tol=1e-5)
      assert summary["max_id"] == "utterance2"
  
file_path: speechbrain/tests/unittests/test_metrics.py
imports: import torch
  import torch.nn
  import math
label_desc: Use image node_id 1 for calling a global function with example usage: test_metric_stats(device) without return types