mirror of
https://github.com/wassname/ray.git
synced 2026-08-09 12:20:09 +08:00
[tune] Prevent leak of magic keys in trial config (#9903)
Co-authored-by: Kai Fricke <kai@anyscale.com> Co-authored-by: Richard Liaw <rliaw@berkeley.edu>
This commit is contained in:
co-authored by
Kai Fricke
Richard Liaw
parent
bdc42f8dab
commit
ef717ecda6
@@ -1,6 +1,7 @@
|
||||
import copy
|
||||
import logging
|
||||
import os
|
||||
from typing import Sequence
|
||||
|
||||
from ray.tune.error import TuneError
|
||||
from ray.tune.function_runner import detect_checkpoint_function
|
||||
@@ -45,6 +46,31 @@ def _raise_on_durable(trainable_name, sync_to_driver, upload_dir):
|
||||
"`upload_dir` must be provided.")
|
||||
|
||||
|
||||
def _validate_log_to_file(log_to_file):
|
||||
"""Validate ``tune.run``'s ``log_to_file`` parameter. Return
|
||||
validated relative stdout and stderr filenames."""
|
||||
if not log_to_file:
|
||||
stdout_file = stderr_file = None
|
||||
elif isinstance(log_to_file, bool) and log_to_file:
|
||||
stdout_file = "stdout"
|
||||
stderr_file = "stderr"
|
||||
elif isinstance(log_to_file, str):
|
||||
stdout_file = stderr_file = log_to_file
|
||||
elif isinstance(log_to_file, Sequence):
|
||||
if len(log_to_file) != 2:
|
||||
raise ValueError(
|
||||
"If you pass a Sequence to `log_to_file` it has to have "
|
||||
"a length of 2 (for stdout and stderr, respectively). The "
|
||||
"Sequence you passed has length {}.".format(len(log_to_file)))
|
||||
stdout_file, stderr_file = log_to_file
|
||||
else:
|
||||
raise ValueError(
|
||||
"You can pass a boolean, a string, or a Sequence of length 2 to "
|
||||
"`log_to_file`, but you passed something else ({}).".format(
|
||||
type(log_to_file)))
|
||||
return stdout_file, stderr_file
|
||||
|
||||
|
||||
class Experiment:
|
||||
"""Tracks experiment specifications.
|
||||
|
||||
@@ -82,6 +108,7 @@ class Experiment:
|
||||
upload_dir=None,
|
||||
trial_name_creator=None,
|
||||
loggers=None,
|
||||
log_to_file=False,
|
||||
sync_to_driver=None,
|
||||
checkpoint_freq=0,
|
||||
checkpoint_at_end=False,
|
||||
@@ -133,6 +160,8 @@ class Experiment:
|
||||
|
||||
_raise_on_durable(self._run_identifier, sync_to_driver, upload_dir)
|
||||
|
||||
stdout_file, stderr_file = _validate_log_to_file(log_to_file)
|
||||
|
||||
spec = {
|
||||
"run": self._run_identifier,
|
||||
"stop": stopping_criteria,
|
||||
@@ -145,6 +174,7 @@ class Experiment:
|
||||
"remote_checkpoint_dir": self.remote_checkpoint_dir,
|
||||
"trial_name_creator": trial_name_creator,
|
||||
"loggers": loggers,
|
||||
"log_to_file": (stdout_file, stderr_file),
|
||||
"sync_to_driver": sync_to_driver,
|
||||
"checkpoint_freq": checkpoint_freq,
|
||||
"checkpoint_at_end": checkpoint_at_end,
|
||||
|
||||
Reference in New Issue
Block a user