Hyperparameter search
Run the same training many times with different values, such as the learning rate or batch size, and find the combination with the best target metric. After reading this page you can start a search from the UI or from code, read the results, and retrain with the winning combination.
How a search runs
Section titled “How a search runs”A search uses one finished run as its base run. qgon clones the base run, changes only the values you chose, and puts the clone on the GPU queue. Each of these clones is a trial. The code and environment stay the same as the base run. Only the parameter values differ.
The job that queues trials one after another and collects their results is the controller. When you start from the UI, the controller runs inside the workspace you pick, under your account. When you start from code, the process that runs the code is the controller. Either way, the search stops when the controller stops.
Prepare the base run
Section titled “Prepare the base run”The base run must have run to the end (completed or stopped). It must also have recorded the values to search and the target metric. Values are recorded when you pass them to run.params or take them as argparse arguments.
import qgon
run = qgon.init(project="image-cls", name="resnet18-base")cfg = run.params({"lr": 1e-3, "batch": 64, "epochs": 10}) # each trial gets its values back here
for ep in range(cfg["epochs"]): ... # train and validate with cfg["lr"], cfg["batch"] run.log_metrics({"loss": vl, "acc": acc}, step=ep, prefix="val") # val/loss, val/accA trial runs this script again with new values. So the code must read its values from cfg, the value that run.params returns. If you hard-code the numbers, every trial runs with the same values.
With prefix="val", acc becomes the series acc in the graph val, and the search refers to it as val/acc. Log metrics every epoch. Then the results can use the best value during training, and Bayesian optimization can spot hopeless trials early. See Track experiments for logging.
Start a search from the UI
Section titled “Start a search from the UI”Press New search at the top of Build › Hyperparameter search. A five-step form opens.
-
Base run. Find a completed run by name or id and pick it. Runs that were HPO trials or pipeline steps are hidden from the list.
-
Search parameters. Turn on the parameters to vary and set a range type and range for each. Parameters you leave off keep the base run's value. The first ranges are guesses from the base values, so check and adjust them.
-
Goal. Pick one objective metric, a direction (Higher is better or Lower is better) and an aggregation (Final value or Best value). The final value is the last value logged. The best value is the best value seen during training.
-
Method and budget. Set the method, total trials, concurrent trials, the overall time limit in minutes and the per-trial limit in minutes.
-
Where it runs. Pick the trial queue and the controller workspace, then press Start search. The search page opens once the controller is up.
Pick a range type that fits the value.
| Range type | Good for |
|---|---|
| Continuous range | A real number inside a range, such as dropout |
| Log-scale range | Values that change by orders of magnitude, such as the learning rate (e.g. 0.0001 ~ 0.1) |
| Integer range | Whole numbers, such as the number of layers |
| List of values | Values separated by commas, such as 32, 64, adam |
There are three methods.
| Method | What it does |
|---|---|
| Random search | Samples evenly inside the ranges. Total trials default to 10. |
| Grid search | Runs every combination in turn. Continuous ranges need a step, and log-scale ranges are not allowed. |
| Bayesian optimization (Optuna) | Picks the next values from finished trials and stops hopeless trials early. |
Bayesian optimization and early stopping
Section titled “Bayesian optimization and early stopping”Bayesian optimization uses the results of earlier trials to choose what to try next. It watches the objective metric logged during training and stops a hopeless trial before it ends. That trial shows as stopped in the results. The first 10 or so trials are random, so plan for 20 or more trials to see the benefit.
This method needs Optuna installed in the controller workspace. If it is missing, the form tells you. Run pip install optuna in that workspace's terminal (this needs an internet connection) and press Check again.
Concurrent trials
Section titled “Concurrent trials”Concurrent trials is how many trials go on the queue at once. The UI default is 1. The upper limit is the smaller of the number of agents on the trial queue and the server limit the administrator set.
Controller workspace
Section titled “Controller workspace”The controller workspace must be on and must have finished Set up access. If the qgon SDK in that workspace is too old, the form asks you to update it. Keep the workspace on until the search ends. Turning it off stops the search. The controller log goes to files under ~/.qgon/hpo/ in that workspace, one per start time.
Stop and search again
Section titled “Stop and search again”Press Stop search in the header of the search page to stop the search and its running trials. Only the person who created the search and administrators can stop it. Each person can have two searches started from the UI in progress at a time by default. Search again opens a new search form with the same base run.
Search from code
Section titled “Search from code”Call qgon.hpo.optimize from a notebook or terminal in a workspace. Keep the search code separate from the base run script. Calling optimize in a process that already called qgon.init() is refused.
import qgon # do not call qgon.init() in this script
opt = qgon.hpo.optimize( base_run="<base run id>", space=[ qgon.hpo.log_uniform("lr", 1e-4, 1e-1), qgon.hpo.choice("batch", [32, 64, 128]), ], objective="val/acc", mode="max", method="random", max_runs=12, concurrency=1,)opt.wait() # wait until the search ends
best = opt.best()print(best.params, best.value)for t in opt.top(3): print(t.id, t.params, t.value)Agents on the GPU queue run the trials. The process running this script is the controller. If the script ends without opt.wait(), or you press Ctrl-C while waiting, the search stops and running trials are stopped too. Start long searches with tmux or nohup so they keep running after you close the terminal.
Search space
Section titled “Search space”| Function | Values |
|---|---|
qgon.hpo.uniform(name, lo, hi, step=None) |
A real number from lo to hi. Grid search needs step. |
qgon.hpo.log_uniform(name, lo, hi) |
A real number from lo to hi on a log scale. Not allowed in grid search. |
qgon.hpo.integer(name, lo, hi, step=1) |
An integer from lo to hi (hi included) |
qgon.hpo.choice(name, values) |
One value from the list |
Use the same name you passed to run.params or the argparse argument name. If the base run has no such name, the call stops and lists the names it has. If the same name exists in two sections, include the section, as in "Args/lr".
Main arguments
Section titled “Main arguments”| Argument | Meaning |
|---|---|
base_run |
Base run id or a Run |
objective |
Objective metric in "graph/series" form (e.g. "val/acc"). For a value logged with run.summary("best_acc", …), use "best_acc". |
mode |
"max" (higher is better) or "min" |
use |
"last" (last value, default) or "best" (best value during training) |
method |
"random" (default), "grid" or "optuna" (when Optuna is installed) |
max_runs |
Total trials. Defaults to 10 for random and optuna, and to every combination for grid. |
concurrency |
Concurrent trials. The code default is 2. Set it to 1 on a server where trials share GPU memory. |
queue |
Queue for the trials. Defaults to gpu. |
time_limit_min · run_time_limit_min |
Overall time limit and per-trial time limit, in minutes |
name · project |
Search name and project. If empty, the base run name plus a search suffix, and the base run's project. |
local |
If True, runs trials one by one in this process without the queue (for testing). |
Get the results
Section titled “Get the results”optimize returns an Optimization right away without waiting.
| Name | What it does |
|---|---|
opt.wait(timeout=None) |
Waits until the search ends. timeout is in seconds. Returns True if the search ended. |
opt.running |
True while the search is still running |
opt.stop() |
Stops the search. Running trials are stopped too. |
opt.top(n=5) |
The n completed trials with the best objective, best first |
opt.best() |
The best trial, or None if no trial has completed |
opt.id |
Id of the search (controller) run |
top and best return Trial objects. A trial holds id, the changed values in params, the objective value in value and other metrics in metrics. t.run gives that trial's Run. See the qgon.hpo reference for full signatures.
Run from a spec file
Section titled “Run from a spec file”qgon hpo --spec starts a search from a JSON spec and acts as the controller until the search ends. Start search in the UI runs this same command inside the controller workspace.
{ "base_run": "<base run id>", "objective": "val/acc", "mode": "max", "use": "best", "method": "optuna", "space": [ {"name": "lr", "type": "log_uniform", "min": 0.0001, "max": 0.1}, {"name": "batch", "type": "choice", "values": [32, 64, 128]} ], "max_runs": 20, "concurrency": 1}qgon hpo --spec hpo-spec.jsonThe spec keys match the optimize arguments. Each space item has a type of uniform, log_uniform, integer or choice. Write ranges with min, max and step, and lists with values. With --json, the command writes one JSON line to standard output when it starts and another when it ends. Press Ctrl-C, or Stop search in the UI, to stop it.
Read the results
Section titled “Read the results”Pick a search in the list on the left of Build › Hyperparameter search. The results read from the top: summary, best combination, results by parameter, ranking and results by combination. The top three blocks are enough to see the outcome, the winning combination and how each value did.

