Call wandb.init() at the top of your script to start a new run
Call wandb.init() once at the beginning of your script to initialize a new job. This creates a new run in W&B and launches a background process to sync data.
View the reference docs for this function, generated from the wandb Python library.
#|hide
import wandb
If you're trying to start multiple runs from one script, add two things to your code:
#|output: false
#|eval: false
import wandb
for x in range(2):
run = wandb.init(reinit=True)
for y in range (25):
wandb.log({"metric": x+y})
run.finish()
wandb: Currently logged in as: hamelsmu (github-wandb). Use `wandb login --relogin` to force relogin
/Users/hamel/wandb-nbdev/docs/wandb/run-20220819_091814-34hsdgyi
VBox(children=(Label(value='0.000 MB of 0.000 MB uploaded (0.000 MB deduped)\r'), FloatProgress(value=1.0, max…
| metric | ▁▁▂▂▂▂▃▃▃▄▄▄▅▅▅▅▆▆▆▇▇▇▇██ |
| metric | 24 |
./wandb/run-20220819_091814-34hsdgyi/logs
/Users/hamel/wandb-nbdev/docs/wandb/run-20220819_091840-hiugxi6j
VBox(children=(Label(value='0.000 MB of 0.000 MB uploaded (0.000 MB deduped)\r'), FloatProgress(value=1.0, max…
| metric | ▁▁▂▂▂▂▃▃▃▄▄▄▅▅▅▅▆▆▆▇▇▇▇██ |
| metric | 25 |
./wandb/run-20220819_091840-hiugxi6j/logs
Alternatively you can use a python context manager which will automatically finish logging:
#|output: false
#|eval: false
import wandb
for x in range(2):
run = wandb.init(reinit=True)
with run:
for y in range(25):
run.log({"metric": x+y})
/Users/hamel/wandb-nbdev/docs/wandb/run-20220819_091906-1pwi8bd5
VBox(children=(Label(value='0.000 MB of 0.000 MB uploaded (0.000 MB deduped)\r'), FloatProgress(value=1.0, max…
| metric | ▁▁▂▂▂▂▃▃▃▄▄▄▅▅▅▅▆▆▆▇▇▇▇██ |
| metric | 24 |
./wandb/run-20220819_091906-1pwi8bd5/logs
/Users/hamel/wandb-nbdev/docs/wandb/run-20220819_091931-2wterg8o
VBox(children=(Label(value='0.000 MB of 0.000 MB uploaded (0.000 MB deduped)\r'), FloatProgress(value=1.0, max…
| metric | ▁▁▂▂▂▂▃▃▃▄▄▄▅▅▅▅▆▆▆▇▇▇▇██ |
| metric | 25 |
./wandb/run-20220819_091931-2wterg8o/logs
This error indicates that the library is having difficulty launching the process which synchronizes data to the server. The following workarounds can help resolve the issue in certain environments:
::: {.panel-tabset}
#|eval: false
#|output: false
wandb.init(settings=wandb.Settings(start_method="fork"))
/Users/hamel/wandb-nbdev/docs/wandb/run-20220819_091958-yvnab4te
For versions prior to 0.13.0 we suggest using:
#|eval: false
#|output: false
wandb.init(settings=wandb.Settings(start_method="thread"))
VBox(children=(Label(value='0.000 MB of 0.000 MB uploaded (0.000 MB deduped)\r'), FloatProgress(value=1.0, max…
./wandb/run-20220819_091958-yvnab4te/logs
/Users/hamel/wandb-nbdev/docs/wandb/run-20220819_092005-wfzidwwi
#|output: false
import wandb
wandb.init();
run_name = wandb.run.name
VBox(children=(Label(value='0.001 MB of 0.001 MB uploaded (0.000 MB deduped)\r'), FloatProgress(value=1.0, max…
./wandb/run-20220819_092102-ir6w5g66/logs
/Users/hamel/wandb-nbdev/docs/wandb/run-20220819_092935-3udt6k6p
print(run_name)
sweet-sun-46
If you'd like to overwrite the run name (like snowy-owl-10) with the run ID (like qvlp96vk) you can use this snippet:
#| output: false
import wandb
wandb.init();
wandb.run.name = wandb.run.id
wandb.run.save()
VBox(children=(Label(value='0.000 MB of 0.000 MB uploaded (0.000 MB deduped)\r'), FloatProgress(value=1.0, max…
./wandb/run-20220819_092952-1bbzqokp/logs
/Users/hamel/wandb-nbdev/docs/wandb/run-20220819_093015-16ej8478
True
print(wandb.run.name)
16ej8478
By default, wandb.init starts a process that syncs metrics in real time to our cloud hosted app. If your machine is offline, you don't have internet access, or you just want to hold off on the upload, here's how to run wandb in offline mode and sync later. You'll need to set two environment variables.
WANDB_API_KEY=$KEY, where $KEY is the API Key from your settings pageWANDB_MODE="offline"And here's a sample of what this would look like in your script:
#|echo: false
%pycat offline.py
import wandb import os os.environ["WANDB_MODE"] = "offline" config = { "dataset": "CIFAR10", "machine": "offline cluster", "model": "CNN", "learning_rate": 0.01, "batch_size": 128, } wandb.init(project="offline-demo") for i in range(100): wandb.log({"accuracy": i})
#|hide
!rm -rf wandb
Here's a sample terminal output:
%%bash
python offline.py
wandb: Tracking run with wandb version 0.13.1 wandb: W&B syncing is set to `offline` in this directory. wandb: Run `wandb online` or set WANDB_MODE=online to enable cloud syncing. wandb: Waiting for W&B process to finish... (success). wandb: wandb: wandb: Run history: wandb: accuracy ▁▁▁▁▂▂▂▂▂▃▃▃▃▃▃▄▄▄▄▄▅▅▅▅▅▅▆▆▆▆▆▇▇▇▇▇▇███ wandb: wandb: Run summary: wandb: accuracy 99 wandb: wandb: You can sync this run to the cloud by running: wandb: wandb sync /Users/hamel/wandb-nbdev/docs/wandb/offline-run-20220819_111619-1kj5i84c wandb: Find logs at: ./wandb/offline-run-20220819_111619-1kj5i84c/logs
And once you're ready, just run a sync command to send that folder to the cloud with the following command:
wandb sync wandb/dryrun-folder-name
#|eval: false
!wandb sync wandb/latest-run
Find logs at: /Users/hamel/wandb-nbdev/docs/wandb/debug-cli.hamel.log Syncing: https://wandb.ai/github-wandb/offline-demo/runs/1kj5i84c ... done.