Hack for infer task run, add tokens for multiprocess.
(self, tokens: SyncManager.Semaphore)
| 24 | |
| 25 | |
| 26 | def monkey_run(self, tokens: SyncManager.Semaphore): |
| 27 | """Hack for infer task run, add tokens for multiprocess.""" |
| 28 | self.logger.info(f'Task {task_abbr_from_cfg(self.cfg)}') |
| 29 | for model_cfg, dataset_cfgs in zip(self.model_cfgs, self.dataset_cfgs): |
| 30 | self.max_out_len = model_cfg.get('max_out_len', None) |
| 31 | self.min_out_len = model_cfg.get('min_out_len', None) |
| 32 | self.batch_size = model_cfg.get('batch_size', None) |
| 33 | self.model = build_model_from_cfg(model_cfg) |
| 34 | # add global tokens for concurrents |
| 35 | assert self.model.is_api, 'Only API model is supported.' |
| 36 | self.model.tokens = tokens |
| 37 | |
| 38 | for dataset_cfg in dataset_cfgs: |
| 39 | self.model_cfg = model_cfg |
| 40 | self.dataset_cfg = dataset_cfg |
| 41 | self.infer_cfg = self.dataset_cfg['infer_cfg'] |
| 42 | self.dataset = build_dataset_from_cfg(self.dataset_cfg) |
| 43 | self.sub_cfg = { |
| 44 | 'models': [self.model_cfg], |
| 45 | 'datasets': [[self.dataset_cfg]], |
| 46 | } |
| 47 | out_path = get_infer_output_path( |
| 48 | self.model_cfg, self.dataset_cfg, |
| 49 | osp.join(self.work_dir, 'predictions')) |
| 50 | if osp.exists(out_path): |
| 51 | continue |
| 52 | self._inference() |
| 53 | |
| 54 | |
| 55 | old_stdout = sys.stdout |
nothing calls this directly
no test coverage detected