Yes, this error is raised if you are running out of memory.
Could you check, if the used device is free before running your script?
Also, try to reduce the batch size as much as possible to check the minimal necessary memory usage.