code: def fastnlp_no_sync_context(level: int = 2):
      """
      用于让 **fastNLP** 的 :meth:`barrier` 以及 ``gather`` / ``broadcast`` 等操作等同于只有 1 卡的多卡程序。如果为 1 表示 **fastNLP** 里的
      :meth:`barrier` 操作失效；如果为 2 表示 :meth:`barrier` 与 ``gather`` / ``broadcast`` 都失效。
  
      :param level: 可选 ``[0, 1, 2]``
      """
      old_level = os.environ.get(FASTNLP_NO_SYNC, None)
      os.environ[FASTNLP_NO_SYNC] = f"{level}"
      yield
      if old_level is None:
          os.environ.pop(FASTNLP_NO_SYNC)
      else:
          os.environ[FASTNLP_NO_SYNC] = old_level
  
file_path: fastNLP/fastNLP/envs/distributed.py
imports: import os
  from functools import wraps
  from pathlib import Path
  from typing import Callable, Any, Optional, Union
  from contextlib import contextmanager
  from fastNLP.envs.env import FASTNLP_GLOBAL_RANK, FASTNLP_NO_SYNC
label_desc: Use image node_id 4 for calling a global function with example usage: fastnlp_no_sync_context(level) without return types