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

Raise clearer Exception when calling method of unbound module #1014

Closed
ingmarschuster opened this issue Feb 10, 2021 · 4 comments · Fixed by #2440
Closed

Raise clearer Exception when calling method of unbound module #1014

ingmarschuster opened this issue Feb 10, 2021 · 4 comments · Fixed by #2440
Assignees
Labels
Priority: P2 - no schedule Best effort response and resolution. We have no plan to work on this at the moment.

Comments

@ingmarschuster
Copy link

Using this minimal example

import jax.numpy as np
from jax.numpy import log, exp
import jax.random as rand
import flax.linen as ln

class MultipleForw(ln.Module):
    def setup(self):
        self.s1 = self.param("s1", ln.initializers.ones, (1,))

    def __call__(self, X, ):
        return X * log(1 + exp(self.s1 - 1))



mf = MultipleForw()
X = np.arange(5)
mf.init(rand.PRNGKey(0), X)
mf(X)

Problem you have encountered:

The last line raised the rather opaque error message AttributeError: 'MultipleForw' object has no attribute 's1'

What you expected to happen:

The raised Exception should contain a hint that makes clear that calling a linen-Module correctly is by using mf.apply(parameters, input). See Discussion #1013

@avital avital added this to the Improve Error Messages milestone Feb 25, 2021
@avital avital added the Priority: P1 - soon Response within 5 business days. Resolution within 30 days. (Assignee required) label Feb 25, 2021
@marcvanzee marcvanzee linked a pull request Mar 3, 2021 that will close this issue
@marcvanzee marcvanzee assigned marcvanzee and unassigned avital Mar 11, 2021
@marcvanzee
Copy link
Collaborator

In #1072, I tried fixing this by creating a custom error class for Module AtttributeError, but after a discussion with @avital we found that this is not a very natural solution because users expect a normal AttributeError when they are trying to access an unknown attribute in a Module.

Solving this issue is a bit more work, and probably not our highest priority. For now I'm lowering the priority of this issue because it seems we won't fix it soon, and we can higher it when it turns out that more users run into this problem.

@marcvanzee marcvanzee added Priority: P2 - no schedule Best effort response and resolution. We have no plan to work on this at the moment. and removed Priority: P1 - soon Response within 5 business days. Resolution within 30 days. (Assignee required) labels Mar 15, 2021
@marcvanzee marcvanzee removed their assignment Mar 25, 2021
@marcvanzee
Copy link
Collaborator

Also unassigning myself since I don't plan to work on this soon.

@marcvanzee marcvanzee removed this from the Improve Error Messages milestone Apr 28, 2022
@cgarciae cgarciae self-assigned this Sep 6, 2022
@cgarciae
Copy link
Collaborator

cgarciae commented Sep 6, 2022

I'd like to take this issue. A simple solution would be to customize the current error message to suggest calling apply if self.scope is None. I'll create a PR as this is a rather simple fix, if we want to tackle it a different way we can discuss there.

@ingmarschuster
Copy link
Author

This already sounds an order of magnitude better than the current situation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: P2 - no schedule Best effort response and resolution. We have no plan to work on this at the moment.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants