Skip to content

[FEATURE] Load command line options from config file #86

@timothybrooks

Description

@timothybrooks

Hello! I love Typer and have started to use it for my deep learning training.

One addition that would be really helpful for deep learning CLIs is the ability to load command line arguments and options from configuration files. This is particularly useful to help manage CLIs with lots of arguments and options, especially when certain sets of inputs are common. Sacred configs have this ability, as do WandB configs:

Here is a demo of how this could work with Typer:

Parameters specified in resnet.yml will automatically fill in args/options of the same names:

train.py --config resnet.yml

When multiple configs are provided, the latter will override the former should there be conflicts.

run.py --config resnet.yml small_test.yml

If args/options are also specified directly, those override anything provided in the config.

run.py --config resnet.yml small_test.yml --num_layers 4

An alternative to consider is just making each config its own boolean option. This has the following downsides:

  • Requires adding more flags, even if they only modify other args/options. This does not scale well.
  • Ambiguous overriding if multiple configs are provided or if args/options are also added directly.

With argparser, people will sometimes use the following pattern to achieve something similar. By changing the defaults and re-parsing rather than directly changing the args, this allows args/options defined directly on the command line to still override the new defaults. However, this too does not scale well, and there is no clear way to change defaults with Typer.

args, _ = parser.parse_known_args()
        if opt.small_test:
            parser.set_defaults(batch_size=1, num_layers=2, multiscale=False, ...)
args = parser.parse()

I believe the addition of loading args from config files would make Typer fantastic for deep learning research, making it much easier to scale and compose different configurations, and clarifying which parameters override others.

This unfortunately isn't something I know how to implement, but I would be happy to discuss or clarify this further if you agree that it would be a good addition.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature, enhancement or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions