Skip to content

Commit

Permalink
Moved torch_device setting to root conftest
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov committed May 30, 2024
1 parent 1c94736 commit 519c7c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
17 changes: 0 additions & 17 deletions tests/brainmapper/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import os
import pathlib
import sys

import pytest
import torch
from brainglobe_utils.general.config import get_config_obj
from cellfinder.core.download.cli import main as cellfinder_download
from cellfinder.core.tools.system import force_cpu

test_data_dir = pathlib.Path(__file__) / ".." / ".." / "data"
data_dir = test_data_dir / "brain"
Expand All @@ -15,20 +12,6 @@
TEST_ATLAS = "allen_2017_100um"


@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()


def download_atlas(directory):
download_args = [
"cellfinder_download",
Expand Down
19 changes: 19 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os

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


@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 19 in tests/conftest.py

View check run for this annotation

Codecov / codecov/patch

tests/conftest.py#L19

Added line #L19 was not covered by tests

0 comments on commit 519c7c6

Please sign in to comment.