When adding loop state variables to a differentiable LoopOp, and some of them do not have gradients attached, the grad_in_offset and might not correspond to the index in m_input_indices.
When indexing into this array, using that index, an out-of-bounds access occurs.
I fixed this by adding another index grad_in_index to the Input struct that always tracks the index in m_input_indices, and can be used for indexing into that array.
It also fixes a reference counting bug, where ad variables in a suspended scope would be added to the loop state, and their count would be decremented when the temporary loop state arrays where freed.
When adding loop state variables to a differentiable
LoopOp
, and some of them do not have gradients attached, thegrad_in_offset
and might not correspond to the index inm_input_indices
. When indexing into this array, using that index, an out-of-bounds access occurs.I fixed this by adding another index
grad_in_index
to theInput
struct that always tracks the index inm_input_indices
, and can be used for indexing into that array.It also fixes a reference counting bug, where ad variables in a suspended scope would be added to the loop state, and their count would be decremented when the temporary loop state arrays where freed.