If this error is thrown randomly, the index tensor is most likely changing the type “randomly” in your code base.
I would recommend to narrow down, why the index tensor changes the type and make sure you are using valid indices.