From 3b86dc62541640585ebef07416d7c791be3d18ab Mon Sep 17 00:00:00 2001 From: Ivan Date: Sun, 15 Jun 2025 13:52:42 +0400 Subject: [PATCH] fix: fallback to CPU when CUDA is not available Previously, the code unconditionally attempted to move the model to the CUDA device (`self.model.to("cuda")`), which caused a runtime crash on systems where CUDA is not available (e.g., Apple M1/M2 or CPU-only environments). This resulted in the error: AssertionError: Torch not compiled with CUDA enabled The fix introduces a dynamic device selection: device = "cuda" if torch.cuda.is_available() else "cpu" self.model.to(device) This change ensures compatibility across platforms and prevents crashes due to unavailable CUDA devices. --- chat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chat.py b/chat.py index 27e4fe0..4f310f6 100644 --- a/chat.py +++ b/chat.py @@ -93,7 +93,8 @@ class DOLPHIN: ckpt = try_rename_lagacy_weights(ckpt) self.model.load_state_dict(ckpt, strict=True) - self.model.to("cuda") + device = "cuda" if torch.cuda.is_available() else "cpu" + self.model.to(device) self.model.eval() transform_args = { "input_size": self.swin_args["img_size"],