Skip to content

vmap: fixed to work with functools.partial#43028

Closed
zou3519 wants to merge 2 commits intogh/zou3519/286/basefrom
gh/zou3519/286/head
Closed

vmap: fixed to work with functools.partial#43028
zou3519 wants to merge 2 commits intogh/zou3519/286/basefrom
gh/zou3519/286/head

Conversation

@zou3519
Copy link
Copy Markdown
Contributor

@zou3519 zou3519 commented Aug 13, 2020

Stack from ghstack:

There was a bug where we always tried to grab the __name__ attribute of
the function passed in by the user. Not all Callables have the
__name__ attribute, an example being a Callable produced by
functools.partial.

This PR modifies the error-checking code to use repr if __name__ is
not available. Furthermore, it moves the "get the name of this function"
functionality to the actual error sites as an optimization so we don't
spend time trying to compute __repr__ for the Callable if there is no
error.

Test Plan:

  • pytest test/test_vmap.py -v, added new tests.

Differential Revision: D23130235

There was a bug where we always tried to grab the `__name__` attribute of
the function passed in by the user. Not all Callables have the
`__name__` attribute, an example being a Callable produced by
functools.partial.

This PR modifies the error-checking code to use `repr` if `__name__` is
not available. Furthermore, it moves the "get the name of this function"
functionality to the actual error sites as an optimization so we don't
spend time trying to compute `__repr__` for the Callable if there is no
error.

Test Plan:
- `pytest test/test_vmap.py -v`, added new tests.

[ghstack-poisoned]
zou3519 added a commit that referenced this pull request Aug 13, 2020
There was a bug where we always tried to grab the `__name__` attribute of
the function passed in by the user. Not all Callables have the
`__name__` attribute, an example being a Callable produced by
functools.partial.

This PR modifies the error-checking code to use `repr` if `__name__` is
not available. Furthermore, it moves the "get the name of this function"
functionality to the actual error sites as an optimization so we don't
spend time trying to compute `__repr__` for the Callable if there is no
error.

Test Plan:
- `pytest test/test_vmap.py -v`, added new tests.

ghstack-source-id: 09ec881
Pull Request resolved: #43028
@zou3519 zou3519 requested review from cpuhrsch and ezyang August 13, 2020 20:35
@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented Aug 13, 2020

💊 CI failures summary and remediations

As of commit 79174ef (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 5 times.

There was a bug where we always tried to grab the `__name__` attribute of
the function passed in by the user. Not all Callables have the
`__name__` attribute, an example being a Callable produced by
functools.partial.

This PR modifies the error-checking code to use `repr` if `__name__` is
not available. Furthermore, it moves the "get the name of this function"
functionality to the actual error sites as an optimization so we don't
spend time trying to compute `__repr__` for the Callable if there is no
error.

Test Plan:
- `pytest test/test_vmap.py -v`, added new tests.

Differential Revision: [D23130235](https://our.internmc.facebook.com/intern/diff/D23130235)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@zou3519 merged this pull request in 768c2a8.

1 similar comment
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@zou3519 merged this pull request in 768c2a8.

@facebook-github-bot facebook-github-bot deleted the gh/zou3519/286/head branch August 21, 2020 14:16
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Pull Request resolved: pytorch#43028

There was a bug where we always tried to grab the `__name__` attribute of
the function passed in by the user. Not all Callables have the
`__name__` attribute, an example being a Callable produced by
functools.partial.

This PR modifies the error-checking code to use `repr` if `__name__` is
not available. Furthermore, it moves the "get the name of this function"
functionality to the actual error sites as an optimization so we don't
spend time trying to compute `__repr__` for the Callable if there is no
error.

Test Plan: - `pytest test/test_vmap.py -v`, added new tests.

Reviewed By: yf225

Differential Revision: D23130235

Pulled By: zou3519

fbshipit-source-id: 937f3640cc4d759bf6fa38b600161f5387a54dcf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants