class_docstr: 复原了 paddle 的 launch_collective 函数，将其简化后集成到一个类里
  仅支持每个机器单卡的情况。
class_docstr_tok: ["\u590d\u539f\u4e86","paddle","\u7684","launch_collective","\u51fd\u6570\uff0c\u5c06\u5176\u7b80\u5316\u540e\u96c6\u6210\u5230\u4e00\u4e2a\u7c7b\u91cc","\u4ec5\u652f\u6301\u6bcf\u4e2a\u673a\u5668\u5355\u5361\u7684\u60c5\u51b5\u3002"]
docstr: 设置分布式训练需要的全局变量，包括：
  1、GLOO 相关的设置
  2、`PADDLE_TRAINERS_NUM` ：所有的进程数目
  3、`PADDLE_TRAINER_ENDPOINTS` ：使用的所有地址及其端口
  4、`PADDLE_WORLD_DEVICE_IDS` ：使用的所有设备
  5、FASTNLP_DISTRIBUTED_CHECK：通过 fastNLP 建立子进程的标志，保存分布式训练使用的设备
docstr_tok: ["\u8bbe\u7f6e\u5206\u5e03\u5f0f\u8bad\u7ec3\u9700\u8981\u7684\u5168\u5c40\u53d8\u91cf\uff0c\u5305\u62ec\uff1a","1\u3001GLOO","\u76f8\u5173\u7684\u8bbe\u7f6e","2\u3001","`","PADDLE_TRAINERS_NUM","`","\uff1a\u6240\u6709\u7684\u8fdb\u7a0b\u6570\u76ee","3\u3001","`","PADDLE_TRAINER_ENDPOINTS","`","\uff1a\u4f7f\u7528\u7684\u6240\u6709\u5730\u5740\u53ca\u5176\u7aef\u53e3","4\u3001","`","PADDLE_WORLD_DEVICE_IDS","`","\uff1a\u4f7f\u7528\u7684\u6240\u6709\u8bbe\u5907","5\u3001FASTNLP_DISTRIBUTED_CHECK\uff1a\u901a\u8fc7","fastNLP","\u5efa\u7acb\u5b50\u8fdb\u7a0b\u7684\u6807\u5fd7\uff0c\u4fdd\u5b58\u5206\u5e03\u5f0f\u8bad\u7ec3\u4f7f\u7528\u7684\u8bbe\u5907"]
code: def get_global_env(self):
      """
      设置分布式训练需要的全局变量，包括：
      1、GLOO 相关的设置
      2、`PADDLE_TRAINERS_NUM` ：所有的进程数目
      3、`PADDLE_TRAINER_ENDPOINTS` ：使用的所有地址及其端口
      4、`PADDLE_WORLD_DEVICE_IDS` ：使用的所有设备
      5、FASTNLP_DISTRIBUTED_CHECK：通过 fastNLP 建立子进程的标志，保存分布式训练使用的设备
      """
  
      global_envs = copy.copy(os.environ.copy())
      os.environ[FASTNLP_GLOBAL_RANK] = "0"
  
      self.gloo_rendezvous_dir = tempfile.mkdtemp()
      # launch中涉及的gloo环境
      global_envs["PADDLE_WITH_GLOO"] = str(
          os.getenv("PADDLE_WITH_GLOO", "0")
      )
      global_envs["PADDLE_GLOO_RENDEZVOUS"] = "3"
      global_envs["PADDLE_GLOO_FS_PATH"] = self.gloo_rendezvous_dir
      global_envs["PADDLE_DISTRI_BACKEND"] = "nccl"
  
      # 通过FNLP初始化的标志
      global_envs[
          FASTNLP_DISTRIBUTED_CHECK
      ] = f"{','.join([str(g) for g in self.devices])}"
  
      # 统计全局信息
      device_ids = []
      for t in self.sub_trainers:
          device_ids.append([str(acc) for acc in t.devices])
      world_device_ids = [":".join(ele) for ele in device_ids]
      # 全局环境变量
      global_envs.update(
          {
              # world_size
              "PADDLE_TRAINERS_NUM": f"{len(self.sub_trainers)}",
              "PADDLE_TRAINER_ENDPOINTS": ",".join(self.endpoints),
              "PADDLE_WORLD_DEVICE_IDS": ",".join(world_device_ids),
          }
      )
  
      return global_envs
  
imports: import os
  import sys
  import __main__
  import tempfile
  import copy
  from typing import List
  from fastNLP.core.drivers.utils import distributed_open_proc
  from fastNLP.envs.env import FASTNLP_DISTRIBUTED_CHECK, FASTNLP_LOG_LEVEL, FASTNLP_GLOBAL_SEED, FASTNLP_GLOBAL_RANK
  from fastNLP.core.utils import get_paddle_device_id
  from .utils import find_free_ports
label_desc: Use image node_id 5 for calling the FleetLauncher obj's underlying member method code with example usage: obj.get_global_env() and returns: global_envs