The error points towards a failed indexing operation:
Assertion `index >= -sizes[i] && index < sizes[i] && "index out of bounds"` failed.

Based on the stacktrace I assume it’s caused in this line of code:
noobj_mask[b[i], anchor_ious > ignore_thres, gj[i], gi[i]] = 0

To make sure it’s the right line of code causing this assertion, rerun the code with CUDA_LAUNCH_BLOCKING=1 python script.py args, which would show the right place in the stacktrace.