mirror of
https://github.com/wassname/ray.git
synced 2026-09-10 12:38:43 +08:00
[tune] TensorBoard HParams for TF2.0 (#5678)
This commit is contained in:
committed by
Richard Liaw
parent
79b9c70ad6
commit
7e214fd95e
@@ -8,7 +8,8 @@ import random
|
||||
from ray.tune.error import TuneError
|
||||
from ray.tune.experiment import convert_to_experiment_list
|
||||
from ray.tune.config_parser import make_parser, create_trial_from_spec
|
||||
from ray.tune.suggest.variant_generator import generate_variants
|
||||
from ray.tune.suggest.variant_generator import (generate_variants, format_vars,
|
||||
flatten_resolved_vars)
|
||||
from ray.tune.suggest.search import SearchAlgorithm
|
||||
|
||||
|
||||
@@ -78,13 +79,13 @@ class BasicVariantGenerator(SearchAlgorithm):
|
||||
for resolved_vars, spec in generate_variants(unresolved_spec):
|
||||
experiment_tag = str(self._counter)
|
||||
if resolved_vars:
|
||||
experiment_tag += "_{}".format(resolved_vars)
|
||||
experiment_tag += "_{}".format(format_vars(resolved_vars))
|
||||
self._counter += 1
|
||||
yield create_trial_from_spec(
|
||||
spec,
|
||||
output_path,
|
||||
self._parser,
|
||||
evaluated_params=resolved_vars,
|
||||
evaluated_params=flatten_resolved_vars(resolved_vars),
|
||||
experiment_tag=experiment_tag)
|
||||
|
||||
def is_finished(self):
|
||||
|
||||
@@ -7,7 +7,7 @@ import copy
|
||||
|
||||
from ray.tune.error import TuneError
|
||||
from ray.tune.trial import Trial
|
||||
from ray.tune.util import merge_dicts
|
||||
from ray.tune.util import merge_dicts, flatten_dict
|
||||
from ray.tune.experiment import convert_to_experiment_list
|
||||
from ray.tune.config_parser import make_parser, create_trial_from_spec
|
||||
from ray.tune.suggest.search import SearchAlgorithm
|
||||
@@ -89,7 +89,8 @@ class SuggestionAlgorithm(SearchAlgorithm):
|
||||
else:
|
||||
break
|
||||
spec = copy.deepcopy(experiment_spec)
|
||||
spec["config"] = merge_dicts(spec["config"], suggested_config)
|
||||
spec["config"] = merge_dicts(spec["config"],
|
||||
copy.deepcopy(suggested_config))
|
||||
flattened_config = resolve_nested_dict(spec["config"])
|
||||
self._counter += 1
|
||||
tag = "{0}_{1}".format(
|
||||
@@ -98,7 +99,7 @@ class SuggestionAlgorithm(SearchAlgorithm):
|
||||
spec,
|
||||
output_path,
|
||||
self._parser,
|
||||
evaluated_params=list(suggested_config),
|
||||
evaluated_params=flatten_dict(suggested_config),
|
||||
experiment_tag=tag,
|
||||
trial_id=trial_id)
|
||||
|
||||
|
||||
@@ -39,10 +39,15 @@ def generate_variants(unresolved_spec):
|
||||
|
||||
"activation": {"grid_search": ["relu", "tanh"]}
|
||||
"cpu": {"eval": "spec.config.num_workers"}
|
||||
|
||||
Use `format_vars` to format the returned dict of hyperparameters.
|
||||
|
||||
Yields:
|
||||
(Dict of resolved variables, Spec object)
|
||||
"""
|
||||
for resolved_vars, spec in _generate_variants(unresolved_spec):
|
||||
assert not _unresolved_values(spec)
|
||||
yield format_vars(resolved_vars), spec
|
||||
yield resolved_vars, spec
|
||||
|
||||
|
||||
def grid_search(values):
|
||||
@@ -79,6 +84,7 @@ def resolve_nested_dict(nested_dict):
|
||||
|
||||
|
||||
def format_vars(resolved_vars):
|
||||
"""Formats the resolved variable dict into a single string."""
|
||||
out = []
|
||||
for path, value in sorted(resolved_vars.items()):
|
||||
if path[0] in ["run", "env", "resources_per_trial"]:
|
||||
@@ -96,6 +102,17 @@ def format_vars(resolved_vars):
|
||||
return ",".join(out)
|
||||
|
||||
|
||||
def flatten_resolved_vars(resolved_vars):
|
||||
"""Formats the resolved variable dict into a mapping of (str -> value)."""
|
||||
flattened_resolved_vars_dict = {}
|
||||
for pieces, value in resolved_vars.items():
|
||||
if pieces[0] == "config":
|
||||
pieces = pieces[1:]
|
||||
pieces = [str(piece) for piece in pieces]
|
||||
flattened_resolved_vars_dict["/".join(pieces)] = value
|
||||
return flattened_resolved_vars_dict
|
||||
|
||||
|
||||
def _clean_value(value):
|
||||
if isinstance(value, float):
|
||||
return "{:.5}".format(value)
|
||||
|
||||
Reference in New Issue
Block a user