For the complete documentation index, see llms.txt. This page is also available as Markdown.

Weights & Biases

Logging and visualizing experiments with Weights & Biases.

The Weights & Biases Experiment Tracker is an Experiment Tracker flavor provided with the Weights & Biases ZenML integration that uses the Weights & Biases experiment tracking platform to log and visualize information from your pipeline steps (e.g. models, parameters, metrics).

When would you want to use it?

Weights & Biases is a very popular platform that you would normally use in the iterative ML experimentation phase to track and visualize experiment results. That doesn't mean that it cannot be repurposed to track and visualize the results produced by your automated pipeline runs, as you make the transition towards a more production-oriented workflow.

You should use the Weights & Biases Experiment Tracker:

  • if you have already been using Weights & Biases to track experiment results for your project and would like to continue doing so as you are incorporating MLOps workflows and best practices in your project through ZenML.

  • if you are looking for a more visually interactive way of navigating the results produced from your ZenML pipeline runs (e.g. models, metrics, datasets)

  • if you would like to connect ZenML to Weights & Biases to share the artifacts and metrics logged by your pipelines with your team, organization, or external stakeholders

You should consider one of the other Experiment Tracker flavors if you have never worked with Weights & Biases before and would rather use another experiment tracking tool that you are more familiar with.

How do you deploy it?

The Weights & Biases Experiment Tracker flavor is provided by the W&B ZenML integration, you need to install it on your local machine to be able to register a Weights & Biases Experiment Tracker and add it to your stack:

zenml integration install wandb -y

The Weights & Biases Experiment Tracker needs to be configured with the credentials required to connect to the Weights & Biases platform using one of the available authentication methods.

Authentication Methods

You need to configure the following credentials for authentication to the Weights & Biases platform:

  • api_key: Mandatory API key token of your Weights & Biases account.

  • project_name: The name of the project where you're sending the new run. If the project is not specified, the run is put in an "Uncategorized" project.

  • entity: An entity is a username or team name where you're sending runs. This entity must exist before you can send runs there, so make sure to create your account or team in the UI before starting to log runs. If you don't specify an entity, the run will be sent to your default entity, which is usually your username.

This option configures the credentials for the Weights & Biases platform directly as stack component attributes.

For more, up-to-date information on the Weights & Biases Experiment Tracker implementation and its configuration, you can have a look at the SDK docs .

How do you use it?

To be able to log information from a ZenML pipeline step using the Weights & Biases Experiment Tracker component in the active stack, you need to enable an experiment tracker using the @step decorator. Then use Weights & Biases logging or auto-logging capabilities as you would normally do, e.g.:

Instead of hardcoding an experiment tracker name, you can also use the Client to dynamically use the experiment tracker of your active stack:

Weights & Biases UI

Weights & Biases comes with a web-based UI that you can use to find further details about your tracked experiments.

Every ZenML step that uses Weights & Biases should create a separate experiment run which you can inspect in the Weights & Biases UI:

WandB UI

You can find the URL of the Weights & Biases experiment linked to a specific ZenML run via the metadata of the step in which the experiment tracker was used:

Or on the ZenML dashboard as metadata of a step that uses the tracker:

WandB UI

Alternatively, you can see an overview of all experiment runs at https://wandb.ai/{ENTITY_NAME}/{PROJECT_NAME}/runs/.

The naming convention of each Weights & Biases experiment run is {pipeline_run_name}_{step_name} (e.g. wandb_example_pipeline-25_Apr_22-20_06_33_535737_tf_evaluator). By default, ZenML groups W&B runs by the ZenML pipeline run name, adds human-readable tags (zenml, the pipeline name, and the pipeline run name), and stores durable ZenML identifiers in the W&B config.

Additional configuration

For additional configuration of the Weights & Biases experiment tracker, you can pass WandbExperimentTrackerSettings to overwrite the wandb.Settings or pass additional tags for your runs:

ZenML disables W&B SDK console output by default with settings equivalent to wandb.Settings(console="off", silent=True). W&B writes normal status and progress messages to stderr and uses carriage returns to redraw progress output. ZenML log stores preserve stderr as error-level logs, which can create confusing entries and trigger error-based log alerts even when W&B is working correctly. Metrics logged with wandb.log(...) are still sent to W&B. To show W&B SDK console output again, override these settings:

