Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force cpu usage on macos-latest runners #114

Merged
merged 11 commits into from
May 31, 2024
Merged
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,7 @@ commands =
description =
Run tests
coredev: Run tests with the development version of cellfinder
passenv =
CI
GITHUB_*
"""
24 changes: 24 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os

import pytest
import torch
from cellfinder.core.tools.system import force_cpu


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


@pytest.fixture(scope="session", autouse=True)
def set_device_arm_macos_ci():
"""
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
"""
if (
os.getenv("GITHUB_ACTIONS") == "true"
and torch.backends.mps.is_available()
):
force_cpu()

Check warning on line 24 in tests/conftest.py

View check run for this annotation

Codecov / codecov/patch

tests/conftest.py#L24

Added line #L24 was not covered by tests
Loading