Skip to content

Conversation

@albanD
Copy link
Collaborator

@albanD albanD commented Nov 23, 2018

Add to the Tensor doc info about .device, .is_cuda, .requires_grad, .is_leaf and .grad.
Update the register_backward_hook doc with a warning stating that it does not work in all cases.
Add support in the _add_docstr function to add docstring to attributes.

There is an explicit cast here but I am not sure how to handle it properly. The thing is that the doc field for getsetdescr is written as being a const char * (as all other doc fields in descriptors objects) in cpython online documentation. But in the code, it is the only one that is not const.
I assumed here that it is a bug in the code because it does not follow the doc and the convention of the others descriptors and so I cast out the const.
EDIT: the online doc I was looking at is for 3.7 and in that version both the code and the doc are const. For older versions, both are non const.
Please let me know if this should not be done. And if it should be done if there is a cleaner way to do it !

@albanD
Copy link
Collaborator Author

albanD commented Nov 23, 2018

As expected clang tidy is not happy with the cast.

@ezyang
Copy link
Contributor

ezyang commented Nov 23, 2018

Do a const_cast and that should shut clang tidy up. (I haven't verified if the cast is valid or not, but if you're sure you're right , that's what you should do)

@albanD
Copy link
Collaborator Author

albanD commented Nov 23, 2018

I do think the cast is valid here to the best of my knowledge:
Basically, up to python 3.6, the field is not const as you see here and it becomes const for python 3.7.
In our case I think it's fine to always give it our const tensor as numpy's implementation gives them here the result of PyString_AS_STRING as seen here which must not be modified.

But I would like to wait for another opinion on this.

@albanD albanD requested a review from goldsborough November 23, 2018 22:40
@albanD
Copy link
Collaborator Author

albanD commented Nov 28, 2018

The CI fail seems due to a division by 0 in Batchnorm1D test. So I guess unrelated to this PR?

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@ezyang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@ezyang ezyang left a comment

Choose a reason for hiding this comment

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

okey dokey

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.

3 participants