If you enable W&B SDK console output again, expect W&B login, sync, and progress messages to appear in ZenML step logs. Some of these messages may be stored as error-level logs because they are emitted through stderr by the W&B SDK.

ZenML manages common wandb.init(...) fields for you. In addition to the W&B entity and project configured on the stack component, WandbExperimentTrackerSettings supports:

ZenML truncates W&B tags to 64 characters and removes duplicates after truncation, so long tags with the same first 64 characters collapse into one W&B tag.

When ZenML metadata is enabled, W&B config receives flat keys such as zenml_pipeline_name, zenml_pipeline_run_name, zenml_pipeline_run_id, zenml_step_name, zenml_latest_step_run_id, and zenml_latest_step_run_version. ZenML dashboard links are added when they can be derived from the active server. These values are written to W&B config, not W&B summary, so metric summaries stay focused on experiment results.

To use W&B in a minimal mode without ZenML-added grouping, tags, or config, disable metadata:

By default, ZenML leaves W&B run IDs unset (run_id_strategy="wandb_generated"), preserving W&B-generated IDs. The supported run_id_strategy values are:

Strategy
Behavior

wandb_generated

Let W&B generate the run ID.

reuse_on_retry

Use one deterministic W&B run ID for each ZenML pipeline-step invocation, so retries for the same invocation resume the same W&B run.

new_on_retry

Use one deterministic W&B run ID for each ZenML step-run attempt, including retries.

For example, this configuration keeps retries for the same ZenML step invocation attached to the same W&B run:

If you prefer one W&B run for every ZenML step-run attempt, including retries, use:

When run_id_strategy="new_on_retry" is used without an explicit run_name, ZenML appends the ZenML step-run version to the W&B display name so retry attempts are easier to distinguish in the W&B UI.

ZenML defaults resume to allow whenever it passes a deterministic or explicit W&B run ID.

Advanced users can attach logging to an existing W&B run, or pass unmanaged W&B initialization fields through init_kwargs:

ZenML validates conflicts early:

  • run_id cannot be combined with a non-default run_id_strategy.

  • resume="never" cannot be combined with run_id_strategy="reuse_on_retry", because retries intentionally reuse the same W&B run ID.

  • resume="must" requires either an explicit run_id or a deterministic run_id_strategy.

  • run_config cannot contain zenml_* keys, which are reserved for ZenML metadata.

  • init_kwargs cannot override ZenML-managed wandb.init(...) keys such as entity, project, name, id, resume, group, job_type, tags, config, or settings.

Using Weights & Biases Weave

Weights & Biases Weave is a customizable dashboard interface that allows you to visualize and interact with your machine learning models, data, and results. ZenML provides built-in support for Weave through the WandbExperimentTrackerSettings.

Enabling and Disabling Weave

You can enable or disable Weave for specific steps in your pipeline by configuring the enable_weave parameter in the WandbExperimentTrackerSettings (or setting it when registering the experiment tracker component):

Using Weave with ZenML Steps

To use Weave with your ZenML steps, you need to:

  1. Configure your WandbExperimentTrackerSettings with enable_weave=True

  2. Apply the @weave.op() decorator to your step function

  3. Configure your step to use the Weights & Biases experiment tracker with your Weave settings

Here's an example:

To explicitly disable Weave for specific steps, while keeping the ability to use the @weave.op() decorator:

Weave Initialization Behavior

When using Weave with ZenML, there are a few important behaviors to understand:

  1. If enable_weave=True and a project_name is specified in your W&B experiment tracker, Weave will be initialized with that project name.

  2. If enable_weave=True but no project_name is specified, Weave initialization will be skipped.

  3. If enable_weave=False and a project_name is specified (explicit disabling), Weave will be disabled with settings={"disabled": True}.

  4. If enable_weave=False and no project_name is specified, Weave disabling will be skipped.

For more information about Weights & Biases Weave and its capabilities, visit the Weave documentation.

Full Code Example

This section shows an end to end run with the ZenML W&B integration.

Example without Weave
Example with Weave for LLM Tracing

Check out the SDK docs for a full list of available attributes and this docs page for more information on how to specify settings.

ZenML Scarf

Last updated

Was this helpful?