I wanted to share a few things that helped me resolve this issue!
The two key principles I found were that:
1/ I needed to make many parts of the code into arrays instead of vectors (so size of the object would be (X,) as opposed to (X,1))
2/ Sometimes updating vectors using vec[i] caused problems; instead, adding had no issues. I wonder if this reflects that direct updates are not differentiable in any sense that I understand.
Unfortunately, I don’t have a 100% clear understanding of why these changes matter and want to note that these adjustments did not need to be made everywhere in the code. I do not have a good understanding of which scenarios require these changes and which do not