Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for clearing XLA:CUDA cached memory. #7824

Open
ysiraichi opened this issue Aug 9, 2024 · 2 comments
Open

API for clearing XLA:CUDA cached memory. #7824

ysiraichi opened this issue Aug 9, 2024 · 2 comments
Labels

Comments

@ysiraichi
Copy link
Collaborator

PyTorch/XLA currently has no means to clear cached memory, i.e. something similar to torch.cuda.empty_cache(). This is relevant for benchmarking a model on both PyTorch CUDA and XLA:CUDA.

For comparison, using PyTorch CUDA, we have:

# Memory usage rises to 4G
>>> a = torch.rand(1024, 1024, 1024, device="cuda")
>>> del a
>>> gc.collect()
# Memory goes back to ~200M
>>> torch.cuda.empty_cache()

In contrast, using XLA:CUDA with PJRT_ALLOCATOR_PREALLOCATE=false, we have:

# Memory usage rises to 4G
>>> a = torch.rand(1024, 1024, 1024, device=xm.xla_device())
>>> a.cpu()
>>> del a
>>> gc.collect()
# Memory usage never goes back...

Not only that, but it would be nice to have an API call for deleting the pre-allocated memory.

cc @miladm @JackCaoG

@miladm
Copy link
Collaborator

miladm commented Aug 9, 2024

Thank you @ysiraichi!
do you plan to work on this issue?

@ysiraichi
Copy link
Collaborator Author

It's actually not something that's blocking me, so I wasn't going to. But, if you think this is worth looking into, I could do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants