Skip to main content
The DeepChem library provides open source tools that democratize the use of deep learning in drug discovery, materials science, chemistry, and biology. This W&B integration adds experiment tracking and model checkpointing while training models with DeepChem. Use this page to add W&B logging to your DeepChem training workflow so that you can track training loss, evaluation metrics, and model checkpoints across experiments. If you already train models with DeepChem, you can add experiment tracking with minimal code changes.

DeepChem logging in 3 lines of code

logger = WandbLogger(…)
model = TorchModel(…, wandb_logger=logger)
model.fit(…)
Passing a WandbLogger instance into a DeepChem model attaches W&B logging to the training run, so metrics produced during fit automatically stream to your W&B project.
DeepChem molecular analysis

Report and Google Colab

The following resources show the integration in practice before you wire it into your own code:

Track experiments

The rest of this page explains how to set up an API key, install the wandb library, and enable logging for either a TorchModel or KerasModel. Set up W&B for DeepChem models of type KerasModel or TorchModel.

Sign up and create an API key

An API key authenticates your machine to W&B. You can generate an API key from your user profile.
For a more streamlined approach, go to User Settings and create an API key. Copy the API key immediately and save it in a secure location such as a password manager.
To find your API key in the W&B app:
  1. Click your user profile icon in the upper right corner.
  2. Select User Settings, then scroll to the API Keys section.

Install the wandb library and log in

To install the wandb library locally and log in:
  1. Set the WANDB_API_KEY environment variable to your API key. Replace values enclosed in <> with your own:
    export WANDB_API_KEY=<your_api_key>
    
  2. Install the wandb library and log in.
    pip install wandb
    
    wandb login
    

Log your training and evaluation data to W&B

With wandb installed and authenticated, you can now attach a WandbLogger to your DeepChem model so that training and evaluation data flow to W&B. Training loss and evaluation metrics log to W&B automatically. To enable optional evaluation, use the DeepChem ValidationCallback. The WandbLogger detects the ValidationCallback and logs the metrics it produces.
from deepchem.models import TorchModel, ValidationCallback

vc = ValidationCallback(…)  # optional
model = TorchModel(…, wandb_logger=logger)
model.fit(…, callbacks=[vc])
logger.finish()
After model.fit runs, training loss and any evaluation metrics emitted by the ValidationCallback appear in your W&B project under the run created by WandbLogger.