Skip to content

Commit

Permalink
Remove env var from HPUProfiler
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitgola005 committed Mar 5, 2024
1 parent 2404a85 commit 68250d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/lightning_habana/pytorch/profiler/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ def __init__(
record_module_names: bool = True,
**profiler_kwargs: Any,
) -> None:
os.environ["HABANA_PROFILE"] = "1"
assert os.environ.get("HABANA_PROFILE", None) in (
None,
"profile_api_light",
), "`HABANA_PROFILE` should not be set when using `HPUProfiler`"
super().__init__(
dirpath=dirpath,
filename=filename,
Expand Down Expand Up @@ -159,7 +162,3 @@ def on_trace_ready(profiler: _PROFILER) -> None:

def summary(self) -> str:
return "Summary not supported for HPU Profiler"

def teardown(self, stage: Optional[str]) -> None:
super().teardown(stage=stage)
os.environ.pop("HABANA_PROFILE", None)
6 changes: 6 additions & 0 deletions tests/test_pytorch/test_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,9 @@ def test_hpu_trace_event_kernel(tmpdir):
raise Exception("Could not find event kernel in trace")
for event_duration in event_duration_arr:
assert event_duration >= 0


def test_hpu_profiler_env(monkeypatch):
monkeypatch.setenv("HABANA_PROFILE", "1")
with pytest.raises(AssertionError, match="`HABANA_PROFILE` should not be set when using `HPUProfiler`"):
HPUProfiler()

0 comments on commit 68250d0

Please sign in to comment.