Did you print the problematic batch, which creates the error or just a random one?
In the latter case you could add an assert statement checking for the invalid indices and print them, in case it’s triggered. This could narrow down the faulty batch and you could dig into the code to figure out, how this invalid index is created.