From 825a3aff01bedccee7abf17df7074bbe15efa743 Mon Sep 17 00:00:00 2001 From: st1vms <96783398+st1vms@users.noreply.github.com> Date: Tue, 31 Oct 2023 17:19:06 +0100 Subject: [PATCH 1/2] [SDContext] fallback device configuration --- sdkit/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sdkit/__init__.py b/sdkit/__init__.py index 26e6c96..849f346 100644 --- a/sdkit/__init__.py +++ b/sdkit/__init__.py @@ -1,9 +1,15 @@ from threading import local - +from torch.cuda import is_available as cuda_available +from .utils import log class Context(local): def __init__(self) -> None: - self._device: str = "cuda:0" + + self._device: str = 'cuda:0' + if not cuda_available(): + log.warning("CUDA device not found, fallback to cpu device.") + self._device: str = 'cpu' + self._half_precision: bool = True self._vram_usage_level = None From 2dda24044e89dba3d5d9c77c7e949e853da08b9a Mon Sep 17 00:00:00 2001 From: Stefano Raneri <96783398+st1vms@users.noreply.github.com> Date: Wed, 1 Nov 2023 00:30:20 +0100 Subject: [PATCH 2/2] Update __init__.py Circular import fix `from .utils import log` when running proof of concept. --- sdkit/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdkit/__init__.py b/sdkit/__init__.py index 849f346..e81fbe5 100644 --- a/sdkit/__init__.py +++ b/sdkit/__init__.py @@ -1,13 +1,13 @@ from threading import local from torch.cuda import is_available as cuda_available -from .utils import log +from logging import getLogger class Context(local): def __init__(self) -> None: self._device: str = 'cuda:0' if not cuda_available(): - log.warning("CUDA device not found, fallback to cpu device.") + getLogger('sdkit').warning("CUDA device not found, fallback to cpu device.") self._device: str = 'cpu' self._half_precision: bool = True