code: def test_1(trainer_params: TrainerParameters, device):
      # 测试能否自动 aggregate 。
      for aggregate_when_get_metric, use_dist_sampler in product(
          [True, False], [True, False, None]
      ):
          metric = DistMetric(
              aggregate_when_get_metric=aggregate_when_get_metric
          )
  
          evaluator = Evaluator(
              trainer_params.model,
              dataloaders=trainer_params.evaluate_dataloaders,
              metrics={"c": metric},
              driver="torch",
              device=device,
              use_dist_sampler=use_dist_sampler,
              progress_bar="tqdm",
          )
          if use_dist_sampler is None:
              use_dist_sampler = device is not None
          results = evaluator.run()
          num_samples = len(trainer_params.evaluate_dataloaders.dataset)
          if device is None:
              assert results["count#c"] == num_samples
              assert results["count2#c"] == num_samples
          else:
              if (
                  aggregate_when_get_metric is True
                  and use_dist_sampler is True
              ):
                  assert results["count#c"] == num_samples
                  assert results["count2#c"] == num_samples
              elif (
                  aggregate_when_get_metric is True
                  and use_dist_sampler is False
              ):
                  assert results["count#c"] == 2 * num_samples
                  assert results["count2#c"] == 2 * num_samples
              elif (
                  aggregate_when_get_metric is False
                  and use_dist_sampler is True
              ):
                  assert results["count#c"] in (49, 50)  # 不同卡，数量不同
                  assert results["count2#c"] in (49, 50)
              else:
                  assert results["count#c"] == num_samples
                  assert results["count2#c"] == num_samples
  
      if dist.is_initialized():
          dist.destroy_process_group()
  
imports: import pytest
  from fastNLP import Metric, Evaluator
  from dataclasses import dataclass
  from typing import Any
  from itertools import product
  from fastNLP.core.controllers.trainer import Trainer
  from tests.helpers.models.torch_model import TorchNormalModel_Classification_1
  from tests.helpers.datasets.torch_data import TorchNormalDataset_Classification, TorchArgMaxDataset
  from tests.helpers.utils import magic_argv_env_context
  from fastNLP.envs.imports import _NEED_IMPORT_TORCH
  from fastNLP import Event
label_desc: Use image node_id 2 for calling a global function with example usage: test_1(trainer_params, device) without return types