code: def _test(
      local_rank: int,
      world_size: int,
      device: "torch.device",
      dataset: DataSet,
      metric_class,
      metric_kwargs,
      metric_result,
  ):
      metric = metric_class(**metric_kwargs)
      # dataset 也类似（每个进程有自己的一个）
      dataset = copy.deepcopy(dataset)
      metric.to(device)
      # 把数据拆到每个 GPU 上，有点模仿 DistributedSampler 的感觉，但这里数据单位是一个 batch（即每个 i 取了一个 batch 到自己的 GPU 上）
      for i in range(local_rank, len(dataset), world_size):
          pred, tg = dataset[i]["pred"].to(device), dataset[i]["tg"].to(
              device
          )
          metric.update(pred, tg)
  
      my_result = metric.get_metric()
      for keys in ["f", "pre", "rec"]:
          assert np.allclose(
              my_result[keys], metric_result[keys], atol=0.000001
          )
  
file_path: fastNLP/tests/core/metrics/test_classify_f1_pre_rec_metric_torch.py
imports: from functools import partial
  import copy
  import pytest
  import numpy
  from fastNLP.core.metrics import ClassifyFPreRecMetric
  from fastNLP.core.dataset import DataSet
  from fastNLP.envs.imports import _NEED_IMPORT_TORCH
  from .utils import find_free_network_port, setup_ddp
label_desc: Use image node_id 1 for calling a global function with example usage: _test(local_rank, world_size, device, dataset, metric_class, metric_kwargs, metric_result) without return types