Skip to content

Commit 1d319cd

Browse files
authored
Fix hpo converter (#3940)
* save best hp after hpo * add test
1 parent d43226e commit 1d319cd

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

src/otx/engine/hpo/hpo_api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from __future__ import annotations
77

88
import dataclasses
9+
import json
910
import logging
1011
import time
1112
from functools import partial
@@ -128,6 +129,10 @@ def execute_hpo(
128129
hpo_algo.print_result()
129130
_remove_unused_model_weights(hpo_workdir, best_hpo_weight)
130131

132+
if best_config is not None:
133+
with (hpo_workdir / "best_hp.json").open("w") as f:
134+
json.dump(best_config, f)
135+
131136
return best_config, best_hpo_weight
132137

133138

src/otx/tools/converter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ def convert(config_path: str, task: OTXTaskType | None = None) -> dict:
202202
task_info["task"] = task
203203
default_config = ConfigConverter._get_default_config(task_info)
204204
ConfigConverter._update_params(default_config, param_dict)
205+
if (hpo_time_ratio := template_config.get("hpo_parameters", {}).get("hpo_time_ratio")) is not None:
206+
default_config["hpo_config.expected_time_ratio"] = hpo_time_ratio
205207
ConfigConverter._remove_unused_key(default_config)
206208
return default_config
207209

tests/unit/engine/hpo/test_hpo_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def test_execute_hpo(
148148

149149
# check hpo workdir exists
150150
assert (engine_work_dir / "hpo").exists()
151+
assert (engine_work_dir / "hpo" / "best_hp.json").exists()
151152
# check a case where progress_update_callback exists
152153
mock_thread.assert_called_once()
153154
assert mock_thread.call_args.kwargs["target"] == _update_hpo_progress

0 commit comments

Comments
 (0)