Skip to main content
By default, W&B only saves the latest git commit hash. You can turn on more code features to compare the code between your experiments dynamically in the UI. Starting with wandb version 0.8.28, W&B can save the code from your main training file where you call wandb.init().

Save library code

When you enable code saving, W&B saves the code from the file that called wandb.init(). To save additional library code, you have three options:

Call wandb.Run.log_code(".") after calling wandb.init()

import wandb

with wandb.init() as run:
  run.log_code(".")

Pass a settings object to wandb.init() with code_dir set

import wandb

wandb.init(settings=wandb.Settings(code_dir="."))
This captures all python source code files in the current directory and all subdirectories as an artifact. For more control over the types and locations of source code files that are saved, see the reference docs.

Set code saving in the UI

In addition to setting code saving programmatically, you can also toggle this feature in your W&B account Settings. Note that this will enable code saving for all teams associated with your account.
By default, W&B disables code saving for all teams.
  1. Log in to your W&B account.
  2. Navigate to Settings > Privacy.
  3. Under Project and content security, toggle Disable default code saving on.

Code comparer

Compare code used in different W&B runs:
  1. Select the Add panels button in the top right corner of the page.
  2. Expand TEXT AND CODE dropdown and select Code.
Code comparer panel

View unstaged changes

View unstaged changes in your project workspace.
  1. Navigate to your project’s workspace.
  2. Select the Files tab.
  3. From the list of files, click on the diff.patch file.
  4. Select a file from the list to expand the diff of unstaged changes for that file.
W&B supports two modes to view the diff of unstaged or unpushed changes across runs: unified and split.
  • Unified view shows the diff of unstaged changes in a single pane:
    Diff patch unified view
  • Split view shows the diff of unstaged changes in two panes side by side:
    Diff patch split view
Toggle between the two views by selecting either the Unified or Split buttons in the upper right corner of the diff view, below the Download button.

Jupyter session history

W&B saves the history of code executed in your Jupyter notebook session. When you call wandb.init() inside of Jupyter, W&B adds a hook to automatically save a Jupyter notebook containing the history of code executed in your current session.
  1. Navigate to your project’s workspace that contains your code.
  2. Select the Artifacts tab in the project sidebar.
  3. Expand the code artifact.
  4. Select the Files tab.
Jupyter session history
This displays the cells that were run in your session along with any outputs created by calling iPython’s display method. This enables you to see exactly what code was run within Jupyter in a given run. When possible W&B also saves the most recent version of the notebook which you would find in the code directory as well.
Jupyter session output