Skip to main content

Overview

The bulk_log_metadata() function allows you to log metadata to multiple ZenML resources (steps, artifacts, models) in a single efficient call. This is useful when you need to attach the same metadata to multiple entities.

Signature

from zenml import bulk_log_metadata

def bulk_log_metadata(
    metadata: Dict[str, MetadataType],
    resources: List[RunMetadataResource],
) -> None:
    """Log metadata for multiple resources at once.
    
    Args:
        metadata: Dictionary of metadata key-value pairs to log
        resources: List of resources to attach metadata to
    """

Parameters

metadata
Dict[str, MetadataType]
required
Dictionary of metadata key-value pairs. Values can be:
  • Primitive types: str, int, float, bool
  • URI: Uri type for file/resource references
  • Structured data: dict, list
resources
List[RunMetadataResource]
required
List of ZenML resources to attach metadata to. Each resource specifies:
  • Resource type (step, artifact, model)
  • Resource identifier (ID or name)

Return Value

return
None
This function does not return a value. Metadata is logged to the ZenML server.

Usage Examples

Log Metadata to Multiple Artifacts

from zenml import bulk_log_metadata
from zenml.models import RunMetadataResource
from zenml.enums import MetadataResourceTypes

# Log experiment metadata to multiple artifacts
metadata = {
    "experiment_id": "exp-2024-001",
    "accuracy": 0.95,
    "framework": "pytorch"
}

resources = [
    RunMetadataResource(
        type=MetadataResourceTypes.ARTIFACT_VERSION,
        id="artifact-id-1"
    ),
    RunMetadataResource(
        type=MetadataResourceTypes.ARTIFACT_VERSION,
        id="artifact-id-2"
    ),
]

bulk_log_metadata(metadata=metadata, resources=resources)

Log Training Metadata to Step and Model

from zenml import bulk_log_metadata, get_step_context
from zenml.models import RunMetadataResource
from zenml.enums import MetadataResourceTypes

# Inside a step
context = get_step_context()

training_metadata = {
    "learning_rate": 0.001,
    "batch_size": 32,
    "epochs": 10,
    "optimizer": "adam"
}

# Log to both the current step and the model
resources = [
    RunMetadataResource(
        type=MetadataResourceTypes.STEP_RUN,
        id=context.step_run.id
    ),
    RunMetadataResource(
        type=MetadataResourceTypes.MODEL_VERSION,
        id=context.model.id
    ),
]

bulk_log_metadata(metadata=training_metadata, resources=resources)

When to Use

Use bulk_log_metadata When

  • Logging the same metadata to multiple resources
  • Attaching experiment metadata to all artifacts
  • Tagging multiple entities with common information
  • Optimizing metadata logging performance

Use log_metadata When

  • Logging to a single resource
  • Different metadata for each resource
  • Using convenience parameters (infer_model, etc.)
  • Simpler use cases

log_metadata

Log metadata to a single resource

log_artifact_metadata

Specialized function for artifact metadata

log_model_metadata

Specialized function for model metadata

log_step_metadata

Specialized function for step metadata

Notes

bulk_log_metadata() is more efficient than calling log_metadata() multiple times when you need to attach the same metadata to multiple resources.
All resources must exist in the ZenML database before logging metadata. Use valid IDs or identifiers for each resource.

Build docs developers (and LLMs) love