2021-05-13 23:48:51 +00:00
---
title: ClearML Task Tutorial
---
2022-01-23 09:02:38 +00:00
In this tutorial, you will use `clearml-task` to execute [a script ](https://github.com/allegroai/events/blob/master/webinar-0620/keras_mnist.py )
on a remote or local machine, from a remote repository and your local machine.
2021-05-13 23:48:51 +00:00
### Prerequisites
2023-12-26 13:49:35 +00:00
- [`clearml` ](../../getting_started/ds/ds_first_steps.md ) Python package installed and configured
- [`clearml-agent` ](../../clearml_agent.md#installation ) running on at least one machine (to execute the experiment), configured to listen to `default` queue
2021-05-13 23:48:51 +00:00
2021-09-09 10:17:46 +00:00
### Executing Code from a Remote Repository
2021-05-13 23:48:51 +00:00
``` bash
2022-01-27 10:32:35 +00:00
clearml-task --project keras_examples --name remote_test --repo https://github.com/allegroai/events.git --branch master --script /webinar-0620/keras_mnist.py --args batch_size=64 epochs=1 --queue default
2021-05-13 23:48:51 +00:00
```
2022-01-23 09:02:38 +00:00
This sets the following arguments:
2021-05-13 23:48:51 +00:00
2022-01-23 09:02:38 +00:00
* `--project keras_examples --name remote_test` - The project and experiment names
* `--repo https://github.com/allegroai/events.git` - The repository's URL. By default, `clearml-task` uses the latest
commit from the master branch
2022-01-27 10:32:35 +00:00
* `--branch master` - The repository branch
2022-01-23 09:02:38 +00:00
* `--script /webinar-0620/keras_mnist.py` - The script to be executed
* `--args batch_size=64 epochs=1` - Arguments passed to the script. This uses the `argparse` object to get CLI parameters
* `--queue default` - Selected queue to send the experiment to
2021-05-13 23:48:51 +00:00
2022-01-23 09:02:38 +00:00
:::note Adding Requirements
`clearml-task` automatically finds the requirements.txt file in remote repositories.
If a remote repo does not have such a file, make sure to either add one with all the required Python packages,
or add the `--packages "<package_name>"` option to the command (for example: `--packages "tqdm>=2.1" "scikit-learn"` ).
:::
2021-05-13 23:48:51 +00:00
2022-01-23 09:02:38 +00:00
Now `clearml-task` does all the heavy-lifting!
2023-12-26 13:49:35 +00:00
1. It creates a new [ClearML Task ](../../fundamentals/task.md )
2022-01-23 09:02:38 +00:00
1. `clearml-task` enqueues the task in the selected execution queue, where a [ClearML Agent ](../../clearml_agent.md )
2023-12-26 13:49:35 +00:00
assigned to that queue executes the task
2021-05-13 23:48:51 +00:00
2022-01-23 09:02:38 +00:00
Your output should look something like this:
2021-05-13 23:48:51 +00:00
```console
New task created id=2f96ee95b05d4693b360d0fcbb26b727
Task id=2f96ee95b05d4693b360d0fcbb26b727 sent for execution on queue default
2022-03-13 13:07:06 +00:00
Execution log at: https://app.clear.ml/projects/552d5399112d47029c146d5248570295/experiments/2f96ee95b05d4693b360d0fcbb26b727/output/log
2021-05-13 23:48:51 +00:00
```
2021-09-09 10:17:46 +00:00
### Executing a Local Script
2021-05-13 23:48:51 +00:00
2022-01-23 09:02:38 +00:00
For this example, use a local version of [this script ](https://github.com/allegroai/events/blob/master/webinar-0620/keras_mnist.py ).
1. Clone the [allegroai/events ](https://github.com/allegroai/events ) repository
1. Go to the root folder of the cloned repository
1. Run the following command:
2021-05-13 23:48:51 +00:00
2022-01-24 13:42:17 +00:00
```bash
2022-01-27 10:32:35 +00:00
clearml-task --project keras --name local_test --script webinar-0620/keras_mnist.py --branch master --requirements webinar-0620/requirements.txt --args epochs=1 --queue default
2021-05-13 23:48:51 +00:00
```
2022-01-23 09:02:38 +00:00
This sets the following arguments:
* `--project keras --name local_test` - The project and experiment names
* `--script /webinar-0620/keras_mnist.py` - The local script to be executed
* `-requirements webinar-0620/requirements.txt` - The local python package requirements file
* `--args batch_size=64 epochs=1` - Arguments passed to the script. This uses the argparse object to capture CLI parameters
* `--queue default` - Selected queue to send the experiment to
2021-05-13 23:48:51 +00:00
2022-01-23 09:02:38 +00:00
`clearml-task` creates a task according to the input parameters, and sends the task to the `default` queue for execution.