Skip to content
qgonDEV DOCSSDK 0.3.31
ENKR

Track experiments

In the appBuild › ExperimentsExamples checked on SDK 0.3.29

Add a few lines to your training code to record hyperparameters, metrics and models as an experiment. After reading this page you can find your runs in Build › Experiments, compare several runs, and download tables for a paper. It also covers how to turn on recording without changing your code.

The SDK (import qgon and the qgon command) is already installed in workspaces and in the training job environment. Use the examples below in a workspace terminal or notebook.

Calling qgon.init() creates a run and starts recording. One run is one row on the Experiments page. Use the returned Run to record more values.

import qgon
run = qgon.init(project="vision", name="resnet18-lr1e-3", tags=["baseline"])
cfg = run.params({"lr": 1e-3, "epochs": 10, "batch": 64})

Values passed to run.params() are saved as the experiment's settings. When you re-run with changed values from the UI, or a hyperparameter search changes them, the new values come back through cfg. So read values such as cfg["lr"] instead of hard-coding numbers.

If you leave out project, the run goes to the Default project. Calling qgon.init() inside a run sent to a queue does not create a new run. It keeps recording to that run. To close a run in a notebook and start a new one, call run.finish().

run.log_metrics() records several metrics at once. With prefix, the metrics become lines on one graph. The metric name is then prefix/key.

for ep in range(cfg["epochs"]):
tl = train_one_epoch(model, opt)
vl, acc = evaluate(model)
run.log_metrics({"loss": tl}, step=ep, prefix="train") # train/loss
run.log_metrics({"loss": vl, "acc": acc}, step=ep, prefix="val") # val/loss, val/acc

step is the x axis of the graph. Pass the epoch or iteration number. Without prefix, each key gets its own graph and keeps its name as is.

To record a single metric, use run.log("val", acc, step=ep, series="acc"). The name is the same val/acc.

Use the same name everywhere else. A hyperparameter search takes it as objective="val/acc" (Hyperparameter search). The run comparison table and exports also pick it as val/acc.

run.summary("best_val_acc", best_acc) # one final value
run.log_confusion("confusion", cm, labels=class_names, step=ep) # confusion matrix (x predicted, y true)
run.log_image("predictions", grid, step=ep, caption="first val batch") # numpy array or PIL image
run.log_table("per-class", [["class", "precision", "recall"],
["cat", 0.91, 0.88],
["dog", 0.87, 0.90]])
run.text("data: shapes version 3") # a note in the log

run.summary() records one value, not a curve. It shows up in the experiment summary and in the run comparison table. Use it for the best score or the test score at the end of training.

Confusion matrices, images and tables do not appear in the Graphs tab of the experiment details. Open them with Advanced view of this run at the top of the detail panel.

torch.save(model.state_dict(), "best.pt")
model_id = run.save_model("best.pt", name="resnet18-best", tags=["vision"])
run.save("eval", {"best_val_acc": best_acc, "test_acc": test_acc})

run.save_model() uploads the file to the model store and returns the model id. The model appears in Deploy › Models and is linked as this run's output model. With publish=True it is published as it is uploaded. run.save() uploads a result file. It takes a file path, a dict, a numpy array or a pandas table.

A run sent to a queue runs in a job container. Files written inside the container disappear when the run ends, so upload what you need with the two methods above. To save training state and resume later, use checkpoints instead of save_model.

After qgon.init(), the following is recorded even if you add no logging lines.

Recorded Where to look
Console output (print, logging), error tracebacks Log tab
Command-line arguments (argparse, click) Settings in the Summary tab
Git repository, commit, whether there are uncommitted changes Summary tab
GPU, CPU and memory utilization Graphs tab
TensorBoard scalars Graphs tab
matplotlib figures Advanced view of this run
Model saves by frameworks, such as torch.save Files · models tab

Some items may not be recorded, depending on the framework and its version. Record values you must keep with the methods above. To turn automatic recording off, start with qgon.init(auto_log=False). This turns off both framework hooks and command-line argument recording.

qgon run runs a script in the current workspace and calls qgon.init() for you right before the script starts. Even with no qgon lines in your training code, command-line arguments, console output, model saves and GPU utilization are recorded.

qgon run --project vision --name baseline python train.py --lr 0.01
qgon run --project vision train.py --lr 0.01 # you can leave out python
qgon run --project vision -m mypkg.train --lr 0.01 # run a module

Put options before the script. Options after it are passed to the script as arguments. If you leave out --name, the script name is used. Calling qgon.init() again inside the script keeps recording to the same run.

