Could you check via nvidia-smi how much memory is reported to be free there when the script runs OOM?
Also, could you update the code snippet to be executable so that we could try to reproduce it on an A6000?