Detect SimpleNamespace as flag

Hi, I’m trying to tune hyperparameters using guild. These are defined as follows:

from types import SimpleNamespace
params = SimpleNamespace(
    embedding_dim = 256,
    window_size = 5,
    batch_size = 2048,
    epochs = 2,
    preprocessed = f'{DATASET_ROOT}/{DATASET_PREFIX}',
    working = f'{WORKING_ROOT}/{DATASET_PREFIX}',
    modelname = f'{WORKING_ROOT}/{DATASET_VERSION}.pt',
    train = True
)

Guild won’t find them by default and I am having a hard time working around this. I am new to guild so maybe there is an answer in the DOCS i haven’t found.

Thanks in advance

Hello and welcome! This is not supported using SimpleNamespace for flags directly, but you can use a standard Python dict this way:

from types import SimpleNamespace

param_vals = {
    "foo": 123,
    "bar": "hello there",
}

params = SimpleNamespace(**param_vals)

print(params)

The Guild file (guild.yml) needs to look like this in this case:

op:
  flags-dest: global:param_vals
  flags-import: all

Support for SimpleNamespace based globals is a great idea! In the meantime, this workaround will get you past the blocker.

Thanks for the response!

We have a branch started for this feature:

From the look of it, it’s completed but we won’t merge to master until 0.7.3 is released (hopefully later today).

To support this, you need to use the namespace dest type like this:

With that, this code works as expected:

Thanks for the question—I think it’s a solid feature. The namespace interface is much cleaner than using dicts.