Skip to content
qgonDEV DOCSSDK 0.3.31
ENKR

qgon.hpo

In the appBuild › Hyperparameter search

Searches hyperparameters (HPO) by running clones of a finished base run with different parameter values.

import qgon
# the base run's training code logged the metric val/acc with run.log_metrics({"acc": acc}, step=ep, prefix="val")
opt = qgon.hpo.optimize(
base_run="<base run id>", # a finished base run (this script does not call qgon.init())
space=[qgon.hpo.log_uniform("lr", 1e-4, 1e-1),
qgon.hpo.choice("batch", [32, 64])],
objective="val/acc", mode="max",
max_runs=8, concurrency=2,
)
opt.wait()
print(opt.best().params, opt.best().value)
  • Each trial is a clone of the base run with only the parameters changed, and an agent on the GPU queue (default gpu) runs it.
  • The search controller runs inside this process (your workspace). When this process ends, the search stops too.
  • Use the parameter names you passed to run.params({...}). The internal section names are found automatically.
import qgon.hpo

uniform

function

A float between lo and hi; with step, only values on that grid (grid search needs step).

uniform(
name: str,
lo: float,
hi: float,
step: Optional[float] = None,
) -> _Param

In the app · Build › Hyperparameter search

log_uniform

function

A float between lo and hi drawn evenly on a log scale, for values that span orders of magnitude such as a learning rate (for example 1e-4 to 1e-1).

log_uniform(name: str, lo: float, hi: float) -> _Param

In the app · Build › Hyperparameter search

integer

function

An integer between lo and hi, hi included.

integer(name: str, lo: int, hi: int, step: int=1) -> _Param

In the app · Build › Hyperparameter search

choice

function

One of the given values.

choice(name: str, values: Sequence[Any]) -> _Param

In the app · Build › Hyperparameter search

optimize

functionchanged in 0.3.29

Starts a search and returns without waiting; call opt.wait() to wait for it.

optimize(
base_run: Union[str, Run, Task],
space: Sequence[_Param],
objective: str,
mode: str = 'max',
*,
queue: Optional[str] = None,
max_runs: Optional[int] = None,
concurrency: int = 2,
method: Union[str, type] = 'random',
name: Optional[str] = None,
project: Optional[str] = None,
use: str = 'last',
time_limit_min: Optional[float] = None,
run_time_limit_min: Optional[float] = None,
local: bool = False,
controller_queue: Optional[str] = None,
poll_seconds: float = 15,
**engine_kwargs: Any,
) -> Optimization
space
a list of uniform/log_uniform/integer/choice. Use the names you passed to run.params.
objective
the target metric, written as "graph/line". acc logged with run.log_metrics({"acc": acc}, step=ep, prefix="val") is "val/acc". A metric whose graph and line share one name (run.log("val_acc", ...)) or run.summary("val_acc", ...) can be given by the name alone, such as "val_acc".
mode
"max" (higher is better) or "min".
use
"last" (the last value, default) or "best" (the best value recorded).
queue
the queue for trials (default gpu; environment variable QGON_QUEUE).
max_runs
the maximum number of trials (default 10 for random and optuna; every combination for grid).
concurrency
how many trials run at once (default 2).
method
"random" (default), "grid" or "optuna" (when installed).
time_limit_min / run_time_limit_min
the time limit in minutes for the whole search / for one trial.
local
if True, trials also run one after another in this process without a queue (for testing).
controller_queue
runs the controller on an agent of this queue, for administrators (the services queue is admin-only). This process then ends here and the script runs again on the agent.
engine_kwargs
passed as they are to the engine (HyperParameterOptimizer).

In the app · Build › Hyperparameter search

A search that is running or has finished.

Optimization(
engine: HyperParameterOptimizer,
task: Optional[Task],
names: Dict[str, _Param],
objective: tuple,
mode: str,
extremum: bool,
own_task: bool,
)
MemberWhat it does
id -> Optional[str]Id of the search (controller) task, shown under this name on the hyperparameter search screen.
url -> Optional[str]Address of this search in the qgon web app; it opens this search on the hyperparameter search screen.
running -> boolTrue while the search is running.
wait(timeout: Optional[float]=None) -> boolWaits until the search ends (timeout in seconds), returns True if it ended and marks the search task completed; Ctrl-C while waiting stops the search, aborting running trials, and re-raises the exception.
stop() -> NoneStops the search; running trials are aborted.
top(n: int=5) -> List[Trial]Returns n completed trials ordered from the best objective value.
best() -> Optional[Trial]Returns the best trial, or None if no trial has completed.
engine -> HyperParameterOptimizerThe underlying engine optimizer object, for advanced use.

In the app · Build › Hyperparameter search

Trial

dataclass

The result of one trial.

Trial()
FieldTypeNotes
idstr-
paramsDict[str, Any]-
valueOptional[float]-
metricsDict[str, Any]-
MemberWhat it does
run -> RunThe trial's Run, for looking further at its metrics, artifacts and models.

In the app · Build › Hyperparameter search

Converts a search spec into optimize() arguments; unknown keys or invalid values raise ValueError with a readable message.

kwargs_from_spec(spec: dict) -> Dict[str, Any]

In the app · Build › Hyperparameter search