Skip to content

Commit

Permalink
profiler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
awaelchli committed Jul 12, 2024
1 parent d36856c commit f19baea
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/tests_pytorch/profilers/test_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import logging
import os
import platform
import sys
import time
from copy import deepcopy
from unittest.mock import patch
Expand All @@ -35,6 +36,13 @@
PROFILER_OVERHEAD_MAX_TOLERANCE = 0.0005


# TODO: Nested profile calls are not supported and raise an error in Python 3.12+
# https://github.com/Lightning-AI/pytorch-lightning/issues/19983
skip_advanced_profiler_py312 = pytest.mark.skipif(
sys.version_info >= (3, 12), reason="Nested profiler calls not supported."
)


def _get_python_cprofile_total_duration(profile):
return sum(x.inlinetime for x in profile.getstats())

Expand Down Expand Up @@ -333,6 +341,7 @@ def test_pytorch_profiler_describe(pytorch_profiler):
assert len(data) > 0


@skip_advanced_profiler_py312
def test_advanced_profiler_cprofile_deepcopy(tmp_path):
"""Checks for pickle issue reported in #6522."""
model = BoringModel()
Expand Down Expand Up @@ -510,7 +519,11 @@ def __init__(self):
assert "[pl][module]torch.nn.modules.linear.Linear: layer.2" in event_names


@pytest.mark.parametrize("cls", [SimpleProfiler, AdvancedProfiler, PyTorchProfiler])
@pytest.mark.parametrize("cls", [
SimpleProfiler,
PyTorchProfiler,
pytest.param(AdvancedProfiler, marks=skip_advanced_profiler_py312),
])
def test_profiler_teardown(tmp_path, cls):
"""This test checks if profiler teardown method is called when trainer is exiting."""

Expand Down

0 comments on commit f19baea

Please sign in to comment.