Skip to content

Commit 7330d87

Browse files
committed
br: get_devie_and_memory_allocated() move to torch.py [skip ci]"
Signed-off-by: Brian Roland <broland@nvidia.com>
1 parent 5027a51 commit 7330d87

3 files changed

Lines changed: 21 additions & 28 deletions

File tree

sub-packages/bionemo-evo2/tests/bionemo/evo2/conftest.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import pytest
2121
import torch
2222

23-
from bionemo.testing.test_tools import get_device_and_memory_usage
23+
from bionemo.testing.torch import get_device_and_memory_allocated
24+
2425

2526
def pytest_sessionstart(session):
2627
"""Called at the start of the test session."""
@@ -29,10 +30,9 @@ def pytest_sessionstart(session):
2930
print(
3031
f"""
3132
sub-packages/bionemo-evo2/tests/bionemoe/evo2: Starting test session
32-
{get_device_and_memory_usage()}
33+
{get_device_and_memory_allocated()}
3334
"""
3435
)
35-
3636

3737

3838
def pytest_sessionfinish(session, exitstatus):
@@ -43,19 +43,10 @@ def pytest_sessionfinish(session, exitstatus):
4343
print(
4444
f"""
4545
sub-packages/bionemo-evo2/tests/bionemoe/evo2: Test session complete
46-
current_device={torch.cuda.current_device()}
47-
current device name: {torch.cuda.get_device_name(torch.cuda.current_device())}
48-
gb_available={torch.cuda.mem_get_info()[0] / 1024**3}
49-
Peak GPU memory: {peak_memory / 1024**3:.3f} GB
50-
Final GPU memory: {final_memory / 1024**3:.3f} GB
46+
{get_device_and_memory_allocated()}
5147
"""
5248
)
5349

54-
55-
56-
57-
58-
5950

6051
@pytest.fixture(autouse=True)
6152
def cleanup_after_test():

sub-packages/bionemo-testing/src/bionemo/testing/test_tools.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

sub-packages/bionemo-testing/src/bionemo/testing/torch.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,20 @@ def recursive_assert_approx_equal(x, y, atol=1e-4, rtol=1e-4):
6161
recursive_assert_approx_equal(x[key], y[key], atol=atol, rtol=rtol)
6262
else:
6363
assert x == y
64+
65+
66+
def get_device_and_memory_allocated() -> str:
67+
"""Get the current device index, name, and memory usage."""
68+
current_device_index = torch.cuda.current_device()
69+
props = torch.cuda.get_device_properties(current_device_index)
70+
message = (
71+
f"""
72+
current device index: {current_device_index}
73+
current device uuid: {props.uuid}
74+
current device name: {props.name}
75+
memory available: {torch.cuda.mem_get_info()[0] / 1024**3:.3f} GB
76+
memory allocated: {torch.cuda.memory_allocated() / 1024**3:.3f} GB
77+
max memory allocated: {torch.cuda.max_memory_allocated() / 1024**3:.3f} GB
78+
"""
79+
)
80+
return message

0 commit comments

Comments
 (0)