Skip to content

Commit

Permalink
Switched to using pytest_sessionstart instead of an autouse fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov committed May 29, 2024
1 parent a31ee29 commit e58e112
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@
import torch.backends.mps


@pytest.fixture(scope="session", autouse=True)
def set_backend():
os.environ["KERAS_BACKEND"] = "torch"
yield


@pytest.fixture(scope="session", autouse=True)
def set_device_arm_macos_ci():
def pytest_sessionstart(session):
"""
Ensure that the device is set to CPU when running on arm based macOS
GitHub runners. This is to avoid the following error:
https://discuss.pytorch.org/t/mps-back-end-out-of-memory-on-github-action/189773/5
"""
os.environ["KERAS_BACKEND"] = "torch"

if (
os.getenv("GITHUB_ACTIONS") == "true"
and torch.backends.mps.is_available()
Expand All @@ -26,5 +21,3 @@ def set_device_arm_macos_ci():
keras.src.backend.common.global_state.set_global_attribute(
"torch_device", "cpu"
)

yield

0 comments on commit e58e112

Please sign in to comment.