Log to multiple objects at once#
To log to multiple runs or other Neptune objects in one script, you can initialize multiple objects. You can then log metadata to each object separately.
Why log to multiple runs at once?#
A common case for working with multiple simultaneous runs is logging each hyperparameter optimization trial as a separate run. For examples, see:
- Optuna integration guide
- Tracking hyperparameter optimization jobs (framework-agnostic)
Using different runs also helps organize the parameters and results of different methods called in the script.
Example#
In the following example, we create and log metadata to three separate runs.
import neptune
# Start 1st run
run1 = neptune.init_run(
project="common/quickstarts",
name="logging-to-multipe-runs",
tags=["multiple"],
)
run1["params"] = {"lr": 0.007}
# Start 2nd run
run2 = neptune.init_run(
project="common/quickstarts",
name="logging-to-multipe-runs",
tags=["multiple"],
)
run2["params"] = {"lr": 0.0034}
# Start 3rd run
run3 = neptune.init_run(
project="common/quickstarts",
name="logging-to-multipe-runs",
tags=["multiple"],
)
run3["params"] = {"lr": 0.005}
# Log metric to run1
for j in range(1, 101):
run1["train/loss"].append(0.7 / j**0.5)
# Log metric to run2
for j in range(1, 101):
run2["train/loss"].append(0.8 / j**0.5)
# Log metric to run3
for j in range(1, 101):
run3["train/loss"].append(0.9 / j**0.5)
# Stop tracking
run1.stop()
run2.stop()
run3.stop()