From bc5faa205355cd4e8c683363a04d7a2603b336e5 Mon Sep 17 00:00:00 2001 From: Jamie Pine Date: Tue, 21 Apr 2026 21:17:33 -0700 Subject: [PATCH] fix(offline): install mistral-regex patch for non-MLX backends The previous commit left the patch wired only through ``mlx_backend.py``'s existing import of ``hf_offline_patch``. On Windows/Linux/CUDA users who never load the MLX backend (everyone who hit #526), the patch module was never imported, so ``patch_transformers_mistral_regex`` never ran and the crash persisted. Hoist the import into ``backends/__init__.py``. Every backend imports from this package, so the module-level patch install runs before any ``from_pretrained`` call regardless of which engine the user picks. Caught by CodeRabbit and Cursor Bugbot on #530. --- backend/backends/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/backends/__init__.py b/backend/backends/__init__.py index e90311c4..b2eeb678 100644 --- a/backend/backends/__init__.py +++ b/backend/backends/__init__.py @@ -5,6 +5,13 @@ Provides a unified interface for MLX and PyTorch backends, and a model config registry that eliminates per-engine dispatch maps. """ +# Install HF compatibility patches before any backend imports transformers / +# huggingface_hub. The module runs ``patch_transformers_mistral_regex`` at +# import time, which wraps transformers' tokenizer load against the +# unconditional HuggingFace metadata call that otherwise raises on +# HF_HUB_OFFLINE=1 and on network failures. +from ..utils import hf_offline_patch # noqa: F401 + import threading from dataclasses import dataclass, field from typing import Protocol, Optional, Tuple, List