Skip to content

Commit

Permalink
Moved force cpu into cellfinder function (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov authored May 29, 2024
1 parent 4355b95 commit 4ebbd46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 10 additions & 0 deletions cellfinder/core/tools/system.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path

import keras
from brainglobe_utils.general.exceptions import CommandLineInputError


Expand Down Expand Up @@ -80,3 +81,12 @@ def memory_in_bytes(memory_amount, unit):
)
else:
return memory_amount * 10 ** supported_units[unit]


def force_cpu():
"""
Forces the CPU to be used, even if a GPU is available
"""
keras.src.backend.common.global_state.set_global_attribute(
"torch_device", "cpu"
)
6 changes: 2 additions & 4 deletions tests/core/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from typing import Tuple

import keras.src.backend.common.global_state
import numpy as np
import pytest
import torch.backends.mps
Expand All @@ -11,6 +10,7 @@
DEFAULT_DOWNLOAD_DIRECTORY,
download_models,
)
from cellfinder.core.tools.system import force_cpu


@pytest.fixture(scope="session", autouse=True)
Expand All @@ -24,9 +24,7 @@ def set_device_arm_macos_ci():
os.getenv("GITHUB_ACTIONS") == "true"
and torch.backends.mps.is_available()
):
keras.src.backend.common.global_state.set_global_attribute(
"torch_device", "cpu"
)
force_cpu()


@pytest.fixture(scope="session")
Expand Down

0 comments on commit 4ebbd46

Please sign in to comment.