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]])
| 178 | ], 'Only supported for api infer task.' |
| 179 | |
| 180 | def launch(self, tasks: List[Dict[str, Any]]) -> List[Tuple[str, int]]: |
| 181 | """Launch multiple tasks. |
| 182 | |
| 183 | Args: |
| 184 | tasks (list[dict]): A list of task configs, usually generated by |
| 185 | Partitioner. |
| 186 | |
| 187 | Returns: |
| 188 | list[tuple[str, int]]: A list of (task name, exit code). |
| 189 | """ |
| 190 | status = [] |
| 191 | if self.debug: |
| 192 | # fall back to LocalRunner debug mode |
| 193 | for task in tasks: |
| 194 | task = TASKS.build(dict(cfg=task, type=self.task_cfg['type'])) |
| 195 | task_name = task.name |
| 196 | # get cmd |
| 197 | mmengine.mkdir_or_exist('tmp/') |
| 198 | param_file = f'tmp/{os.getpid()}_params.py' |
| 199 | try: |
| 200 | task.cfg.dump(param_file) |
| 201 | cmd = task.get_command(cfg_path=param_file, |
| 202 | template='{task_cmd}') |
| 203 | # run in subprocess if starts with torchrun etc. |
| 204 | if cmd.startswith('python'): |
| 205 | task.run() |
| 206 | else: |
| 207 | subprocess.run(cmd, shell=True, text=True) |
| 208 | finally: |
| 209 | os.remove(param_file) |
| 210 | status.append((task_name, 0)) |
| 211 | else: |
| 212 | |
| 213 | pbar = tqdm(total=len(tasks)) |
| 214 | |
| 215 | get_logger().info('All the logs and processes for each task' |
| 216 | ' should be checked in each infer/.out file.') |
| 217 | with Manager() as manager: |
| 218 | tokens = manager.Semaphore(self.concurrent_users) |
| 219 | # pbar update has visualization issue when direct |
| 220 | # update pbar in callback, need an extra counter |
| 221 | pbar_counter = manager.Value('i', 0) |
| 222 | status = [] |
| 223 | |
| 224 | def update(args): |
| 225 | """Update pbar counter when callback.""" |
| 226 | pbar_counter.value += 1 |
| 227 | status.append(args) |
| 228 | |
| 229 | with Pool(processes=self.max_num_workers) as pool: |
| 230 | for task in tasks: |
| 231 | pool.apply_async(submit, |
| 232 | (task, self.task_cfg['type'], tokens), |
| 233 | callback=update) |
| 234 | pool.close() |
| 235 | |
| 236 | # update progress bar |
| 237 | while True: |
nothing calls this directly
no test coverage detected