Fix studio crash on Mac by deferring unsloth_zoo import

Move `from unsloth_zoo.rl_environments import check_signal_escape_patterns`
from module-level to inside `_check_code_safety()` and wrap it in a
try/except for NotImplementedError. The top-level import triggers
`unsloth_zoo.__init__` which calls `get_device_type()` at module scope,
raising NotImplementedError on Apple Silicon. On Mac the safety check
gracefully skips since unsloth_zoo is unavailable, while GGUF inference
via llama.cpp continues to work.
This commit is contained in:
Daniel Han 2026-03-18 15:58:00 +00:00
commit 973532786a

View file

@ -17,7 +17,6 @@ import tempfile
import threading
from loggers import get_logger
from unsloth_zoo.rl_environments import check_signal_escape_patterns
logger = get_logger(__name__)
@ -171,6 +170,11 @@ def _check_code_safety(code: str) -> str | None:
Returns an error message string if the code is unsafe, or None if OK.
"""
# Check for signal/timeout escape patterns
try:
from unsloth_zoo.rl_environments import check_signal_escape_patterns
except (ImportError, NotImplementedError):
# unsloth_zoo may not be available or may fail on non-GPU platforms (e.g. Mac)
return None
safe, info = check_signal_escape_patterns(code)
if not safe:
reasons = [