This function first parses the configuration arguments, using :func:`parse_args()` in case one of the input arguments are not given. Then initialize and set distributed environment by calling global_context's functions. Args: config (Union[str, dict, Config]): Config file or config
(
config: Union[str, Path, Config, Dict],
rank: int,
world_size: int,
host: str,
port: int,
backend: str = "nccl",
local_rank: int = None,
seed: int = 1024,
)
| 296 | |
| 297 | |
| 298 | def launch( |
| 299 | config: Union[str, Path, Config, Dict], |
| 300 | rank: int, |
| 301 | world_size: int, |
| 302 | host: str, |
| 303 | port: int, |
| 304 | backend: str = "nccl", |
| 305 | local_rank: int = None, |
| 306 | seed: int = 1024, |
| 307 | ): |
| 308 | """This function first parses the configuration arguments, using :func:`parse_args()` in case one of the input |
| 309 | arguments are not given. Then initialize and set distributed environment by calling global_context's functions. |
| 310 | |
| 311 | Args: |
| 312 | config (Union[str, dict, Config]): Config file or config file path are both acceptable |
| 313 | rank (int): Rank for the default process group |
| 314 | world_size (int): World size of the default process group |
| 315 | host (str): The master address for distributed training |
| 316 | port (str): The master port for distributed training |
| 317 | backend (str, optional): Backend for ``torch.distributed``, defaults to ``nccl`` |
| 318 | local_rank (int, optional): |
| 319 | Rank for the process on the node and is used to set the default CUDA device, |
| 320 | defaults to None. If local_rank = None, the default device ordinal will be calculated automatically. |
| 321 | seed (int, optional): Specified random seed for every process. Defaults to 1024. |
| 322 | |
| 323 | Raises: |
| 324 | Exception: Raise exception when config type is wrong |
| 325 | """ |
| 326 | |
| 327 | # set config |
| 328 | assert isinstance( |
| 329 | config, (Config, str, Path, dict) |
| 330 | ), f"expected argument config to be Config, str or Path, but got {type(config)}" |
| 331 | if not isinstance(config, Config) and isinstance(config, dict): |
| 332 | config = Config(config) |
| 333 | if isinstance(config, (str, Path)): |
| 334 | config = Config.from_file(config) |
| 335 | gpc.load_config(config) |
| 336 | |
| 337 | # init default process group |
| 338 | gpc.init_global_dist(rank, world_size, backend, host, port) |
| 339 | |
| 340 | # init process groups for different parallel modes from config |
| 341 | gpc.init_parallel_groups() |
| 342 | |
| 343 | # set cuda device |
| 344 | if torch.cuda.is_available(): |
| 345 | # if local rank is not given, calculate automatically |
| 346 | gpc.set_device(local_rank) |
| 347 | |
| 348 | # set the number of processes running on the same node |
| 349 | gpc.detect_num_processes_on_current_node() |
| 350 | |
| 351 | gpc.set_seed(seed) |
| 352 | |
| 353 | if gpc.is_rank_for_log(): |
| 354 | logger.info( |
| 355 | f"Distributed environment is initialized, " |
no test coverage detected