How to skip some batches when using DDP?

I’ve tried with model.no_sync(). It will show the error CUDA is out of memory. I also tried to continue directly. But it showed the error collective operation timeout. What’s the best practice to skip some batches if their loss is infinite? I’d appreciate it if someone could give the advice.