clearml-docs/docs/guides/reporting/hyper_parameters.md

84 lines
2.8 KiB
Markdown
Raw Normal View History

2021-05-13 23:48:51 +00:00
---
title: Hyperparameters Reporting
---
The [hyper_parameters.py](https://github.com/allegroai/clearml/blob/master/examples/reporting/hyper_parameters.py) example
script demonstrates:
2022-03-13 13:07:06 +00:00
* ClearML's automatic logging of `argparse` command line options and TensorFlow Definitions
2021-05-13 23:48:51 +00:00
* Logging user-defined hyperparameters with a parameter dictionary and connecting the dictionary to a Task.
2022-05-26 06:54:41 +00:00
Hyperparameters appear in the **web UI** in the experiment's page, under **CONFIGURATION** **>** **HYPER PARAMETERS**.
2021-05-13 23:48:51 +00:00
Each type is in its own subsection. Parameters from older experiments are grouped together with the ``argparse`` command
line options (in the **Args** subsection).
When the script runs, it creates an experiment named `hyper-parameters example`, which is associated with the `examples` project.
2021-09-09 10:17:46 +00:00
## Argparse Command Line Options
2021-05-13 23:48:51 +00:00
2022-03-13 13:07:06 +00:00
If a code uses argparse and initializes a Task, ClearML automatically logs the argparse arguments.
2021-12-14 13:12:30 +00:00
```python
parser = ArgumentParser()
parser.add_argument('--argparser_int_value', help='integer value', type=int, default=1)
parser.add_argument(
'--argparser_disabled', action='store_true', default=False, help='disables something'
)
parser.add_argument('--argparser_str_value', help='string value', default='a string')
2021-05-13 23:48:51 +00:00
2021-12-14 13:12:30 +00:00
args = parser.parse_args()
```
2021-05-13 23:48:51 +00:00
Command line options appears in **HYPER PARAMETERS** **>** **Args**.
![image](../../img/examples_reporting_hyper_param_01.png)
## TensorFlow Definitions
2022-03-13 13:07:06 +00:00
ClearML automatically logs TensorFlow Definitions, whether they are defined before or after the Task is initialized.
2021-05-13 23:48:51 +00:00
2021-12-14 13:12:30 +00:00
```python
flags.DEFINE_string('echo', None, 'Text to echo.')
flags.DEFINE_string('another_str', 'My string', 'A string', module_name='test')
2021-05-13 23:48:51 +00:00
2021-12-14 13:12:30 +00:00
task = Task.init(project_name='examples', task_name='hyper-parameters example')
2021-05-13 23:48:51 +00:00
2021-12-14 13:12:30 +00:00
flags.DEFINE_integer('echo3', 3, 'Text to echo.')
2021-05-13 23:48:51 +00:00
2021-12-14 13:12:30 +00:00
flags.DEFINE_string('echo5', '5', 'Text to echo.', module_name='test')
```
2021-05-13 23:48:51 +00:00
TensorFlow Definitions appear in **HYPER PARAMETERS** **>** **TF_DEFINE**.
![image](../../img/examples_reporting_hyper_param_03.png)
2021-09-09 10:17:46 +00:00
## Parameter Dictionaries
2021-05-13 23:48:51 +00:00
Connect a parameter dictionary to a Task by calling the [Task.connect](../../references/sdk/task.md#connect)
2022-03-13 13:07:06 +00:00
method, and ClearML logs the parameters. ClearML also tracks changes to the parameters.
2021-05-13 23:48:51 +00:00
2021-12-14 13:12:30 +00:00
```python
parameters = {
'list': [1, 2, 3],
'dict': {'a': 1, 'b': 2},
'tuple': (1, 2, 3),
'int': 3,
'float': 2.2,
'string': 'my string',
}
2021-05-13 23:48:51 +00:00
2021-12-14 13:12:30 +00:00
parameters = task.connect(parameters)
2021-05-13 23:48:51 +00:00
2021-12-14 13:12:30 +00:00
# adding new parameter after connect (will be logged as well)
parameters['new_param'] = 'this is new'
# changing the value of a parameter (new value will be stored instead of previous one)
parameters['float'] = '9.9'
```
2021-05-13 23:48:51 +00:00
Parameters from dictionaries connected to Tasks appear in **HYPER PARAMETERS** **>** **General**.
![image](../../img/examples_reporting_hyper_param_02.png)