2021-05-13 23:48:51 +00:00
---
title: Hyperparameters
---
2022-05-18 08:49:31 +00:00
Hyperparameters are a script's configuration options. Since hyperparameters can have substantial impact on
model performance, it is crucial to efficiently track and manage them.
ClearML supports tracking and managing hyperparameters in each experiment and provides a dedicated [hyperparameter
optimization module](hpo.md). With ClearML's logging and tracking capabilities, experiments can be reproduced, and their
hyperparameters and results can be saved and compared, which is key to understanding model behavior.
2023-12-03 12:27:46 +00:00
ClearML lets you easily try out different hyperparameter values without changing your original code. ClearML's [execution
2022-05-18 08:49:31 +00:00
agent](../clearml_agent.md) will override the original values with any new ones you specify through the web UI (see
2024-02-15 13:28:26 +00:00
[Configuration ](../webapp/webapp_exp_tuning.md#configuration ) in the Tuning Experiments page). You can also
2022-05-18 08:49:31 +00:00
programmatically set experiment parameters.
## Tracking Hyperparameters
Hyperparameters can be added from anywhere in your code, and ClearML provides multiple ways to obtain them! ClearML logs
and tracks hyperparameters of various types, supporting automatic logging and explicit reporting.
### Automatic Logging
Once a ClearML Task has been [initialized ](../references/sdk/task.md#taskinit ) in a script, ClearML automatically captures and tracks
the following types of parameters:
* Command line parsing - command line parameters passed when invoking code that uses standard python packages, including:
2024-08-04 15:45:38 +00:00
* [click ](../integrations/click.md )
* [argparse ](../guides/reporting/hyper_parameters.md#argparse-command-line-options )
* [Python Fire ](../integrations/python_fire.md )
* [LightningCLI ](../integrations/pytorch_lightning.md )
2022-05-18 08:49:31 +00:00
* TensorFlow Definitions (`absl-py`). See examples of ClearML's automatic logging of TF Defines:
* [TensorFlow MNIST ](../guides/frameworks/tensorflow/tensorflow_mnist.md )
* [TensorBoard PR Curve ](../guides/frameworks/tensorflow/tensorboard_pr_curve.md )
2024-03-03 08:43:10 +00:00
* [Hydra ](../integrations/hydra.md ) - ClearML logs the `OmegaConf` which holds all the configuration files,
as well as values overridden during runtime.
2022-05-18 08:49:31 +00:00
:::tip Disabling Automatic Logging
2024-03-12 09:24:42 +00:00
Automatic logging can be disabled. See [Control Automatic Logging ](../clearml_sdk/task_sdk.md#control-automatic-logging ).
2022-05-18 08:49:31 +00:00
:::
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
### Environment Variables
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
:::important Experiment Reproducibility
2021-05-13 23:48:51 +00:00
Relying on environment variables makes an experiment not fully reproducible, since ClearML Agent can't reproduce them at
runtime.
:::
2024-08-04 15:43:02 +00:00
Environment variables can be logged to a task by specifying the variables in the `sdk.development.log_os_environments`
field of the [`clearml.conf` ](../configs/clearml_conf.md ) file:
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
```editorconfig
2023-01-23 13:04:24 +00:00
log_os_environments: ["AWS_*", "CUDA_VERSION"]
2021-05-13 23:48:51 +00:00
```
2024-08-04 15:43:02 +00:00
You can also specify environment variables using the `CLEARML_LOG_ENVIRONMENT` environment variable:
* All environment variables:
```
export CLEARML_LOG_ENVIRONMENT=*
```
* Specific environment variables. For example, log `PWD` and `PYTHONPATH` :
```
export CLEARML_LOG_ENVIRONMENT=PWD,PYTHONPATH
```
2024-08-05 07:12:18 +00:00
* No environment variables:
2024-08-04 15:43:02 +00:00
```
export CLEARML_LOG_ENVIRONMENT=
```
2022-05-18 08:49:31 +00:00
:::note Overriding clearml.conf
2024-08-04 15:43:02 +00:00
The `CLEARML_LOG_ENVIRONMENT` variable always overrides the `clearml.conf` file.
2022-05-18 08:49:31 +00:00
:::
2021-05-13 23:48:51 +00:00
2024-08-04 15:43:02 +00:00
When a script that has integrated ClearML is executed, the environment variables listed in the `clearml.conf` or specified by
2022-05-18 08:49:31 +00:00
the `CLEARML_LOG_ENVIRONMENT` variable are logged by ClearML.
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
### Explicit Logging
2021-09-01 06:39:38 +00:00
2022-05-18 08:49:31 +00:00
To augment its automatic logging, ClearML supports explicitly logging parameters. ClearML provides methods to directly
connect Python objects and configuration objects, as well as manually set and update task parameters.
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
#### Connecting Python Objects
Users can directly connect Python objects, such as dictionaries and custom classes, to tasks, using the
2023-01-19 15:21:52 +00:00
[`Task.connect` ](../references/sdk/task.md#connect ) method. Once objects are connected to a task, all object elements
2022-05-18 08:49:31 +00:00
(e.g. class members, dictionary key-values pairs) are automatically logged by ClearML. Additionally, ClearML tracks these
values as they change through your code.
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
When connecting objects to ClearML, users can directly access and modify an object's elements (e.g. a specific key-value
pair in a parameter dictionary).
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
#### Connecting Configuration Objects
2024-03-06 13:00:50 +00:00
Configuration objects are dictionaries or configuration files connected to the task using
[`Task.connect_configuration()` ](../references/sdk/task.md#connect_configuration ). With this method, configuration
2022-05-18 08:49:31 +00:00
objects are saved as blobs i.e. ClearML is not aware of their internal structure.
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
#### Setting and Updating Parameters
2024-03-06 13:00:50 +00:00
ClearML provides methods to set and update task parameters manually. Use [`Task.set_parameters()` ](../references/sdk/task.md#set_parameters )
to define parameters manually. To update the parameters in an experiment, use [`Task.set_parameters_as_dict()` ](../references/sdk/task.md#set_parameters_as_dict ).
The `set_parameters_as_dict` method updates parameters while the `set_parameters` method overrides the parameters.
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
ClearML does not automatically track changes to explicitly set parameters.
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
### User Properties
2023-05-04 07:52:09 +00:00
User properties do not impact task execution and can be modified at any stage. They are convenient for setting
2023-02-16 10:17:53 +00:00
helpful values which are displayed in the [experiment table ](../webapp/webapp_exp_table.md ) (i.e. customize columns),
2022-05-18 08:49:31 +00:00
making it easier to search / filter experiments. Add user properties to an experiment with the
2023-01-19 15:21:52 +00:00
[`Task.set_user_properties` ](../references/sdk/task.md#set_user_properties ) method.
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
### Accessing Parameters
2021-05-13 23:48:51 +00:00
2023-12-03 12:27:46 +00:00
ClearML provides methods to directly access a task's logged parameters.
2021-05-13 23:48:51 +00:00
2024-04-04 07:45:19 +00:00
To get all of a task's parameters and properties (hyperparameters, configuration objects, and user properties), use
[`Task.get_parameters()` ](../references/sdk/task.md#get_parameters ), which will return a dictionary with the parameters,
2024-03-27 09:56:21 +00:00
including their subsections (see [WebApp sections ](#webapp-interface ) below).
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
## WebApp Interface
2021-05-13 23:48:51 +00:00
2022-05-26 06:54:41 +00:00
Configurations can be viewed in web UI experiment pages, in the **CONFIGURATION** tab.
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
The configuration panel is split into three sections according to type:
2024-08-04 15:45:38 +00:00
- **User Properties** - Modifiable section that can be edited post-execution
2022-05-18 08:49:31 +00:00
- **Hyperparameters** - Individual parameters for configuration
2024-08-04 15:45:38 +00:00
- **Configuration Objects** - Usually configuration files (JSON / YAML) or Python objects
2022-05-18 08:49:31 +00:00
2024-03-27 09:56:21 +00:00
These sections are further broken down into subsections based on how the parameters were logged (General / Args / TF_Define / Environment).
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
![Task hyperparameters sections ](../img/hyperparameters_sections.png )
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
## SDK Interface
2021-05-13 23:48:51 +00:00
2022-05-18 08:49:31 +00:00
See the [Configuration section ](../clearml_sdk/task_sdk.md#configuration ) of the Task SDK page for an overview of basic Pythonic
methods for working with hyperparameters.