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

Defaults for CLI predict configs: default "obs_names_n" batch_key and default PredictionWriter #266

Open
sjfleming opened this issue Nov 7, 2024 · 1 comment

Comments

@sjfleming
Copy link
Contributor

I sometimes forget that I need to specify obs_names_n as a "batch_key" when writing a yaml config for prediction. Since this is always the same and always required for prediction, isn't it possible to inject it as a default when running the predict subcommand?

  batch_keys:
    ...
    obs_names_n:
      attr: obs_names

Similarly, is it possible to include a default PredictionWriter callback (that can be overwritten by the yaml) whenever the CLI subcommand is predict?

I guess my ultimate goal would be this:
For most cases, you can actually use the same yaml config file for train and predict. This might be enabled if, for example, you could give a couple extra inputs at the command line at runtime to specify things like ckpt_path.

@sjfleming
Copy link
Contributor Author

I fooled with this for a while and it seems to be less trivial than I thought. I can add defaults for something like "data.batch_keys", but if for example I put this in NewLightningCLI.add_arguments_to_parser

            if self.subcommand_is_predict:
                parser.set_defaults(
                    {
                        "data.batch_keys": {"obs_names_n": {"attr": "obs_names"}},
                    }
                )

then that becomes the default... but if you specify any data.batch_keys in your config file (which you will), then this default gets totally overridden, not added to.

If I try to add a default just for obs_names_n directly like this

            if self.subcommand_is_predict:
                parser.set_defaults(
                    {
                        "data.batch_keys.obs_names_n": {"attr": "obs_names"},
                    }
                )

then I get some error about

jsonargparse._namespace.NSKeyError: No action for key "data.batch_keys.obs_names_n" to set its default.

which I think means that the parser considers data.batch_keys to be an input argument, but does not consider data.batch_keys.obs_names_n to be an input argument.

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

1 participant