Integrations
Weights & Biases
and
ZenML logo in purple, representing machine learning pipelines and MLOps framework.
Supercharge your ZenML pipelines with seamless Weights & Biases experiment tracking and visualization
Weights & Biases
All integrations

Weights & Biases

Supercharge your ZenML pipelines with seamless Weights & Biases experiment tracking and visualization
Add to ZenML
COMPARE
related resources
No items found.

Supercharge your ZenML pipelines with seamless Weights & Biases experiment tracking and visualization

Integrate Weights & Biases with ZenML to track, log, and visualize your pipeline experiments effortlessly. This powerful combination enables you to leverage Weights & Biases' interactive UI and collaborative features while managing your end-to-end ML workflows with ZenML's pipelines.

Features with ZenML

  • Seamlessly log models, parameters, and metrics from ZenML pipeline steps
  • Visualize and compare pipeline run results in the intuitive Weights & Biases UI
  • Share pipeline artifacts and performance with team members and stakeholders
  • Maintain experiment tracking continuity as you transition to MLOps best practices with ZenML

Main Features

  • Comprehensive experiment tracking and logging
  • Interactive visualization of models, datasets, and results
  • Collaboration features for sharing and discussing ML experiments
  • Integrations with popular ML frameworks and tools
  • Powerful querying and comparison of runs across projects

How to use ZenML with
Weights & Biases
from typing import Tuple
from zenml import pipeline, step
from zenml.client import Client
from zenml.integrations.wandb.flavors.wandb_experiment_tracker_flavor import (
    WandbExperimentTrackerSettings,
)
from transformers import (
    AutoModelForSequenceClassification,
    AutoTokenizer,
    Trainer,
    TrainingArguments,
    DistilBertForSequenceClassification,
)
from datasets import load_dataset, Dataset
import numpy as np
from sklearn.metrics import accuracy_score, precision_recall_fscore_support
import wandb

# Get the experiment tracker from the active stack
experiment_tracker = Client().active_stack.experiment_tracker


@step
def prepare_data() -> Tuple[Dataset, Dataset]:
    dataset = load_dataset("imdb")
    tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
    def tokenize_function(examples):
        return tokenizer(examples["text"], padding="max_length", truncation=True)
    tokenized_datasets = dataset.map(tokenize_function, batched=True)
    return (
        tokenized_datasets["train"].shuffle(seed=42).select(range(1000)),
        tokenized_datasets["test"].shuffle(seed=42).select(range(100)),
    )


@step(experiment_tracker=experiment_tracker.name)
def train_model(
    train_dataset: Dataset, eval_dataset: Dataset
) -> DistilBertForSequenceClassification:
    model = AutoModelForSequenceClassification.from_pretrained(
        "distilbert-base-uncased", num_labels=2
    )
    training_args = TrainingArguments(
        output_dir="./results",
        num_train_epochs=3,
        per_device_train_batch_size=16,
        per_device_eval_batch_size=16,
        report_to=["wandb"],
    )

    def compute_metrics(eval_pred):
        logits, labels = eval_pred
        predictions = np.argmax(logits, axis=-1)
        precision, recall, f1, _ = precision_recall_fscore_support(
            labels, predictions, average="binary"
        )
        acc = accuracy_score(labels, predictions)
        return {"accuracy": acc, "f1": f1, "precision": precision, "recall": recall}

    trainer = Trainer(
        model=model,
        args=training_args,
        train_dataset=train_dataset,
        eval_dataset=eval_dataset,
        compute_metrics=compute_metrics,
    )

    trainer.train()

    # Evaluate the model
    eval_results = trainer.evaluate()
    print(f"Evaluation results: {eval_results}")

    # Log final evaluation results
    wandb.log({"final_evaluation": eval_results})

    return model


@pipeline
def fine_tuning_pipeline():
    train_dataset, eval_dataset = prepare_data()
    model = train_model(train_dataset, eval_dataset)


if __name__ == "__main__":
    # Run the pipeline
    wandb_settings = WandbExperimentTrackerSettings(
        tags=["distilbert", "imdb", "sentiment-analysis"],
    )

    fine_tuning_pipeline.with_options(settings={"experiment_tracker": wandb_settings})()

This code snippet demonstrates how to enable Weights & Biases experiment tracking in a ZenML pipeline step using the @step decorator. Inside the step, the WandbCallback is used to log evaluation metrics during model training, and wandb.log is called to manually log a validation metric. The Weights & Biases experiment tracker is configured through the "wandb_tracker" stack component.

Additional Resources
Read the documentation
Read the full integration docs
Weights & Biases official documentation
End-to-end example: Using wandb with ZenML

Supercharge your ZenML pipelines with seamless Weights & Biases experiment tracking and visualization

Integrate Weights & Biases with ZenML to track, log, and visualize your pipeline experiments effortlessly. This powerful combination enables you to leverage Weights & Biases' interactive UI and collaborative features while managing your end-to-end ML workflows with ZenML's pipelines.
Weights & Biases

Start Your Free Trial Now

No new paradigms - Bring your own tools and infrastructure
No data leaves your servers, we only track metadata
Free trial included - no strings attached, cancel anytime
Dashboard displaying machine learning models, including versions, authors, and tags. Relevant to model monitoring and ML pipelines.

Connect Your ML Pipelines to a World of Tools

Expand your ML pipelines with Apache Airflow and other 50+ ZenML Integrations
Modal
Label Studio
Evidently
Hugging Face (Inference Endpoints)
Azure Container Registry
PyTorch
GitHub Container Registry
AWS
Deepchecks
PyTorch Lightning
Discord