2021-05-13 23:48:51 +00:00
---
title: First Steps
---
:::note
2022-01-19 12:37:16 +00:00
This tutorial assumes that you've already [signed up ](https://app.clear.ml ) to ClearML
2021-05-13 23:48:51 +00:00
:::
2023-11-14 16:51:45 +00:00
ClearML provides tools for **automation** , **orchestration** , and **tracking** , all key in performing effective MLOps and LLMOps.
2021-05-13 23:48:51 +00:00
2023-11-14 16:51:45 +00:00
Effective MLOps and LLMOps rely on the ability to scale work beyond one's own computer. Moving from your own machine can be time-consuming.
2021-11-30 10:11:49 +00:00
Even assuming that you have all the drivers and applications installed, you still need to manage multiple python environments
for different packages / package versions, or worse - manage different Dockers for different package versions.
2021-10-04 09:20:50 +00:00
2021-11-30 10:11:49 +00:00
Not to mention, when working on remote machines, executing experiments, tracking what's running where, and making sure machines
are fully utilized at all times become daunting tasks.
2021-10-04 09:20:50 +00:00
2021-11-30 10:11:49 +00:00
This can create overhead that derails you from your core work!
2021-05-13 23:48:51 +00:00
2025-02-09 17:35:03 +00:00
ClearML Agent was designed to deal with such issues and more! It is a tool responsible for executing tasks on remote machines: on-premises or in the cloud! ClearML Agent provides the means to reproduce and track tasks in your
2021-11-30 10:11:49 +00:00
machine of choice through the ClearML WebApp with no need for additional code.
2021-10-04 09:20:50 +00:00
2024-04-24 07:48:14 +00:00
The agent will set up the environment for a specific Task's execution (inside a Docker, or bare-metal), install the
2023-11-23 13:04:17 +00:00
required python packages, and execute and monitor the process.
2021-05-13 23:48:51 +00:00
2021-11-30 10:11:49 +00:00
## Set up an Agent
2021-05-13 23:48:51 +00:00
2024-02-15 13:28:26 +00:00
1. Install the agent:
2021-05-13 23:48:51 +00:00
2021-11-30 10:11:49 +00:00
```bash
pip install clearml-agent
```
2021-05-13 23:48:51 +00:00
2022-01-19 12:37:16 +00:00
1. Connect the agent to the server by [creating credentials ](https://app.clear.ml/settings/workspace-configuration ), then run this:
2021-05-13 23:48:51 +00:00
2021-11-30 10:11:49 +00:00
```bash
clearml-agent init
```
2021-05-13 23:48:51 +00:00
2021-11-30 10:11:49 +00:00
:::note
If you've already created credentials, you can copy-paste the default agent section from [here ](https://github.com/allegroai/clearml-agent/blob/master/docs/clearml.conf#L15 ) (this is optional. If the section is not provided the default values will be used)
:::
2024-02-15 13:28:26 +00:00
1. Start the agent's daemon and assign it to a [queue ](../../fundamentals/agents_and_queues.md#what-is-a-queue ):
2021-11-30 10:11:49 +00:00
```bash
clearml-agent daemon --queue default
```
A queue is an ordered list of Tasks that are scheduled for execution. The agent will pull Tasks from its assigned
queue (`default` in this case), and execute them one after the other. Multiple agents can listen to the same queue
(or even multiple queues), but only a single agent will pull a Task to be executed.
2021-05-13 23:48:51 +00:00
2022-10-06 12:25:16 +00:00
:::tip Agent Deployment Modes
2024-09-10 13:06:11 +00:00
ClearML Agents can be deployed in:
2025-02-09 17:35:03 +00:00
* [Virtual environment mode ](../../clearml_agent/clearml_agent_execution_env.md ): Agent creates a new venv to execute a task.
* [Docker mode ](../../clearml_agent/clearml_agent_execution_env.md#docker-mode ): Agent executes a task inside a
2024-09-10 13:06:11 +00:00
Docker container.
For more information, see [Running Modes ](../../fundamentals/agents_and_queues.md#running-modes ).
2022-10-06 12:25:16 +00:00
:::
2021-05-13 23:48:51 +00:00
2025-02-09 17:35:03 +00:00
## Clone a Task
Tasks can be reproduced (cloned) for validation or as a baseline for further experimentation.
2024-04-24 07:48:14 +00:00
Cloning a task duplicates the task's configuration, but not its outputs.
2021-10-04 09:20:50 +00:00
2025-02-09 17:35:03 +00:00
**To clone a task in the ClearML WebApp:**
1. Click on any project card to open its [task table ](../../webapp/webapp_exp_table.md ).
1. Right-click one of the tasks on the table.
1. Click **Clone** in the context menu, which will open a **CLONE TASK** window.
2021-11-30 10:11:49 +00:00
1. Click **CLONE** in the window.
2021-05-13 23:48:51 +00:00
2025-02-09 17:35:03 +00:00
The newly cloned task will appear and its info panel will slide open. The cloned task is in draft mode, so
2021-11-30 10:11:49 +00:00
it can be modified. You can edit the Git / code references, control the python packages to be installed, specify the
2025-02-09 17:35:03 +00:00
Docker container image to be used, or change the hyperparameters and configuration files. See [Modifying Tasks ](../../webapp/webapp_exp_tuning.md#modifying-tasks ) for more information about editing tasks in the UI.
2021-05-13 23:48:51 +00:00
2025-02-09 17:35:03 +00:00
## Enqueue a Task
Once you have set up a task, it is now time to execute it.
2021-11-30 10:11:49 +00:00
2025-02-09 17:35:03 +00:00
**To execute a task through the ClearML WebApp:**
1. Right-click your draft task (the context menu is also available through the < img src = "/docs/latest/icons/ico-bars-menu.svg" alt = "Menu" className = "icon size-md space-sm" />
button on the top right of the task's info panel)
1. Click **ENQUEUE,** which will open the **ENQUEUE TASK** window
2021-11-30 10:11:49 +00:00
1. In the window, select `default` in the queue menu
1. Click **ENQUEUE**
2025-02-09 17:35:03 +00:00
This action pushes the task into the `default` queue. The task's status becomes *Pending* until an agent
assigned to the queue fetches it, at which time the task's status becomes *Running* . The agent executes the
task, and the task can be [tracked and its results visualized ](../../webapp/webapp_exp_track_visual.md ).
2021-11-30 10:11:49 +00:00
## Programmatic Interface
The cloning, modifying, and enqueuing actions described above can also be performed programmatically.
2021-05-13 23:48:51 +00:00
2021-12-05 09:29:59 +00:00
### First Steps
2025-02-09 17:35:03 +00:00
#### Access Previously Executed Tasks
2021-11-30 10:11:49 +00:00
All Tasks in the system can be accessed through their unique Task ID, or based on their properties using the [`Task.get_task` ](../../references/sdk/task.md#taskget_task )
method. For example:
2021-05-13 23:48:51 +00:00
```python
from clearml import Task
2024-01-10 12:40:19 +00:00
2021-05-13 23:48:51 +00:00
executed_task = Task.get_task(task_id='aabbcc')
```
2021-11-30 10:11:49 +00:00
Once a specific Task object has been obtained, it can be cloned, modified, and more. See [Advanced Usage ](#advanced-usage ).
2021-10-04 09:20:50 +00:00
2025-02-09 17:35:03 +00:00
#### Clone a Task
2021-05-13 23:48:51 +00:00
2025-02-09 17:35:03 +00:00
To duplicate a task, use the [`Task.clone` ](../../references/sdk/task.md#taskclone ) method, and input either a
2024-04-24 07:48:14 +00:00
Task object or the Task's ID as the `source_task` argument.
2021-11-30 10:11:49 +00:00
```python
cloned_task = Task.clone(source_task=executed_task)
```
2025-02-09 17:35:03 +00:00
#### Enqueue a Task
2021-11-30 10:11:49 +00:00
To enqueue the task, use the [`Task.enqueue` ](../../references/sdk/task.md#taskenqueue ) method, and input the Task object
with the `task` argument, and the queue to push the task into with `queue_name` .
```python
Task.enqueue(task=cloned_task, queue_name='default')
```
### Advanced Usage
2022-01-18 11:23:47 +00:00
Before execution, use a variety of programmatic methods to manipulate a task object.
2021-05-13 23:48:51 +00:00
2021-11-30 10:11:49 +00:00
#### Modify Hyperparameters
[Hyperparameters ](../../fundamentals/hyperparameters.md ) are an integral part of Machine Learning code as they let you
control the code without directly modifying it. Hyperparameters can be added from anywhere in your code, and ClearML supports multiple ways to obtain them!
2025-02-09 17:35:03 +00:00
Users can programmatically change cloned tasks' parameters.
2021-10-04 09:20:50 +00:00
2021-05-13 23:48:51 +00:00
For example:
```python
from clearml import Task
2024-01-10 12:40:19 +00:00
2021-05-13 23:48:51 +00:00
cloned_task = Task.clone(task_id='aabbcc')
cloned_task.set_parameter(name='internal/magic', value=42)
```
2021-11-30 10:11:49 +00:00
#### Report Artifacts
2022-05-18 08:49:31 +00:00
Artifacts are files created by your task. Users can upload [multiple types of data ](../../clearml_sdk/task_sdk.md#logging-artifacts ),
2021-11-30 10:11:49 +00:00
objects and files to a task anywhere from code.
2021-05-13 23:48:51 +00:00
```python
import numpy as np
from clearml import Task
2024-01-10 12:40:19 +00:00
2021-05-13 23:48:51 +00:00
Task.current_task().upload_artifact(name='a_file', artifact_object='local_file.bin')
Task.current_task().upload_artifact(name='numpy', artifact_object=np.ones(4,4))
```
2022-05-18 08:49:31 +00:00
Artifacts serve as a great way to pass and reuse data between tasks. Artifacts can be [retrieved ](../../clearml_sdk/task_sdk.md#using-artifacts )
2021-11-30 10:11:49 +00:00
by accessing the Task that created them. These artifacts can be modified and uploaded to other tasks.
2021-05-13 23:48:51 +00:00
```python
from clearml import Task
2024-01-10 12:40:19 +00:00
2021-05-13 23:48:51 +00:00
executed_task = Task.get_task(task_id='aabbcc')
# artifact as a file
local_file = executed_task.artifacts['file'].get_local_copy()
# artifact as object
a_numpy = executed_task.artifacts['numpy'].get()
```
2021-11-30 10:11:49 +00:00
By facilitating the communication of complex objects between tasks, artifacts serve as the foundation of ClearML's [Data Management ](../../clearml_data/clearml_data.md )
2022-04-26 10:42:55 +00:00
and [pipeline ](../../pipelines/pipelines.md ) solutions.
2021-11-30 10:11:49 +00:00
#### Log Models
Logging models into the model repository is the easiest way to integrate the development process directly with production.
2023-01-23 13:04:24 +00:00
Any model stored by a supported framework (Keras / TensorFlow / PyTorch / Joblib etc.) will be automatically logged into ClearML.
2021-10-04 09:20:50 +00:00
2023-02-16 10:17:53 +00:00
ClearML also supports methods to explicitly log models. Models can be automatically stored on a preferred storage medium
2024-09-10 13:06:11 +00:00
(S3 bucket, Google storage, etc.).
2021-11-30 10:11:49 +00:00
#### Log Metrics
Log as many metrics as you want from your processes using the [Logger ](../../fundamentals/logger.md ) module. This
2024-04-24 07:48:14 +00:00
improves the visibility of your processes' progress.
2021-05-13 23:48:51 +00:00
```python
from clearml import Logger
2024-01-10 12:40:19 +00:00
2021-11-09 13:58:40 +00:00
Logger.current_logger().report_scalar(
2021-11-30 10:11:49 +00:00
graph='metric',
series='variant',
value=13.37,
iteration=counter
2021-11-09 13:58:40 +00:00
)
2021-05-13 23:48:51 +00:00
```
2021-11-30 10:11:49 +00:00
You can also retrieve reported scalars for programmatic analysis:
2021-05-13 23:48:51 +00:00
```python
from clearml import Task
2024-01-10 12:40:19 +00:00
2021-05-13 23:48:51 +00:00
executed_task = Task.get_task(task_id='aabbcc')
# get a summary of the min/max/last value of all reported scalars
2021-11-30 10:11:49 +00:00
min_max_values = executed_task.get_last_scalar_metrics()
2021-09-09 10:17:46 +00:00
# get detailed graphs of all scalars
2021-05-13 23:48:51 +00:00
full_scalars = executed_task.get_reported_scalars()
```
2025-02-09 17:35:03 +00:00
#### Query Tasks
2021-11-30 10:11:49 +00:00
You can also search and query Tasks in the system. Use the [`Task.get_tasks` ](../../references/sdk/task.md#taskget_tasks )
2024-01-10 12:40:19 +00:00
class method to retrieve Task objects and filter based on the specific values of the Task - status, parameters, metrics and more!
2021-11-30 10:11:49 +00:00
2021-05-13 23:48:51 +00:00
```python
from clearml import Task
2024-01-10 12:40:19 +00:00
2021-11-09 13:58:40 +00:00
tasks = Task.get_tasks(
2021-11-30 10:11:49 +00:00
project_name='examples',
task_name='partial_name_match',
task_filter={'status': 'in_progress'}
2021-11-09 13:58:40 +00:00
)
2021-05-13 23:48:51 +00:00
```
2021-11-30 10:11:49 +00:00
#### Manage Your Data
2024-04-24 07:48:14 +00:00
Data is probably one of the biggest factors that determines the success of a project. Associating a model's data with
2021-11-30 10:11:49 +00:00
the model's configuration, code, and results (such as accuracy) is key to deducing meaningful insights into model behavior.
2021-10-04 09:20:50 +00:00
2023-02-16 10:17:53 +00:00
[ClearML Data ](../../clearml_data/clearml_data.md ) lets you version your data, so it's never lost, fetch it from every
2025-02-09 17:35:03 +00:00
machine with minimal code changes, and associate data to task results.
2021-05-13 23:48:51 +00:00
2021-11-30 10:11:49 +00:00
Logging data can be done via command line, or programmatically. If any preprocessing code is involved, ClearML logs it
2025-02-09 17:35:03 +00:00
as well! Once data is logged, it can be used by other tasks.