Skip to content

Conversation

@dasguptar
Copy link
Contributor

Works for both nn.Module and functional versions, fixes #3233.

Works for both nn.Module and functional versions
@colesbury
Copy link
Member

Thanks for the contribution.

I think this would be better implemented in the C++ code. Specifically embedding/embedding_backward in aten/src/ATen/native/Embedding.cpp.

The new functionality also deserves a test. (test_embedding_padding_idx in test_nn.py)

@apaszke
Copy link
Contributor

apaszke commented Jan 5, 2018

Pushing it down to the C++ level would be harder, because it's hard to choose the "no padding" value if it's just an int. You either need an extra flag, or choose INT_MIN or INT_MAX, but these are annoying to get from Python

@dasguptar
Copy link
Contributor Author

dasguptar commented Jan 7, 2018

@colesbury @apaszke thanks for the feedback.

I kept the changes in Python because the C++ code uses -1 to denote no padding, and changing that would require jumping through many more hoops.

I have added unit tests to test_nn.py to account for the new functionality.

@dasguptar
Copy link
Contributor Author

Hi @colesbury @apaszke sorry to bother you, but do the changes look fine to you? Can this be merged in that case?

@apaszke apaszke merged commit f99c7d9 into pytorch:master Jan 9, 2018
@apaszke
Copy link
Contributor

apaszke commented Jan 9, 2018

Thanks @dasguptar!

@soumith soumith added 0.3.1 and removed 0.3.1 labels Feb 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nn.Embedding padding idx doesn't check for negative value

5 participants