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

allow integer device for BatchEncoding #9271

Merged
merged 1 commit into from
Dec 24, 2020

Conversation

jethrokuan
Copy link
Contributor

What does this PR do?

Fixes #9244

I'm not fully aware of the details behind the Apex guard, in the method, so maybe this is not the solution.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

tokenizers: @mfuntowicz

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

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

This looks good to me. torch 1.7 also supports "integer" device assignment. @jethrokuan - do you know if previous PyTorch versions supported this as well?

Also not really sure what is meant by the APEX comment. @sgugger @LysandreJik do you know more here maybe?

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

The comment for APEX is because the to method is lso used to convert the dtype of a Tensor, and APEX does not perform type checks before calling the to method (just that the to method exists), which means or BatchEncoding are converted to a dict of half tensors if we don't have this safeguard.

Using an int should work with older versions of PyTorch AFAICT, however it's considered "legacy" behavior so it may be removed in a future version. In the meantime, I have no problem with accepting them on our side.

@patrickvonplaten patrickvonplaten merged commit 222dbdb into huggingface:master Dec 24, 2020
@jethrokuan jethrokuan deleted the fix/9244 branch December 24, 2020 13:51
guyrosin pushed a commit to guyrosin/transformers that referenced this pull request Jan 15, 2021
Fixes huggingface#9244

Co-authored-by: Jethro Kuan <jethro.kuan@bytedance.com>
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.

BatchEncoding.to accepted types too restrictive
3 participants