Hi,
The .to() operation is out of place, so the first code does weird stuff for sure because it send data to the GPU and then discard it instantly.
The second one actually holds on to it and is only deleted on the next line.
Why one runs out of memory and not the other is due to fragmentation? Not sure what would be the reason here.