Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to view and release GPU resources occupied by closed programs by Pytorch

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces Pytorch how to view and release the GPU resources occupied by the closed program, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.

Look at the code ~ import torch print (torch.cuda.current_device ()) print (torch.cuda.device_count ()) print (torch.cuda.get_device_name ()) print (torch.cuda.is_available ())

Open terminal and enter nvidia-smi to see the current usage status of each graphics card and user. Use kill-9 pid (to be replaced with a specific number) to kill the resource-consuming program, and the result after killing

Add: how to deal with the situation where there are still unreleased GPU resources after Pytorch uses GPU

Using PyTorch to set up multithreading (threads) for data reading (DataLoader) is actually a fake multithreading. He has opened N sub-processes (PID are all connected) to simulate multithreading work, so if your program runs out or kill drops the main process, the GPU memory of the child process will not be released. You need to manually use a kill.

The specific methods are described as follows:

1. Close the ssh (or shell) window first, log out and log in again

two。 View all programs running on gpu:

Fuser-v / dev/nvidia*

3.kill drops all (consecutive) zombie processes

Thank you for reading this article carefully. I hope the article "how to view and release GPU resources occupied by closed programs" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 242

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report