[CK_BUILDER] Tensor input/output reflection #3536
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed changes
While thinking about adding support for bwd, I realized that this would require duplicating a lot of code for the different versions of Input, Output, and related functions. Instead of writing those all out, I figured that it would be possible to derive most of them by providing some reflection utilities. So, this is an idea of how to do that. I'm looking for a bit of feedback, since this is relatively complex in terms of code.
Design
A new concept,
TensorReflectable, can be implemented byInputsandOutputsto automatically provide support forUniqueInputs,UniqueOutputs,alloc_inputs,alloc_outputs, andvalidate(). Basically,Inputs::reflectandOutputs::reflectcall an inspection function with each of its fields, and this can then be used to automatically implement the other functions. Its pretty straight forward, the main complex part is thatinspect()has to be called with a member variable pointer so as to allow the function to be static. To be honest, the main reason for that is so that the automatic implementation ofvalidate()can be a bit cleaner. Let me know what you think.