How to use list as a parameter in configuration file?

Problem

I want to send a list as a parameter in the configuration file without starting grid search. How to do it?

How to run grid search anyways?

Passing a regular list is going to initiate Neptune grid search over list values.

1
2
parameters:
  learning_rate_per_layer: [0.1, 0.25, 0.5]  # start grid search over these values
You initiate grid search in the same way as regular expriment neptune run model_training.py

Solution

Simply, pass it as string.

Step 1

So in order to use it as parameter you need to do in your configuration file (neptune.yaml):

1
2
parameters:
  learning_rate_per_layer: '[0.1, 0.25, 0.5]'  # it is string, no grid search

Step 2

When you use your parameter in the script run eval on it:

1
2
3
4
5
6
import neptune

ctx = neptune.Context()

learning_rate_per_layer = ctx.params.learning_rate_per_layer
learning_rate_per_layer = eval(learning_rate_per_layer)  # learning_rate_per_layer is now list 

How about list of strings?

If your list contains strings as well remember to use a different quote symbol. For example:

1
2
parameters:
 data_paths: '["data/images", "data/targets"]'

and then:

1
2
3
4
5
6
import neptune

ctx = neptune.Context()

data_paths = ctx.params.data_paths
data_paths = eval(data_paths)  # data_paths is now list os strings 

See also