Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support trial name template #146

Merged
merged 4 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions siatune/tune/tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from siatune.codebase import build_task
from siatune.tune import (build_callback, build_scheduler, build_searcher,
build_space, build_stopper)
from .utils import NAME_CREATOR


class Tuner:
Expand Down Expand Up @@ -106,8 +107,10 @@ def __init__(
tune_config=TuneConfig(
search_alg=searcher,
scheduler=trial_scheduler,
trial_name_creator=lambda trial: trial.trial_id,
trial_dirname_creator=lambda trial: trial.experiment_tag,
trial_name_creator=NAME_CREATOR.get(
tune_cfg.pop('trial_name_creator', 'trial_id')),
trial_dirname_creator=NAME_CREATOR.get(
tune_cfg.pop('trial_dirname_creator', 'experiment_tag')),
**tune_cfg),
run_config=RunConfig(
name=self.experiment_name,
Expand Down
4 changes: 4 additions & 0 deletions siatune/tune/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) SI-Analytics. All rights reserved.
from .name_creator import NAME_CREATOR, experiment_tag, trial_id

__all__ = ['NAME_CREATOR', 'experiment_tag', 'trial_id']
15 changes: 15 additions & 0 deletions siatune/tune/utils/name_creator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) SI-Analytics. All rights reserved.
from mmengine.registry import Registry
from ray.tune.experiment import Trial

NAME_CREATOR = Registry('name creator')


@NAME_CREATOR.register_module()
def trial_id(trial: Trial) -> str:
return trial.trial_id


@NAME_CREATOR.register_module()
def experiment_tag(trial: Trial) -> str:
return trial.experiment_tag
28 changes: 28 additions & 0 deletions tests/test_tune/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import inspect
from unittest.mock import MagicMock

import pytest

from siatune.tune.utils import NAME_CREATOR


@pytest.fixture
def trial():
return MagicMock(
trainable_name='test',
trial_id='trial_id',
experiment_tag='experiment_tag')


def test_trial_id(trial):
tmpl = NAME_CREATOR.get('trial_id')
assert inspect.isfunction(tmpl)
assert tmpl.__name__ == 'trial_id'
assert tmpl(trial) == trial.trial_id


def test_experiment_tag(trial):
tmpl = NAME_CREATOR.get('experiment_tag')
assert inspect.isfunction(tmpl)
assert tmpl.__name__ == 'experiment_tag'
assert tmpl(trial) == trial.experiment_tag