Skip to content
SynthGraph

SDK guides

Training runs and metrics

Record a training run, move it through its lifecycle, and log metrics step by step.

A training run records one model training: what model and framework, with what configuration, on which data, and how its metrics moved.

The examples on this page share this setup:

from synthgraph import SynthGraph

sg = SynthGraph()
experiment = sg.project("Docs: training runs").experiment("example")
generation = experiment.generation(generator="blender", generator_version="4.2", seed=1)
dataset = generation.dataset(name="train_set", uri="s3://lab-bucket/train_set")

Record a training run#

training = experiment.training(
    model="yolo",
    framework="pytorch",
    dataset=dataset,
    config={"epochs": 50, "batch_size": 32, "learning_rate": 0.001},
)
ArgumentMeaning
modelThe model's name. Required.
framework, framework_versionThe training framework and its version.
configYour configuration, any JSON object.
dataset, datasets, generationsWhat the run used. See Link data to results.
name, description, metadataA name, free text, and any extra JSON.
metric_directionsDeclare which way is better for your metrics. See Declare metric directions.
capture_environmentTurn off the default capture of environment details.

The lifecycle is yours to call#

A training run is not started or finished for you. Call the steps yourself:

training.start()
# ... train ...
training.complete()   # or training.fail() if it broke

Like a generation, a training run moves forward only, and completed and failed are final. If you never call start() and complete(), the run stays pending and the dashboard treats it that way.

Log metrics#

training = experiment.training(model="yolo", framework="pytorch", dataset=dataset)
training.start()

for step in range(1, 6):
    training.log_metric(step=step, metrics={"loss": 1.0 / step})

training.complete()
  • step must be an integer. A float such as 1.5 is rejected before any request is sent.
  • metrics is a dictionary of names to values. Use numbers for anything you want charted.
  • Metric names are yours. Names with a slash, such as train/loss, are kept as written.

Read them back:

for point in training.metrics():
    print(point.step, point.metrics)

How often to log#

Every log_metric call is one HTTP request, and an API key is limited to about 120 requests a minute. Logging every step of a fast training loop will hit that limit, and the SDK then raises SynthGraphRateLimitError. Log at a sensible interval: every N steps, or once per epoch.

Reading back is limited to 100 points#

training.metrics() returns the first page the backend sends, which is at most 100 points ordered by step. A run with more points than that still has them all stored, but this call will not return them all.

Record what the run scored with training.evaluation(...).