A WorkflowRunner for debugging.
| 438 | |
| 439 | |
| 440 | class DebugWorkflowRunner(WorkflowRunner): |
| 441 | """A WorkflowRunner for debugging.""" |
| 442 | |
| 443 | def __init__( |
| 444 | self, |
| 445 | config: Config, |
| 446 | output_dir: str = "debug_output", |
| 447 | enable_profiling: bool = False, |
| 448 | disable_overwrite: bool = False, |
| 449 | ) -> None: |
| 450 | if disable_overwrite: |
| 451 | # if output dir is not empty, change to a new dir with datetime suffix |
| 452 | if os.path.isdir(output_dir) and os.listdir(output_dir): |
| 453 | suffix = time.strftime("%Y%m%d%H%M%S", time.localtime()) |
| 454 | output_dir = f"{output_dir}_{suffix}" |
| 455 | os.environ[LOG_DIR_ENV_VAR] = os.path.join(output_dir, "log") |
| 456 | os.environ[LOG_LEVEL_ENV_VAR] = "DEBUG" |
| 457 | super().__init__( |
| 458 | config=config, |
| 459 | rollout_model_id=0, |
| 460 | auxiliary_model_ids=[0] * len(config.explorer.auxiliary_models), |
| 461 | runner_id=0, |
| 462 | ) |
| 463 | self.taskset = get_buffer_reader(config.buffer.explorer_input.tasksets[0]) |
| 464 | self.output_dir = output_dir |
| 465 | self.enable_profiling = enable_profiling |
| 466 | self.logger.info(f"Debug output directory: {self.output_dir}") |
| 467 | os.makedirs(self.output_dir, exist_ok=True) |
| 468 | self.output_profiling_file = os.path.join( |
| 469 | self.output_dir, |
| 470 | "profiling.html", |
| 471 | ) |
| 472 | self.output_sqlite_file = "sqlite:///" + os.path.join( |
| 473 | self.output_dir, |
| 474 | "experiences.db", |
| 475 | ) |
| 476 | self.sqlite_writer = get_buffer_writer( |
| 477 | StorageConfig( |
| 478 | name="debug_buffer", |
| 479 | schema_type="experience", |
| 480 | path=self.output_sqlite_file, |
| 481 | storage_type="sql", |
| 482 | batch_size=1, |
| 483 | wrap_in_ray=False, |
| 484 | ) |
| 485 | ) |
| 486 | |
| 487 | async def debug(self) -> None: |
| 488 | """Run the debug workflow.""" |
| 489 | tasks = await self.taskset.read(batch_size=1) |
| 490 | task = tasks[0] |
| 491 | self.logger.info(f"Start debugging task:\n{task.raw_task}") |
| 492 | if not self.enable_profiling: |
| 493 | status, exp_payload = await self.run_task( |
| 494 | task=task, batch_id="debug", repeat_times=1, run_id_base=0 |
| 495 | ) |
| 496 | else: |
| 497 | from viztracer import VizTracer |