diff --git a/tests/conftest.py b/tests/conftest.py index 976b48ccc..69403937c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -166,3 +166,33 @@ def _manage_distributed_env(request: FixtureRequest, monkeypatch: MonkeyPatch) - def fix_valuehead_cpu_loading(): """Fix valuehead model loading.""" patch_valuehead_model() + + +@pytest.fixture(scope="session", autouse=True) +def bypass_mistral_regex_check(): + """Disable Mistral regex network check. + + Monkey-patch TokenizersBackend._patch_mistral_regex into a no-op. + """ + try: + from transformers.tokenization_utils_fast import TokenizersBackend + except ImportError: + # Very old transformers, nothing to patch + yield + return + + if not hasattr(TokenizersBackend, "_patch_mistral_regex"): + # Method does not exist in this version + yield + return + + # Backup original method + original = TokenizersBackend._patch_mistral_regex + + # Replace with no-op + TokenizersBackend._patch_mistral_regex = lambda cls, tokenizer, *args, **kwargs: tokenizer + + yield + + # Restore original method + TokenizersBackend._patch_mistral_regex = original diff --git a/tests_v1/conftest.py b/tests_v1/conftest.py index adb08d49f..34797227a 100644 --- a/tests_v1/conftest.py +++ b/tests_v1/conftest.py @@ -172,3 +172,33 @@ def _manage_distributed_env(request: FixtureRequest, monkeypatch: MonkeyPatch) - monkeypatch.setattr(torch.cuda, "device_count", lambda: 1) elif CURRENT_DEVICE == "npu": monkeypatch.setattr(torch.npu, "device_count", lambda: 1) + + +@pytest.fixture(scope="session", autouse=True) +def bypass_mistral_regex_check(): + """Disable Mistral regex network check. + + Monkey-patch TokenizersBackend._patch_mistral_regex into a no-op. + """ + try: + from transformers.tokenization_utils_fast import TokenizersBackend + except ImportError: + # Very old transformers, nothing to patch + yield + return + + if not hasattr(TokenizersBackend, "_patch_mistral_regex"): + # Method does not exist in this version + yield + return + + # Backup original method + original = TokenizersBackend._patch_mistral_regex + + # Replace with no-op + TokenizersBackend._patch_mistral_regex = lambda cls, tokenizer, *args, **kwargs: tokenizer + + yield + + # Restore original method + TokenizersBackend._patch_mistral_regex = original