Skip to content

Commit

Permalink
[Tune] Remove trial table when running Ray Train in a Jupyter notebook (
Browse files Browse the repository at this point in the history
ray-project#44858)

This PR removes the trial table mistakenly displayed during Ray Train in a Jupyter notebook, which should only appear in Ray Tune sessions.

---------

Signed-off-by: Hongpeng Guo <hpguo@anyscale.com>
  • Loading branch information
hongpeng-guo authored Apr 22, 2024
1 parent ba340b7 commit fbbc38f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions python/ray/tune/progress_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1512,15 +1512,15 @@ def _print_result(self, result: Dict):
return print_result_str


def _detect_reporter(**kwargs) -> TuneReporterBase:
def _detect_reporter(_trainer_api: bool = False, **kwargs) -> TuneReporterBase:
"""Detect progress reporter class.
Will return a :class:`JupyterNotebookReporter` if a IPython/Jupyter-like
session was detected, and a :class:`CLIReporter` otherwise.
Keyword arguments are passed on to the reporter class.
"""
if IS_NOTEBOOK:
if IS_NOTEBOOK and not _trainer_api:
kwargs.setdefault("overwrite", not has_verbosity(Verbosity.V2_TRIAL_NORM))
progress_reporter = JupyterNotebookReporter(**kwargs)
else:
Expand Down
3 changes: 3 additions & 0 deletions python/ray/tune/tests/test_progress_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,9 @@ def testReporterDetection(self):
reporter = _detect_reporter()
self.assertFalse(isinstance(reporter, CLIReporter))
self.assertTrue(isinstance(reporter, JupyterNotebookReporter))
trainer_reporter = _detect_reporter(_trainer_api=True)
self.assertFalse(isinstance(trainer_reporter, JupyterNotebookReporter))
self.assertTrue(isinstance(trainer_reporter, CLIReporter))

def testProgressReporterAPI(self):
class CustomReporter(ProgressReporter):
Expand Down
5 changes: 4 additions & 1 deletion python/ray/tune/tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,10 @@ def run(
progress_reporter = None

if air_verbosity is None:
progress_reporter = progress_reporter or _detect_reporter()
is_trainer = _entrypoint == AirEntrypoint.TRAINER
progress_reporter = progress_reporter or _detect_reporter(
_trainer_api=is_trainer
)

if resume is not None:
resume_config = resume_config or _build_resume_config_from_legacy_config(resume)
Expand Down

0 comments on commit fbbc38f

Please sign in to comment.