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

ValueError getting torch optimizers help message #101

Closed
carmocca opened this issue Nov 24, 2021 · 2 comments
Closed

ValueError getting torch optimizers help message #101

carmocca opened this issue Nov 24, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@carmocca
Copy link
Contributor

carmocca commented Nov 24, 2021

# repro.py
import jsonargparse
import torch

parser = jsonargparse.ArgumentParser()
parser.add_subclass_arguments(torch.optim.Optimizer, "optimizer", skip={"params"})
args = parser.parse_args()
$ python repro.py --optimizer.help torch.optim.Optimizer
Traceback (most recent call last):
  File "/Users/carlosmocholi/git/pytorch-lightning/kk2.py", line 6, in <module>
    args = parser.parse_args()
  File "/Users/carlosmocholi/.pyenv/versions/3.9.1/envs/lightning-3.9/lib/python3.9/site-packages/jsonargparse/deprecated.py", line 112, in patched_parse
    cfg = parse_method(*args, _skip_check=_skip_check, **kwargs)
  File "/Users/carlosmocholi/.pyenv/versions/3.9.1/envs/lightning-3.9/lib/python3.9/site-packages/jsonargparse/core.py", line 371, in parse_args
    cfg, unk = self.parse_known_args(args=args)
  File "/Users/carlosmocholi/.pyenv/versions/3.9.1/envs/lightning-3.9/lib/python3.9/site-packages/jsonargparse/core.py", line 260, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/Users/carlosmocholi/.pyenv/versions/3.9.1/lib/python3.9/argparse.py", line 2060, in _parse_known_args
    start_index = consume_optional(start_index)
  File "/Users/carlosmocholi/.pyenv/versions/3.9.1/lib/python3.9/argparse.py", line 2000, in consume_optional
    take_action(action, args, option_string)
  File "/Users/carlosmocholi/.pyenv/versions/3.9.1/lib/python3.9/argparse.py", line 1928, in take_action
    action(self, namespace, argument_values, option_string)
  File "/Users/carlosmocholi/.pyenv/versions/3.9.1/envs/lightning-3.9/lib/python3.9/site-packages/jsonargparse/actions.py", line 344, in __call__
    self.print_help(args, self._baseclass, dest)
  File "/Users/carlosmocholi/.pyenv/versions/3.9.1/envs/lightning-3.9/lib/python3.9/site-packages/jsonargparse/actions.py", line 375, in print_help
    super().print_help(call_args, val_class, dest+'.init_args')
  File "/Users/carlosmocholi/.pyenv/versions/3.9.1/envs/lightning-3.9/lib/python3.9/site-packages/jsonargparse/actions.py", line 348, in print_help
    tmp.add_class_arguments(val_class, dest)
  File "/Users/carlosmocholi/.pyenv/versions/3.9.1/envs/lightning-3.9/lib/python3.9/site-packages/jsonargparse/signatures.py", line 74, in add_class_arguments
    return self._add_signature_arguments(inspect.getmro(theclass),
  File "/Users/carlosmocholi/.pyenv/versions/3.9.1/envs/lightning-3.9/lib/python3.9/site-packages/jsonargparse/signatures.py", line 248, in _add_signature_arguments
    self._add_signature_parameter(
  File "/Users/carlosmocholi/.pyenv/versions/3.9.1/envs/lightning-3.9/lib/python3.9/site-packages/jsonargparse/signatures.py", line 361, in _add_signature_parameter
    raise ValueError(f'Required parameter without a type for {obj.__name__} parameter {name}.')
ValueError: Required parameter without a type for Optimizer parameter params.

I understand what the error message says, but shouldn't the help message still work?

Noticed this while checking out Lightning-AI/pytorch-lightning#10725

@mauvilsa
Copy link
Member

The code snippet is not equivalent to what is in lightning, in particular missing the skip. But from what I see the class help action is not considering the skip. This is a bug.

@mauvilsa mauvilsa added the bug Something isn't working label Nov 24, 2021
@mauvilsa
Copy link
Member

Fixed in 0f02e94

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants