code: def test_add_file_ddp_1_torch():
      """
      测试 path 是一个文件的地址，但是这个文件所在的文件夹存在；
  
      多卡时根据时间创造文件名字有一个很大的 bug，就是不同的进程启动之间是有时差的，因此会导致他们各自输出到单独的 log 文件中；
      """
      import torch
      import torch.distributed as dist
  
      from fastNLP.core.log.logger import logger
      from fastNLP.core.drivers.torch_driver.ddp import TorchDDPDriver
      from tests.helpers.models.torch_model import (
          TorchNormalModel_Classification_1,
      )
  
      model = TorchNormalModel_Classification_1(
          num_labels=3, feature_dimension=10
      )
  
      driver = TorchDDPDriver(
          model=model,
          parallel_device=[
              torch.device("cuda:0"),
              torch.device("cuda:1"),
          ],
          output_from_new_proc="all",
      )
      driver.setup()
      msg = "some test log msg"
  
      path = Path.cwd()
      filepath = path.joinpath("log.txt")
      handler = logger.add_file(filepath, mode="w")
      logger.info(msg)
      logger.warning(
          f"\nrank {driver.get_local_rank()} should have this message!\n"
      )
  
      for h in logger.handlers:
          if isinstance(h, logging.FileHandler):
              h.flush()
      dist.barrier()
      with open(filepath, "r") as f:
          line = "".join([l for l in f])
      assert msg in line
      assert (
          f"\nrank {driver.get_local_rank()} should have this message!\n"
          in line
      )
  
      pattern = re.compile(msg)
      assert len(pattern.findall(line)) == 1
  
      rank_zero_rm(filepath)
      dist.barrier()
      dist.destroy_process_group()
  
imports: import os
  import tempfile
  import datetime
  from pathlib import Path
  import logging
  import re
  import pytest
  from fastNLP.envs.env import FASTNLP_LAUNCH_TIME
  from fastNLP.envs.distributed import rank_zero_rm
  from fastNLP.core.log.logger import logger
  from tests.helpers.utils import magic_argv_env_context, recover_logger
label_desc: Use image node_id 1 for calling a global function with example usage: test_add_file_ddp_1_torch() without return types