Fix: Align forward and backward arguments in cpp_extension tutorial #3520
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.
This PR fixes a bug in the
lltm_cuda_kernel.cuexample by aligning the return values of thelltm_cuda_backwardfunction with the Python backward interface.In
cpp_extension.rstline 1150:return {d_old_h, d_input, d_weights, d_bias, d_old_cell, d_gates};the original
lltm_cuda_backwardfunction returned six values.However, the corresponding Python backward interface(line 470) only expects five values to be returned, as it corresponds to the number of input tensors to the forward function:
This mismatch causes the example to fail at runtime.
This change corrects the
lltm_cuda_backwardfunction to return only the five required gradient tensors, bringing it into alignment with the Python side. Thed_gatestensor is no longer returned, as its gradient is not needed by the caller.Before this change: The example code would throw
ValueError: too many values to unpack (expected 5).After this change: The example will run successfully, providing a correct and functional demonstration of a custom CUDA extension.