Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception originated from within Sacred. KeyError: 'Invalid key "DogmaticDict.__setitem__". Config-keys cannot contain "." or start with "$"' #920

Open
hyfwyy opened this issue Aug 29, 2023 · 1 comment

Comments

@hyfwyy
Copy link

hyfwyy commented Aug 29, 2023

Hey,

I have some issues with the originated from within Sacred when i debug my code.

ex = sacred.Experiment('Global (train)', ingredients=[data_ingredient, model_ingredient],interactive=True)
SETTINGS.CAPTURE_MODE = 'sys'
ex.captured_out_filter = apply_backspaces_and_linefeeds
@ex.automain
def main(epochs, cpu, cudnn_flag, temp_dir, seed, no_bias_decay):
       '...'

When i debug until the line of @ex.automain, the error was raised as follows.

Exception originated from within Sacred.
Traceback (most recent calls):
File "/root/anaconda3/lib/python3.10/site-packages/sacred/config/utils.py", line 42, in assert_is_valid_key
raise KeyError(
KeyError: 'Invalid key "DogmaticDict.setitem". Config-keys cannot contain "." or start with "$"'

I find the error happen in line 42, in assert_is_valid_key

def assert_is_valid_key(key):
        if SETTINGS.CONFIG.ENFORCE_KEYS_MONGO_COMPATIBLE and (
                isinstance(key, str) and ("." in key or key[0] == "$")
            ):
                raise KeyError(
                    'Invalid key "{}". Config-keys cannot '
                    'contain "." or start with "$"'.format(key)
                )

And the key is defined as:

def normalize_or_die(obj):
    if isinstance(obj, dict):
        res = dict()
        for key, value in obj.items():
            assert_is_valid_key(key)
            res[key] = normalize_or_die(value)
        return res
    elif isinstance(obj, (list, tuple)):
        return list([normalize_or_die(value) for value in obj])
    return normalize_numpy(obj)

But i cannot find the definition of obj. And I cannot find any solution online.

I would be grateful for some help!

Best,

@thequilo
Copy link
Collaborator

Hey! What does your config look like?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants