TraceML
TraceML is the client-side engine for ML/Data tracking, visualization, dashboards, and model UI, designed specifically for integration with the Polyaxon MLOps platform. It allows users to log metrics, parameters, artifacts, and manage experiment runs programmatically. The current version is 1.3.0, and it maintains a relatively frequent release cadence, often aligning with Polyaxon platform updates.
Common errors
-
ModuleNotFoundError: No module named 'traceml'
cause The `traceml` library is not installed in the current Python environment.fix`pip install traceml` -
polyaxon.exceptions.PolyaxonClientException: Unauthorized. Invalid token or credentials.
cause The client is unable to authenticate with the Polyaxon API. This is usually due to a missing, expired, or incorrect authentication token or improperly configured Polyaxon CLI.fixSet the `POLYAXON_TOKEN` environment variable with a valid API token or configure your Polyaxon CLI (`polyaxon login`) and ensure it's accessible by the `traceml` client. -
requests.exceptions.ConnectionError: ('Connection refused', ...)cause The `traceml` client cannot reach the Polyaxon API server. This could be due to the server being down, an incorrect host configuration, or network issues preventing access.fixVerify that your Polyaxon server is running and accessible from your machine. Check the `POLYAXON_HOST` environment variable or your Polyaxon CLI configuration (`polyaxon config show`) to ensure the correct host and port are used.
Warnings
- gotcha Tracking data not appearing in the Polyaxon UI or being incomplete.
- gotcha Confusion between `traceml.tracking.run` and `traceml.client.PolyaxonClient` for experiment tracking.
- gotcha Issues with authentication or connecting to the Polyaxon backend.
Install
-
pip install traceml
Imports
- run
from traceml.tracking import run
- PolyaxonClient
from traceml.client import PolyaxonClient
- V1ArtifactKind
from traceml.artifacts import V1ArtifactKind
Quickstart
import os
from traceml.tracking import run
from traceml.artifacts import V1ArtifactKind
# Ensure Polyaxon is configured. For remote tracking, POLYAXON_TOKEN env var must be set
# or ~/.polyaxon/config.yaml configured. For this quickstart to run standalone
# without a Polyaxon server, 'is_offline=True' is used.
# Log a simple metric and declare a model artifact
with run.start(
project="quickstart-traceml",
name="my-first-experiment",
tags=["python", "demo"],
is_offline=True # Set to False to track to a Polyaxon server
) as r:
print(f"Started run with UUID: {r.uuid}")
r.log_metric("accuracy", 0.925)
r.log_param("learning_rate", 0.001)
# Log an artifact type. The actual model file would be uploaded later.
r.log_outputs(model=V1ArtifactKind.MODEL)
print("Logged metric, param, and model artifact kind.")
print("Run finished.")