Skip to content

Commit

Permalink
clear memory in pytest (NVIDIA#2600)
Browse files Browse the repository at this point in the history
This PR added `clear_cuda_cache()` to each test in `tests/python/pytest_ops.py` to avoid OOM.
  • Loading branch information
liqiangxl authored Jul 16, 2024
1 parent 2e293a3 commit ab79e81
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/python/pytest_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest
import numpy as np

from benchmarks.python.core import clear_cuda_cache
from pytest_fusion_definitions import default_fd_fn, parse_inputs_fusion_definition
from pytest_framework import create_op_test
from pytest_core import ReferenceType, OpInfo, SampleInput
Expand Down Expand Up @@ -155,6 +156,7 @@ def correctness_test_fn(

@create_op_test(tuple(op for op in opinfos if op.sample_input_generator is not None))
def test_correctness(op: OpInfo, dtype: torch.dtype):
clear_cuda_cache()
for sample in op.sample_input_generator(op, dtype):
result = correctness_test_fn(op.reference_type, op, sample)
if result is not None:
Expand Down Expand Up @@ -188,6 +190,7 @@ def schedule(self):
# TODO Maybe only test a single dtype
@create_op_test(tuple(op for op in opinfos if op.sample_input_generator is not None))
def test_definition_op_in_schedule_error(op: OpInfo, dtype: torch.dtype):
clear_cuda_cache()
for sample in op.sample_input_generator(op, dtype):
with pytest.raises(
RuntimeError, match=r"Attempting to add to a completed definition"
Expand Down Expand Up @@ -221,6 +224,7 @@ def _regex_escape_parenthesis(a: str) -> str:

@create_op_test(tuple(op for op in opinfos if op.error_input_generator is not None))
def test_errors(op: OpInfo, dtype: torch.dtype):
clear_cuda_cache()
for sample, exception_type, exception_regex in op.error_input_generator(op, dtype):
with pytest.raises(
exception_type, match=_regex_escape_parenthesis(exception_regex)
Expand Down

0 comments on commit ab79e81

Please sign in to comment.