Skip to content

update_config fails to apply config file values when CLI has default values #200

Description

@zklou

The update_config function in openstl/utils/main_utils.py has a logic bug that prevents config file values from overriding argparse
default values.

Current behavior:
def update_config(args, config, exclude_keys=list()):
for k in config.keys():
if args.get(k, False):
if args[k] != config[k] and k not in exclude_keys and args[k] is not None:
print(f'overwrite config key -- {k}: {config[k]} -> {args[k]}') # Only prints, doesn't assign!
else:
args[k] = config[k]

When args['dataname'] has the default value 'mmnist' and config file has dataname = 'custom_dataset', the config value is never
applied because:

  1. args.get('dataname', False) returns 'mmnist' (truthy)
  2. args[k] != config[k] is True
  3. It only prints a message but doesn't update args[k]

Expected behavior:
Config file values should override argparse defaults. The CLI-provided values should only take precedence when explicitly passed by
the user.

Suggested fix:
def update_config(args, config, exclude_keys=list()):
for k in config.keys():
if k in exclude_keys:
continue
if config[k] is not None:
args[k] = config[k]
return args

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions