forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: NickLucche <[email protected]>
- Loading branch information
1 parent
5ed86b7
commit 6748673
Showing
2 changed files
with
47 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import torch | ||
|
||
|
||
def print_gpu_memory_stats(): | ||
if not torch.cuda.is_available(): | ||
print("No GPU available") | ||
return | ||
|
||
for i in range(torch.cuda.device_count()): | ||
device_name = torch.cuda.get_device_name(i) | ||
# Convert to GB | ||
total_memory = torch.cuda.get_device_properties(i).total_memory / (1024 | ||
**3) | ||
allocated = torch.cuda.memory_allocated(i) / (1024**3) | ||
reserved = torch.cuda.memory_reserved(i) / (1024**3) | ||
max_allocated = torch.cuda.max_memory_allocated(i) / (1024**3) | ||
max_reserved = torch.cuda.max_memory_reserved(i) / (1024**3) | ||
free_memory = reserved - allocated | ||
|
||
print(f"Device {i}: {device_name}") | ||
print(f" Total Memory: {total_memory:.2f} GB") | ||
print(f" Allocated Memory: {allocated:.2f} GB") | ||
print(f" Reserved Memory: {reserved:.2f} GB") | ||
print(f" Free Memory: {free_memory:.2f} GB") | ||
print(f" Max Allocated: {max_allocated:.2f} GB") | ||
print(f" Max Reserved: {max_reserved:.2f} GB") | ||
print("-" * 40) | ||
|
||
|
||
print_gpu_memory_stats() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters