chausies
chausies

Reputation: 854

PyTorch running under WSL2 getting "Killed" for Out of memory even though I have a lot of memory left?

I'm on Windows 11, using WSL2 (Windows Subsystem for Linux). I recently upgraded my RAM from 32 GB to 64 GB.

While I can make my computer use more than 32 GB of RAM, WSL2 seems to be refusing to use more than 32 GB. For example, if I do

>>> import torch
>>> a = torch.randn(100000, 100000) # 40 GB tensor

Then I see the memory usage go up until it hit's 30-ish GB, at which point, I see "Killed", and the python process gets killed. Checking dmesg, it says that it killed the process because "Out of memory".

Any idea what the problem might be, or what the solution is?

Upvotes: 6

Views: 10592

Answers (1)

jonsca
jonsca

Reputation: 10381

According to this blog post, WSL2 is automatically configured to use 50% of the physical RAM of the machine. You'll need to add a memory=48GB (or your preferred setting) to a .wslconfig file that is placed in your Windows home directory (\Users\{username}\).

[wsl2]
memory=48GB

After adding this file, shut down your distribution and wait at least 8 seconds before restarting.

Assume that Windows 11 will need quite a bit of overhead to operate, so setting it to use the full 64 GB would cause the Windows OS to run out of memory.

Upvotes: 10

Related Questions