Skip to content

Commit

Permalink
Force cpu usage on macos-latest runners (#114)
Browse files Browse the repository at this point in the history
* Force cpu usage on macos-latest runners

* Moved torch_device setting to root conftest

* Go back to setting keras global state in brainglobe-workflows

* Force backend env variable to be set with a fixture before importing keras

* Add input that should cause an error only on macos-latest

* Run set_device_arm_macos_ci on all darwin platforms

* Try using the CI variable instead

* Pass GITHUB_* env variables via tox

* Moved passenv to the bottom of testenv to match other pyproject files

* Use force_cpu function from cellfinder

* Removed manual setting of GITHUB_ACTIONS
  • Loading branch information
IgorTatarnikov committed May 31, 2024
1 parent 2cf2020 commit 062bb53
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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()

0 comments on commit 062bb53

Please sign in to comment.