Skip to content

How do I skip an argument of a callable? #669

Open
@carmocca

Description

@carmocca

In this example

from jsonargparse import ArgumentParser, CLI
import torch
from typing import Callable
from dataclasses import dataclass

@dataclass
class Foo:
    opt: Callable[[torch.nn.Parameter], torch.optim.Optimizer]

parser = ArgumentParser()
parser.add_class_arguments(Foo)
args = parser.parse_args()
print(args)
# python script.py --opt torch.optim.Adam

How would I skip the lr?

I tried both:

parser.add_class_arguments(Foo, skip={"opt.lr"})
parser.add_class_arguments(Foo, skip={"opt.init_args.lr"})

but they do nothing.

I noticed that:

    opt: Callable[[torch.nn.Parameter, float], torch.optim.Optimizer]

will work assuming that the lr is the second positional argument of all optimizers, which might not be always true.

Thanks for the help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions