From f9ceb7fa899aea2780b2c8a970681e5418d3902f Mon Sep 17 00:00:00 2001 From: Algorithm5838 <108630393+Algorithm5838@users.noreply.github.com> Date: Wed, 8 Apr 2026 23:21:55 +0300 Subject: [PATCH] perf: skip torch import on non-macOS (#23438) --- backend/open_webui/env.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index e0dcaff276..53737a1f2f 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -60,13 +60,14 @@ if USE_CUDA.lower() == 'true': else: DEVICE_TYPE = 'cpu' -try: - import torch +if sys.platform == 'darwin': + try: + import torch - if torch.backends.mps.is_available() and torch.backends.mps.is_built(): - DEVICE_TYPE = 'mps' -except Exception: - pass + if torch.backends.mps.is_available() and torch.backends.mps.is_built(): + DEVICE_TYPE = 'mps' + except Exception: + pass #################################### # LOGGING