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

More robust handling of variadics in external #25

Merged
merged 3 commits into from
Nov 30, 2023

Conversation

BenjaminMidtvedt
Copy link
Collaborator

@BenjaminMidtvedt BenjaminMidtvedt commented Nov 28, 2023

Fixes an issue where classes with both *args and **kwargs in their signature could not be created using Layer.

There is only very rare case that is not supported, which is when you have both variadics and positionaal only arguments. Example:

class MyOverlyComplexClass
    def __init__(self, posonly, /, param, *args):
        ...

layer = Layer(MyOverlyComplexClass, "foo", "bar", "baz")

Where we now throw a type error. Should be extremely rare (/ is almost never used). But in these cases you can provide a wrapper like

def overly_complex_builder(self, posonly, param, *args):
    return MyOverlyComplexClass(posonly, param, *args)

layer = Layer(overly_complex_builder, "foo", "bar", "baz")

@BenjaminMidtvedt
Copy link
Collaborator Author

BenjaminMidtvedt commented Nov 29, 2023

Note that either variadics or positional only on their own are ok:

class MyLessComplexClass:
    def __init__(self, arg, *args, kwonly, param=None, **kwargs):
        ...

class OtherLessComplexClass:
    def __init__(self, a, /, b *, kw, **kwargs):
        ...

@BenjaminMidtvedt
Copy link
Collaborator Author

This should also close #24

Copy link
Collaborator

@Henrik-KM Henrik-KM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, everything seems to work now at least with standard layers currently in torch.

@BenjaminMidtvedt BenjaminMidtvedt linked an issue Nov 30, 2023 that may be closed by this pull request
@BenjaminMidtvedt BenjaminMidtvedt merged commit 29d40a0 into develop Nov 30, 2023
12 checks passed
@BenjaminMidtvedt BenjaminMidtvedt deleted the bm/variadics_init branch December 1, 2023 14:00
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

Successfully merging this pull request may close these issues.

Cannot fetch attributes from LSTM,GRU,RNN
3 participants