pip install wandbPython 3.10+ and pydantic ≥ 2.6 since 0.27.0.pip install wandb[media]Extra codecs for logging video, audio and 3D objects.wandb loginInteractive. Stores the key in~/.netrc, so you never do it again on that box.wandb.login(key=..., relogin=True)From inside Python.relogin=Trueforces a fresh key over a cached one.export WANDB_API_KEY=...The right way in CI and containers — no interactive prompt, no netrc.wandb login --host https://wandb.acme.comPoint at a self-hosted or dedicated W&B Server instead of the public cloud.wandb login --verifyConfirms the stored credentials actually work before a long job starts.
wandb sync ./wandb/offline-run-...Uploads a run recorded offline. The whole point of offline mode.wandb offline · wandb onlineFlips the default mode for every subsequent run in this directory.wandb sweep sweep.yamlRegisters the sweep and prints the sweep ID you feed to agents.wandb agent entity/project/SWEEP_IDStarts a worker. Run it on as many machines as you like — they coordinate through the controller.wandb artifact put ./data -n dataset -t datasetUpload an artifact without writing any Python.wandb artifact cache cleanup 1GBThe local artifact cache grows without bound. This is the fix when the disk fills.wandb leetGA 0.28.0Terminal dashboard for live runs. Waswandb beta leetbefore 0.28.0.wandb status · wandb verifyShow current settings; check connectivity to the host.
WANDB_API_KEYAuthentication without an interactive login.WANDB_PROJECT · WANDB_ENTITYDefaults forinit(), so the same script works across teams unchanged.WANDB_MODE=offline|disabledofflinerecords to disk for later sync;disabledturns every call into a no-op — ideal for unit tests.WANDB_RUN_IDSet it yourself to make a job resumable after a pre-emption.WANDB_NAME · WANDB_NOTES · WANDB_TAGSDisplay name, free-text notes, comma-separated tags.WANDB_RUN_GROUPGroups distributed workers or CV folds into one logical experiment.WANDB_DIRWhere the localwandb/folder goes. Point it at scratch on a cluster.WANDB_CACHE_DIR · WANDB_DATA_DIRArtifact cache and staging locations — the two that fill up shared home directories.WANDB_SILENT=trueSuppresses the banner and progress output in notebooks and logs.WANDB_DISABLE_CODE=trueStops code and git state being saved, for when the repo cannot leave the building.SINGULARITYENV_* / APPTAINERENV_*Prefix to pass any of the above through into a Singularity/Apptainer container.
with wandb.init(project="p") as run:The recommended form. Flushes and closes on exit — and marks the run failed if the block raises.run = wandb.init(...) # ... run.finish()Manual form. You must callfinish()yourself, or the run sits "running" forever.run.log({"acc": 0.9})Log on the object, not the module. This is the single biggest change from older tutorials.run.finish(exit_code=1)Mark a run failed deliberately — useful in your own exception handler.wandb.setup()Call once in the parent before forking, so multiple processes share one service.# run names cannot contain / \ # ? % :These break the URL. Same restriction applies to artifact names.
project="my-project", entity="my-team"Where the run lands. Entity defaults to your personal account.config={"lr": 3e-4}The inputs. Everything you would want to group or filter by later belongs here.name="resnet-baseline", notes="..."Human label and free text. Omitnameand W&B invents a memorable one.tags=["baseline", "v2"]Filterable labels. Cheaper to reorganise later than project names.mode="online"|"offline"|"disabled"|"shared"sharedlets several processes write to one run — the distributed-training option.id=..., resume="allow"The resumable pair. See card 07.group=..., job_type="train"Two-level organisation for runs that belong together.save_code=TrueSnapshots the main script and git state so a result stays reproducible.sync_tensorboard=TrueMirrors existing TensorBoard writes into W&B without touching your training code.dir=..., settings=wandb.Settings(...)Local output directory, and the escape hatch for everything else.reinit="create_new"Multiple concurrent runs in one process. Replaces the old booleanreinit=True.
run.id · run.name · run.project · run.entityIdentity.run.idis what you keep to resume later.run.urlLink to the run page. Wasrun.get_url()in older code.run.config · run.summaryBoth read/write dict-likes. Config is the input, summary the headline result.run.stepThe current history step. Read-only, monotonic.run.resumedTrueif thisinit()picked up an existing run — branch your warm-start logic on it.run.tags += ("new-tag",)Tags are a tuple. Concatenate; you cannotappend.run.alert(title=..., text=..., level="WARN")Sends email/Slack. Perfect for a NaN loss guard on a long job.run.save("out/*.txt", policy="live")Sync matching files as they change. Policies:live,now,end.run.log_code()Explicitly snapshot source whensave_codewas off.run.mark_preempting()Tells W&B a spot instance is going away, so the run is requeued rather than marked crashed.run.write_logs(text)0.27.0Push arbitrary text into the run's log stream.run.pin_config_keys(["lr", "arch"])0.26.0Pins those keys to the front of the runs table in the UI.
wandb.init(id=rid, resume="allow")Resume: continue the same run, appending to its history. Needs the original id.resume="must"|"allow"|"never"musterrors if the run is missing,nevererrors if it exists.mustis the safe choice for pre-emptible jobs.wandb.init(fork_from=f"{rid}?_step=200")Fork: a brand-new run branching off an existing one at a step. The original is untouched.wandb.init(resume_from=f"{rid}?_step=200")Rewind: same run id, history truncated back to that step. Use it to erase a diverged tail.run.mark_preempting() + resume="must"The standard spot-instance pattern: signal on the way out, resume on the way back in.# step can never go backwardsWhich is exactly why rewind exists — you cannot simply re-log an earlier step.
wandb.init(group="cv-fold-sweep")Collapses related runs into one row that expands. The fix for cross-validation clutter.wandb.init(job_type="eval")Second axis within a group:preprocess,train,eval.wandb.init(tags=["ablation"])Cross-cutting labels that survive reorganisation.wandb.init(group=os.environ["SLURM_JOB_ID"])Ties every worker of one cluster job together automatically.if rank == 0: run = wandb.init(...)Simplest distributed pattern: only rank 0 logs. The alternative ismode="shared"from every rank.run.pin_config_keys(["lr"])Makes the columns you actually compare visible by default.