Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/unittest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
# # Force resource release after test
import pytest
import torch
import tqdm


Expand Down Expand Up @@ -79,3 +80,12 @@ def pytest_sessionstart(session):
# To counter TransformerEngine v2.3's lazy_compile deferral,
# which will cause Pytest thinks there's a thread leakage.
import torch._inductor.async_compile # noqa: F401


@pytest.fixture(autouse=True)
def torch_empty_cache() -> None:
"""
Automatically empty the torch CUDA cache before each test, to reduce risk of OOM errors.
"""
if torch.cuda.is_available():
torch.cuda.empty_cache()