"...git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "3f43d824b909ec92cde5311e9be016767c0fb11b"
Unverified Commit 7417f3ac authored by Wang, Yi's avatar Wang, Yi Committed by GitHub
Browse files

[HPO] update to sigopt new experiment api (#18147)

* [HPO] update to sigopt new experiment api
* follow https://docs.sigopt.com/experiments

Signed-off-by: default avatarWang, Yi A <yi.a.wang@intel.com>

* [HPO] use new API if sigopt version >= 8.0.0
Signed-off-by: default avatarWang, Yi A <yi.a.wang@intel.com>
parent 8c14b342
...@@ -305,41 +305,69 @@ def run_hp_search_ray(trainer, n_trials: int, direction: str, **kwargs) -> BestR ...@@ -305,41 +305,69 @@ def run_hp_search_ray(trainer, n_trials: int, direction: str, **kwargs) -> BestR
def run_hp_search_sigopt(trainer, n_trials: int, direction: str, **kwargs) -> BestRun: def run_hp_search_sigopt(trainer, n_trials: int, direction: str, **kwargs) -> BestRun:
import sigopt
from transformers.utils.versions import importlib_metadata
if importlib_metadata.version("sigopt") >= "8.0.0":
sigopt.set_project("huggingface")
experiment = sigopt.create_experiment(
name="huggingface-tune",
type="offline",
parameters=trainer.hp_space(None),
metrics=[dict(name="objective", objective=direction, strategy="optimize")],
parallel_bandwidth=1,
budget=n_trials,
)
from sigopt import Connection logger.info(f"created experiment: https://app.sigopt.com/experiment/{experiment.id}")
conn = Connection() for run in experiment.loop():
proxies = kwargs.pop("proxies", None) with run:
if proxies is not None: trainer.objective = None
conn.set_proxies(proxies) trainer.train(resume_from_checkpoint=None, trial=run.run)
# If there hasn't been any evaluation during the training loop.
experiment = conn.experiments().create( if getattr(trainer, "objective", None) is None:
name="huggingface-tune", metrics = trainer.evaluate()
parameters=trainer.hp_space(None), trainer.objective = trainer.compute_objective(metrics)
metrics=[dict(name="objective", objective=direction, strategy="optimize")], run.log_metric("objective", trainer.objective)
parallel_bandwidth=1,
observation_budget=n_trials, best = list(experiment.get_best_runs())[0]
project="huggingface", best_run = BestRun(best.id, best.values["objective"].value, best.assignments)
) else:
logger.info(f"created experiment: https://app.sigopt.com/experiment/{experiment.id}") from sigopt import Connection
while experiment.progress.observation_count < experiment.observation_budget: conn = Connection()
suggestion = conn.experiments(experiment.id).suggestions().create() proxies = kwargs.pop("proxies", None)
trainer.objective = None if proxies is not None:
trainer.train(resume_from_checkpoint=None, trial=suggestion) conn.set_proxies(proxies)
# If there hasn't been any evaluation during the training loop.
if getattr(trainer, "objective", None) is None: experiment = conn.experiments().create(
metrics = trainer.evaluate() name="huggingface-tune",
trainer.objective = trainer.compute_objective(metrics) parameters=trainer.hp_space(None),
metrics=[dict(name="objective", objective=direction, strategy="optimize")],
values = [dict(name="objective", value=trainer.objective)] parallel_bandwidth=1,
obs = conn.experiments(experiment.id).observations().create(suggestion=suggestion.id, values=values) observation_budget=n_trials,
logger.info(f"[suggestion_id, observation_id]: [{suggestion.id}, {obs.id}]") project="huggingface",
experiment = conn.experiments(experiment.id).fetch() )
logger.info(f"created experiment: https://app.sigopt.com/experiment/{experiment.id}")
best = list(conn.experiments(experiment.id).best_assignments().fetch().iterate_pages())[0]
best_run = BestRun(best.id, best.value, best.assignments) while experiment.progress.observation_count < experiment.observation_budget:
suggestion = conn.experiments(experiment.id).suggestions().create()
trainer.objective = None
trainer.train(resume_from_checkpoint=None, trial=suggestion)
# If there hasn't been any evaluation during the training loop.
if getattr(trainer, "objective", None) is None:
metrics = trainer.evaluate()
trainer.objective = trainer.compute_objective(metrics)
values = [dict(name="objective", value=trainer.objective)]
obs = conn.experiments(experiment.id).observations().create(suggestion=suggestion.id, values=values)
logger.info(f"[suggestion_id, observation_id]: [{suggestion.id}, {obs.id}]")
experiment = conn.experiments(experiment.id).fetch()
best = list(conn.experiments(experiment.id).best_assignments().fetch().iterate_pages())[0]
best_run = BestRun(best.id, best.value, best.assignments)
return best_run return best_run
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment