2023-10-24 12:06:33 +00:00
---
2024-02-18 11:40:01 +00:00
title: Transformers
2023-10-24 12:06:33 +00:00
---
HuggingFace's [Transformers ](https://huggingface.co/docs/transformers/index ) is a popular deep learning framework. You can
seamlessly integrate ClearML into your Transformer's PyTorch [Trainer ](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/trainer )
code using the built-in [`ClearMLCallback` ](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/callback#transformers.integrations.ClearMLCallback ).
ClearML automatically logs Transformer's models, parameters, scalars, and more.
All you have to do is install and set up ClearML:
1. Install the `clearml` python package:
```commandline
pip install clearml
```
2025-02-06 15:31:11 +00:00
1. To keep track of your tasks and/or data, ClearML needs to communicate to a server. You have 2 server options:
2023-10-24 12:06:33 +00:00
* Sign up for free to the [ClearML Hosted Service ](https://app.clear.ml/ )
* Set up your own server, see [here ](../deploying_clearml/clearml_server.md ).
1. Connect the ClearML SDK to the server by creating credentials (go to the top right in the UI to **Settings > Workspace > Create new credentials** ),
then execute the command below and follow the instructions:
```commandline
clearml-init
```
2025-02-06 15:31:11 +00:00
That's it! In every training run from now on, the ClearML task
2023-10-24 12:06:33 +00:00
manager will capture:
* Source code and uncommitted changes
2023-11-05 08:30:37 +00:00
* Hyperparameters - PyTorch trainer [parameters ](https://huggingface.co/docs/transformers/v4.34.1/en/main_classes/trainer#transformers.TrainingArguments )
2023-10-24 12:06:33 +00:00
and TensorFlow definitions
* Installed packages
* Model files (make sure the `CLEARML_LOG_MODEL` environment variable is set to `True` )
* Scalars (loss, learning rates)
* Console output
* General details such as machine details, runtime, creation date etc.
* And more
All of this is captured into a [ClearML Task ](../fundamentals/task.md ). By default, a task called `Trainer` is created
2023-12-03 12:27:46 +00:00
in the `HuggingFace Transformers` project. To change the task's name or project, use the `CLEARML_PROJECT` and `CLEARML_TASK`
2023-10-24 12:06:33 +00:00
environment variables
:::tip project names
ClearML uses `/` as a delimiter for subprojects: using `example/sample` as a name will create the `sample`
task within the `example` project.
:::
2024-03-12 09:24:42 +00:00
To log the models created during training, set the `CLEARML_LOG_MODEL` environment variable to `True` .
2023-10-24 12:06:33 +00:00
2023-12-03 12:27:46 +00:00
You can see all the captured data in the task's page of the ClearML [WebApp ](../webapp/webapp_exp_track_visual.md ).
2023-10-24 12:06:33 +00:00

2025-02-06 15:31:11 +00:00
Additionally, you can view all of your Transformers runs tracked by ClearML in the [Task Table ](../webapp/webapp_model_table.md ).
2023-10-24 12:06:33 +00:00
Add custom columns to the table, such as mAP values, so you can easily sort and see what is the best performing model.
2025-02-06 15:31:11 +00:00
You can also select multiple tasks and directly [compare ](../webapp/webapp_exp_comparing.md ) them.
2023-10-24 12:06:33 +00:00
2023-12-07 16:33:28 +00:00
See an example of Transformers and ClearML in action [here ](../guides/frameworks/huggingface/transformers.md ).
2023-10-24 12:06:33 +00:00
## Remote Execution
2025-02-06 15:31:11 +00:00
ClearML logs all the information required to reproduce a task on a different machine (installed packages,
2023-10-24 12:06:33 +00:00
uncommitted changes etc.). The [ClearML Agent ](../clearml_agent.md ) listens to designated queues and when a task is
enqueued, the agent pulls it, recreates its execution environment, and runs it, reporting its scalars, plots, etc. to the
2025-02-06 15:31:11 +00:00
task manager.
2023-10-24 12:06:33 +00:00
Deploy a ClearML Agent onto any machine (e.g. a cloud VM, a local GPU machine, your own laptop) by simply running
the following command on it:
```commandline
clearml-agent daemon --queue < queues_to_listen_to > [--docker]
```
Use the ClearML [Autoscalers ](../cloud_autoscaling/autoscaling_overview.md ) to help you manage cloud workloads in the
cloud of your choice (AWS, GCP, Azure) and automatically deploy ClearML agents: the autoscaler automatically spins up
and shuts down instances as needed, according to a resource budget that you set.
### Cloning, Editing, and Enqueuing

2023-12-03 12:27:46 +00:00
Use ClearML's web interface to edit task details, like configuration parameters or input models, then execute the task
2023-10-24 12:06:33 +00:00
with the new configuration on a remote machine:
2025-02-06 15:31:11 +00:00
* Clone the task
2023-10-24 12:06:33 +00:00
* Edit the hyperparameters and/or other details
* Enqueue the task
The ClearML Agent executing the task will use the new values to [override any hard coded values ](../clearml_agent.md ).
## Hyperparameter Optimization
2023-12-03 12:27:46 +00:00
Use ClearML's [`HyperParameterOptimizer` ](../references/sdk/hpo_optimization_hyperparameteroptimizer.md ) class to find
2023-10-24 12:06:33 +00:00
the hyperparameter values that yield the best performing models. See [Hyperparameter Optimization ](../fundamentals/hpo.md )
for more information.