Launch multiple tasks. Args: tasks (list[dict]): A list of task configs, usually generated by Partitioner. Returns: list[tuple[str, int]]: A list of (task name, exit code).
(self, tasks: List[Dict[str, Any]])
| 67 | logger.warning(f'Ignored argument in {self.__module__}: {k}={v}') |
| 68 | |
| 69 | def launch(self, tasks: List[Dict[str, Any]]) -> List[Tuple[str, int]]: |
| 70 | """Launch multiple tasks. |
| 71 | |
| 72 | Args: |
| 73 | tasks (list[dict]): A list of task configs, usually generated by |
| 74 | Partitioner. |
| 75 | |
| 76 | Returns: |
| 77 | list[tuple[str, int]]: A list of (task name, exit code). |
| 78 | """ |
| 79 | |
| 80 | status = [] |
| 81 | import torch |
| 82 | |
| 83 | if is_npu_available(): |
| 84 | visible_devices = 'ASCEND_RT_VISIBLE_DEVICES' |
| 85 | device_nums = torch.npu.device_count() |
| 86 | else: |
| 87 | visible_devices = 'CUDA_VISIBLE_DEVICES' |
| 88 | device_nums = torch.cuda.device_count() |
| 89 | if visible_devices in os.environ: |
| 90 | all_gpu_ids = [ |
| 91 | int(i) |
| 92 | for i in re.findall(r'(?<!-)\d+', os.getenv(visible_devices)) |
| 93 | ] |
| 94 | else: |
| 95 | all_gpu_ids = list(range(device_nums)) |
| 96 | |
| 97 | if self.debug: |
| 98 | for task in tasks: |
| 99 | task = TASKS.build(dict(cfg=task, type=self.task_cfg['type'])) |
| 100 | task_name = task.name |
| 101 | num_gpus = task.num_gpus |
| 102 | assert len(all_gpu_ids) >= num_gpus |
| 103 | # get cmd |
| 104 | mmengine.mkdir_or_exist('tmp/') |
| 105 | import uuid |
| 106 | uuid_str = str(uuid.uuid4()) |
| 107 | |
| 108 | param_file = f'tmp/{uuid_str}_params.py' |
| 109 | try: |
| 110 | task.cfg.dump(param_file) |
| 111 | # if use torchrun, restrict it behaves the same as non |
| 112 | # debug mode, otherwise, the torchrun will use all the |
| 113 | # available resources which might cause inconsistent |
| 114 | # behavior. |
| 115 | if len(all_gpu_ids) > num_gpus and num_gpus > 0: |
| 116 | get_logger().warning(f'Only use {num_gpus} GPUs for ' |
| 117 | f'total {len(all_gpu_ids)} ' |
| 118 | 'available GPUs in debug mode.') |
| 119 | tmpl = get_command_template(all_gpu_ids[:num_gpus]) |
| 120 | cmd = task.get_command(cfg_path=param_file, template=tmpl) |
| 121 | # run in subprocess if starts with torchrun etc. |
| 122 | if 'python3 ' in cmd or 'python ' in cmd: |
| 123 | # If it is an infer type task do not reload if |
| 124 | # the current model has already been loaded. |
| 125 | if 'infer' in self.task_cfg.type.lower(): |
| 126 | # If a model instance already exists, |
nothing calls this directly
no test coverage detected