CUDA error: out of memory

What kind of error do you get? Is your GPU running out of memory?

Did you check, if other applications or maybe dead kernels are using the GPU?
If so, you could try to kill them before running your script.
If you can’t detect any other applications, did you notice a certain pattern, when the OOM occurs?