def test_gpus(self): def _job(): self.assertEqual(len(os.environ['CUDA_VISIBLE_DEVICES']), 1) time.sleep(1) scheduler = resource.Scheduler(num_cpu_workers=2, num_gpu_workers=2) scheduler.add(1, 1, _job, ()) scheduler.add(1, 1, _job, ()) scheduler.run()
def test_scheduler(self): scheduler = resource.Scheduler(num_cpu_workers=2, num_gpu_workers=2) for _ in range(3): scheduler.add(1, 0, time.sleep, (2,)) scheduler.add(1, 1, _incorrect_code, ()) scheduler.add(1, 2, _runtime_error, ()) scheduler.run() self.assertEqual(len(scheduler.failed_tasks), 2) logging.info(scheduler.error_message)
def eval(self): """Evaluate the notebooks and save them in a different folder""" # TODO(mli) if tabs is enabled, and a .md doesn't have the default tab, # then the current implementation will not run the eval. eval_tik = datetime.datetime.now() notebooks, pure_markdowns, depends = self._find_md_files() depends_mtimes = get_mtimes(depends) latest_depend = max(depends_mtimes) if len(depends_mtimes) else 0 updated_notebooks = get_updated_files(notebooks, self.config.src_dir, self.config.eval_dir, 'md', 'ipynb', latest_depend) updated_markdowns = get_updated_files(pure_markdowns, self.config.src_dir, self.config.eval_dir, 'md', 'md', latest_depend) num_updated_notebooks = len(updated_notebooks) num_updated_markdowns = len(updated_markdowns) logging.info('%d notebooks are outdated', num_updated_notebooks) for i, nb in enumerate(updated_notebooks): logging.info('[%d] %s', i + 1, nb[0]) self._copy_resources(self.config.src_dir, self.config.eval_dir) gpus = resource.get_available_gpus() num_cpu_workers = len(gpus) if gpus else 2 logging.info( f'Evaluating notebooks in parallel with {num_cpu_workers} CPU workers and {len(gpus)} GPU workers' ) scheduler = resource.Scheduler(num_cpu_workers, len(gpus)) run_cells = self.config.build['eval_notebook'].lower() == 'true' for i, (src, tgt) in enumerate(updated_notebooks): mkdir(os.path.dirname(tgt)) _process_and_eval_notebook(scheduler, src, tgt, run_cells, self.config) scheduler.run() assert not scheduler.failed_tasks, scheduler.error_message for src, tgt in updated_markdowns: logging.info('Copying %s to %s', src, tgt) mkdir(os.path.dirname(tgt)) shutil.copyfile(src, tgt) self._rm_tgt_files('md', 'ipynb', self.config.eval_dir)