AGKhalil / wandb_tutorial

An example repo for running wandb with PyTorch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Installation

conda create -n wandb_tutorial python==3.8
conda activate wandb_tutorial
pip install -r requirements.txt

Quick usage

  1. Create a wandb account through this link.

  2. Go into your chosen example directory

cd coin_toss

or

cd CNN-MNIST
  1. Edit the train.py script: replace ENTITY by your wandb username.
wandb.init(
    entity="ENTITY",
    project="wandb_tutorial",
    config=args,
    save_code=True,
)
  1. Run the train.py script with default or your chosen arguments. coin_toss example:
python train.py --prob 0.75

Use wandb in 5 easy steps

  1. Create a wandb account.
  2. Install wandb commandline tool.
pip install wandb
  1. Import wandb
import wandb
  1. Initialize wandb, replacing ENTITY with your wandb account username.
wandb.init(
    entity="ENTITY",
    project="wandb_tutorial",
    config=args,
    save_code=True,
)
  1. Log to wandb
wandb.log(
    {
        "train/loss": loss,
    }
)

FAQs

How do I keep track of my model gradients?

wandb.watch(model)

What if I'm already logging to tensorboard?

wandb can automatically log your tensorboard metrics. All you need to do is add the sync_tensorboard flag to the wandb initialization. Example:

wandb.init(
    entity="ENTITY",
    project="wandb_tutorial",
    config=args,
    save_code=True,
    sync_tensorboard=True,
)

What if I run wandb in a notebook?

Everything will work nicely but you need to add wandb.finish() at the very bottom of your notebook (after you're done with training/evaluation.)

Will wandb work with my code? wandb is framework agnostic. You can add it yourself as we demonstrate in this tutorial or rely on wandb integrations.

For instance, to use wandb with HuggingFace, you need only do:

from transformers import TrainingArguments, Trainer

args = TrainingArguments(... , report_to="wandb")
trainer = Trainer(... , args=args)

About

An example repo for running wandb with PyTorch


Languages

Language:Python 100.0%