This command runs on the current workspace's CPU and GPU. To send it to the server's GPU queue, add --queue. See Run training on the GPU queue.

Build › Experiments shows one row per run. Each row has the name, the settings whose values differ within this list (up to 4), the best value of the main metric, and the status. Failed runs get a short reason. Hyperparameter searches and pipelines collapse into one controller row. Expand it to see trials and steps sorted by metric.

You pick the main metric per project. When you choose a metric and its direction (higher or lower is better), the choice is saved for your view only. Other people's views stay the same. If you do not choose, it is guessed from the name. Names with acc, f1 or auc are treated as higher is better. Names with loss, error or rmse are treated as lower is better.

At the top, filter by project, Mine, status and period (the last 7 days at first), and search by name, description and tags. When a project is selected, the search also covers parameter values. Sort by Recent or Best metric.

Click an experiment to open the detail tabs on the right.

  • Summary: the main metric and its rank within the project, the last and best value of every metric, settings, and the image, queue, code commit and dataset versions used. Failed runs also show the last console lines.
  • Graphs: pick metrics to see their curves. Save each graph as PNG or SVG.
  • Log: the console. New lines follow while the run is running. You can search and download it as .txt.
  • Files · models: result files and input and output models.
  • Checkpoints: see Checkpoints and resume.
Experiments list with training curves in the detail panel on the right
The tabs at the top of the right panel are the ones listed above. The picture shows the Summary tab.View full size(opens in a new tab)

Pick 2 to 20 runs and gather setting differences, metric summaries, training curves and run environments on one screen. Download tables and figures as files you can put straight into a paper or report.

  1. In Build › Experiments, check the runs to compare. Runs from different projects can be mixed.

  2. Click Compare in the selection bar at the bottom. You can also open a comparison from runs picked in the Scheduling Recently finished tab, or from the top trials of a hyperparameter search.

  3. On the comparison screen, choose the metrics for the table and download the files you need.

The comparison screen is always in English, whatever the UI language. This keeps tables and figures ready for papers without edits. It has three parts.

  • Summary: settings that differ between runs come first and identical settings after. Each metric shows its last and best value, and the best across runs.
  • Graphs: training curves of the chosen metrics, overlaid per run. Save each graph as PNG or SVG.
  • Environment: container image, queue, code commit and dataset versions side by side, with differences marked.

The direction of the best value is guessed from the metric name. Metrics whose direction the name does not tell, such as lr, get no best value. If you set the direction yourself, it is underlined and exports use it too.

Export Result
CSV A table that opens directly in Excel. Text cells starting with =, +, - or @ get a leading ' so they are not read as formulas
LaTeX A booktabs table. 4 significant digits, best values in bold. If names contain Korean, you need a package such as kotex
Markdown A table for a README or wiki
Report (HTML) One HTML file with tables, graphs and environment, with no external files
Print / PDF Opens the browser print dialog

By default the table file has columns for parameters that differ between runs (up to 12) and the last and best values of metrics (up to 6).

Run comparison screen with the Summary table and Graphs curves
Run chips are at the top, the Summary table is in the middle and the Graphs curves are below. Export is the button at the top right.View full size(opens in a new tab)

To get the same table from a script, call the export API. See REST API for how to get a token.

BASE="http://<server address>:<web port>"
curl -sS -H "Authorization: Bearer $TOKEN" \
"$BASE/qgon-api/compare/export?ids=<run id>,<run id>&format=latex&metric=val/acc&direction=val/acc:high" \
-o table.tex

format is one of csv, latex and md. You can repeat metric and param (section/name).

Comparison only reads, with your own login. Runs that were deleted or that you cannot see are listed as excluded, and the table is built from the rest. If you build too many in a short time, you are asked to wait a moment.

Which dataset versions a run read and which models it produced is linked from the records automatically. You do not need to write anything extra, but the records only exist in these cases.

  • A dataset loaded in code with qgon.dataset("name", version="…") is recorded as an input of that run. Reading the mounted folder or a file path directly leaves no record.
  • A dataset chosen on the New run screen is also recorded as an input.
  • A model uploaded with run.save_model() or saved by a framework is recorded as an output.

Click Full lineage in the Summary tab of an experiment, or select one experiment in the list and click Lineage, to open the graph. Lineage is drawn from the existing records. If a run's recorded settings are edited, the graph changes too, so do not use it as a fixed record for audits. See Datasets for how to read the graph.