diff --git a/studio/backend/utils/hardware/hardware.py b/studio/backend/utils/hardware/hardware.py index 8d6c919ebd..117ad7b780 100644 --- a/studio/backend/utils/hardware/hardware.py +++ b/studio/backend/utils/hardware/hardware.py @@ -49,6 +49,11 @@ logger = get_logger(__name__) # and spawn workers copy os.environ. setdefault so an explicit user override wins. os.environ.setdefault("CUDA_DEVICE_ORDER", "PCI_BUS_ID") +# Studio workers can import MLX without importing unsloth first, so mirror the +# package bootstrap here. Keep an explicit user value authoritative. +if platform.system() == "Darwin" and platform.machine() == "arm64": + os.environ.setdefault("AGX_RELAX_CDM_CTXSTORE_TIMEOUT", "1") + # ========== Device Enum ========== diff --git a/unsloth/__init__.py b/unsloth/__init__.py index de5cd0f61b..659637dd92 100644 --- a/unsloth/__init__.py +++ b/unsloth/__init__.py @@ -16,6 +16,11 @@ import os, importlib.util, platform os.environ["UNSLOTH_IS_PRESENT"] = "1" +# Relax Metal's context-store timeout before MLX modules can initialize Metal. +# Keep an explicit user value authoritative. +if platform.system() == "Darwin" and platform.machine() == "arm64": + os.environ.setdefault("AGX_RELAX_CDM_CTXSTORE_TIMEOUT", "1") + # ── Windows console UTF-8 safety ───────────────────────────────────────────── # Legacy Windows consoles (cp1252) can't encode Unsloth's emoji/box-drawing # glyphs and crash with UnicodeEncodeError. Force stdout/stderr to UTF-8 only on