-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Expose custom attributes from C++ functions #1405
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how big this functions folder is going to grow. We may want to separate the attributes code in a separate sub-folder to keep this one with just the actual function implementations?
| type.tp_call = THPCppFunction_call; | ||
| type.tp_methods = THPCppFunction_methods; | ||
| type.tp_getset = THPCppFunction_properties; | ||
| type.tp_methods = function_methods ? function_methods : attributes::default_methods; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| namespace attributes { | ||
|
|
||
| template<class T> | ||
| PyObject* conv_stride(THPCppFunction* self, PyObject* hook) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| { | ||
| auto& var = *self->cdata; | ||
| return PyInt_FromLong(var.output_nr); | ||
| return PyLong_FromLong(var.output_nr); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| namespace attributes { | ||
|
|
||
| template<class T> | ||
| PyObject* conv_stride(THPCppFunction* self, PyObject* hook) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
|
||
| namespace attributes { | ||
|
|
||
| PyObject* next_functions(THPCppFunction* self, PyObject* hook) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
Ok. I have implemented a The one thing I still have to do is to inherit default attributes. |
|
I played with a few C++ possibilities for concatenating At this point, all changes that were suggested are in. |
|
yes please. rebase against master, send a PR there. |
* Gradient clipping routine with fused kernels Identical API as PyTorch. Falls back to PyTorch impl when not computing L2 norm. * Add unit test for gradient clipping * Add fp16 case to gradient clipping unit test * Tweaks to grad clipping unit test Review suggestions from @crcrpar * Debug gradient clipping tests When checking that incorrect results produce assertion errors, make sure to generate a discrepancy outside the range of numerical error.
This PR demonstrates a possible way to expose custom attributes from C++ functions.
Motivation: right now functions implemented in C++ do not expose function-specific attributes or methods (e.g.
strideforConvForward). This makes it impossible to get such attributes while traversing a computation graph.Currently only convolution attributes have been exposed, with the aim of illustrating the approach. If the proposal gets a thumbs up, I'll proceed and expose attributes for the rest of the C++ functions.
As agreed with @apaszke on Slack #autograd-internals, this PR points to the
autogradbranch.