The Summary line shows the objective value of the best trial and how it compares with the base run (better or worse than the base run). It also shows finished trials, the counts of running, queued and failed trials, the elapsed time and the method.
Best combination shows the parameters that varied in large type. Values that stayed the same in every trial appear small next to it, marked fixed. From this line you can open Experiment details or Retrain with these. If that trial saved a model, Model appears too.
By parameter has one row per parameter. When there are only a few candidate values, bars compare the best metric among trials that used each value. Continuous ranges plot each trial as a dot. The bar lengths alone show which value did better.
Ranking lists trials by the objective. Click a row to open that trial's experiment details. You can also pick a few top trials and see them side by side in the run comparison page.
Results by combination is a scatter plot. Choose what goes on the X axis, the Y axis and the color, and each trial appears as a dot. The best point is marked, and failed trials use an × shape. When values span 20 times or more, the axis switches to a log scale.
In Build › Experiments a search is folded into one controller row. Expand it to see the trials sorted by metric.
Retrain with these
Section titled “Retrain with these”Retrain with these clones the chosen trial into a new run with the same code and settings and puts it on the queue the search used. If the queue is unknown, it only creates a draft. In that case, queue it yourself from the experiments page. The new run stays as a child of the original trial, so it does not mix into the search results.
Publish and load the model the retraining saves in Models.