How do I preserve types when using task.get_parameters_as_dict()
or task.get_parameters()
?
If I connect the params via task.connect(input)
, change via the GUI, and use one of the methods above, all int
and float
values turn into strings. This doesn't work very well for hyperparameters that are numerical.
ok
but how can I get the hyperparameters from the current task?
Well, I connected a dictionary of params that needed to be accessible in the GUI via task.connect
using a loop, where I was filtering that dictionary:
for k, v in config_dict.items(): if k not in ['element1', 'element2']: task.connect(v, name=k.lower())
It seemed more logical to return the params with a single call:
task_parameters = task.get_parameters_as_dict()
Say I have a more complicated, nested dict of params, and I only want to send some of the nested keys to the GUI. I also want each one of those to be a "hyper parameters" field in the ClearML GUI. How do I connect each of these fields as such and return the correct types?
example:config: field1: dict(param1=123, param2='text') field2: dict(param1=123, param2='text') field3: dict(param1=123, param2='text')
If I understand what you suggested above, doing task.connect(base_params
on this nested dict will dump everything into one field and won't allow filtering.
What is the advantage to returning only string types?
Hi UnsightlySeagull42
But now I need the hyperparameters in every python file.
You can always get the Task from anywhere?main_task = Task.current_task()
task.connect
is two way, it does everything for you:base_params = dict(param1=123, param2='text') task.connect(base_params) print(base_params)
If you run this code manually, then print is exactly what you initialized base_params
with. But when the agent is running it, it will take the values from the UI (including casting to the correct type), so print will result in values/types from the UI.
Make sense ?
I would expect consistency in types I connected with those I retrieved.
No worries, let's assume we have:base_params = dict( field1=dict(param1=123, param2='text'), field2=dict(param1=123, param2='text'), ... )
Now let's just connect field1:task.connect(base_params['field1'], name='field1')
That's it 🙂
Hi ProudChicken98task.connect(input)
preserves the types based on the "input" dict types, on the flip side get_parameters
returns the string representation (as stored on the clearml-server).
Is there a specific reason for using get_parameters
over connect ?
you can also get it flattened with:task.get_parameters()
Type in both cases is string