ClearML
ClearML is an open-source MLOps platform that provides auto-magical experiment management, version control for data and models, and MLOps capabilities for AI workflows. It helps track, compare, and reproduce machine learning experiments. The library sees active development with frequent patch releases (multiple per month) and regular minor/major version updates, with the current version being 2.1.5.
Warnings
- breaking ClearML v2.1.0 and later removed support for Python versions lower than 3.6. Additionally, work-in-progress to drop Python 2 support was mentioned in v2.1.4, consolidating to Python 3.6+ as the minimum requirement.
- breaking For users self-hosting ClearML Server, upgrading to ClearML Server v2.0.0 or later requires a MongoDB major version upgrade from v5.x to v6.x. If your server is older than v1.17, an intermediate upgrade to v1.17 is necessary before proceeding to v2.0.0. This affects the backend infrastructure rather than the client library directly, but is crucial for compatibility.
- gotcha It is highly recommended to call `Task.init()` at the very beginning of your script's execution, ideally right after `if __name__ == "__main__:".` Delaying `Task.init()` can lead to missed automatic logging (e.g., from PyTorch, TensorFlow, Matplotlib, Tensorboard), memory leaks, or hanging child processes.
- gotcha The `output_uri` parameter in `Task.init()` defaults to `None` or `False`. If not explicitly set to a storage location (e.g., `'s3://your-bucket/clearml-models'`), models registered by the task will NOT be automatically uploaded to ClearML's backend storage, although their metadata will be logged.
- gotcha Calling methods like `Task.force_requirements_env_freeze()` or `Task.force_store_standalone_script()` after `Task.init()` can lead to unexpected behavior and might trigger warnings. These methods are intended for pre-initialization configuration.
Install
-
pip install clearml
Imports
- Task
from clearml import Task
- Dataset
from clearml import Dataset
Quickstart
import os
from clearml import Task
# Set ClearML credentials (replace with your actual keys or configure via `clearml-init` CLI)
os.environ['CLEARML_WEB_HOST'] = os.environ.get('CLEARML_WEB_HOST', 'https://app.clear.ml')
os.environ['CLEARML_API_HOST'] = os.environ.get('CLEARML_API_HOST', 'https://api.clear.ml')
os.environ['CLEARML_FILES_HOST'] = os.environ.get('CLEARML_FILES_HOST', 'https://files.clear.ml')
os.environ['CLEARML_API_ACCESS_KEY'] = os.environ.get('CLEARML_API_ACCESS_KEY', 'YOUR_ACCESS_KEY')
os.environ['CLEARML_API_SECRET_KEY'] = os.environ.get('CLEARML_API_SECRET_KEY', 'YOUR_SECRET_KEY')
# Initialize a ClearML Task (experiment)
task = Task.init(project_name='My Project', task_name='My First ClearML Task')
print(f"ClearML Task initialized: {task.name}")
# Log a simple metric
logger = task.get_logger()
for i in range(10):
logger.report_scalar(series="loss", value=10 - i, iteration=i)
# Simulate some work
import time
time.sleep(2)
# Close the task (optional, often handled automatically on script exit)
task.close()
print("Task completed and closed.")