Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
tests: make `pytest tests` collect cleanly and drop the deleted QVQ registry mirror (#8206)
Daniel Han68e5c3f04bf4
diff --git a/tests/saving/gpt-oss-merge/test_merged_model.py b/tests/saving/gpt-oss-merge/test_merged_model.pyindex 024d48f2767..81365d9ff4f 100644--- a/tests/saving/gpt-oss-merge/test_merged_model.py+++ b/tests/saving/gpt-oss-merge/test_merged_model.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+# inference_on_merged.pyfrom unsloth import FastLanguageModelfrom transformers import TextStreamerdiff --git a/tests/saving/language_models/test_merge_4bit_validation.py b/tests/saving/language_models/test_merge_4bit_validation.pyindex 8c1baeecf43..9977fa9fd75 100644--- a/tests/saving/language_models/test_merge_4bit_validation.py+++ b/tests/saving/language_models/test_merge_4bit_validation.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastLanguageModelfrom unsloth.chat_templates import get_chat_templatefrom trl import SFTTrainer, SFTConfigdiff --git a/tests/saving/language_models/test_merge_model_perplexity_llama-3.2.py b/tests/saving/language_models/test_merge_model_perplexity_llama_3_2.pysimilarity index 94%rename from tests/saving/language_models/test_merge_model_perplexity_llama-3.2.pyrename to tests/saving/language_models/test_merge_model_perplexity_llama_3_2.pyindex a549e58562e..7da16c09fb2 100644--- a/tests/saving/language_models/test_merge_model_perplexity_llama-3.2.py+++ b/tests/saving/language_models/test_merge_model_perplexity_llama_3_2.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastLanguageModel, FastVisionModel, UnslothVisionDataCollatorfrom unsloth.chat_templates import get_chat_templatefrom trl import SFTTrainer, SFTConfigdiff --git a/tests/saving/language_models/test_merge_model_perplexity_mistral.py b/tests/saving/language_models/test_merge_model_perplexity_mistral.pyindex 50b0d3caf40..96604689729 100644--- a/tests/saving/language_models/test_merge_model_perplexity_mistral.py+++ b/tests/saving/language_models/test_merge_model_perplexity_mistral.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastLanguageModel, FastVisionModel, UnslothVisionDataCollatorfrom unsloth.chat_templates import get_chat_templatefrom trl import SFTTrainer, SFTConfigdiff --git a/tests/saving/language_models/test_merge_model_perplexity_phi_4.py b/tests/saving/language_models/test_merge_model_perplexity_phi_4.pyindex 9c7f6c77afa..23f83f6e02f 100644--- a/tests/saving/language_models/test_merge_model_perplexity_phi_4.py+++ b/tests/saving/language_models/test_merge_model_perplexity_phi_4.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastLanguageModel, FastVisionModel, UnslothVisionDataCollatorfrom unsloth.chat_templates import get_chat_templatefrom trl import SFTTrainer, SFTConfigdiff --git a/tests/saving/language_models/test_merged_model_perplexity_llama-3.1-8b.py b/tests/saving/language_models/test_merged_model_perplexity_llama_3_1_8b.pysimilarity index 94%rename from tests/saving/language_models/test_merged_model_perplexity_llama-3.1-8b.pyrename to tests/saving/language_models/test_merged_model_perplexity_llama_3_1_8b.pyindex dcbaad13e1f..a80e07da57f 100644--- a/tests/saving/language_models/test_merged_model_perplexity_llama-3.1-8b.py+++ b/tests/saving/language_models/test_merged_model_perplexity_llama_3_1_8b.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastLanguageModel, FastVisionModel, UnslothVisionDataCollatorfrom unsloth.chat_templates import get_chat_templatefrom trl import SFTTrainer, SFTConfigdiff --git a/tests/saving/language_models/test_merged_model_perplexity_qwen_2.5.py b/tests/saving/language_models/test_merged_model_perplexity_qwen_2_5.pysimilarity index 95%rename from tests/saving/language_models/test_merged_model_perplexity_qwen_2.5.pyrename to tests/saving/language_models/test_merged_model_perplexity_qwen_2_5.pyindex cfa364c697f..bec978d083d 100644--- a/tests/saving/language_models/test_merged_model_perplexity_qwen_2.5.py+++ b/tests/saving/language_models/test_merged_model_perplexity_qwen_2_5.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastLanguageModel, FastVisionModel, UnslothVisionDataCollatorfrom unsloth.chat_templates import get_chat_templatefrom trl import SFTTrainer, SFTConfigdiff --git a/tests/saving/language_models/test_push_to_hub_merged.py b/tests/saving/language_models/test_push_to_hub_merged.pyindex 0a1dd3406a1..abf14c54805 100644--- a/tests/saving/language_models/test_push_to_hub_merged.py+++ b/tests/saving/language_models/test_push_to_hub_merged.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastLanguageModel, FastVisionModel, UnslothVisionDataCollatorfrom unsloth.chat_templates import get_chat_templatefrom trl import SFTTrainer, SFTConfigdiff --git a/tests/saving/language_models/test_push_to_hub_merged_sharded_index_file.py b/tests/saving/language_models/test_push_to_hub_merged_sharded_index_file.pyindex a77d35d05f2..cd583d1e271 100644--- a/tests/saving/language_models/test_push_to_hub_merged_sharded_index_file.py+++ b/tests/saving/language_models/test_push_to_hub_merged_sharded_index_file.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastLanguageModel, FastVisionModel, UnslothVisionDataCollatorfrom unsloth.chat_templates import get_chat_templatefrom trl import SFTTrainer, SFTConfigdiff --git a/tests/saving/language_models/test_save_merged_grpo_model.py b/tests/saving/language_models/test_save_merged_grpo_model.pyindex 24a35dc8257..6b0025f525e 100644--- a/tests/saving/language_models/test_save_merged_grpo_model.py+++ b/tests/saving/language_models/test_save_merged_grpo_model.py@@ -1,6 +1,20 @@# -*- coding: utf-8 -*-"""Llama 3.1 (3B) GRPO LoRA train + merged-model save/eval."""+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)++from unsloth import FastLanguageModelimport torchimport sysdiff --git a/tests/saving/non_peft/test_mistral_non_peft.py b/tests/saving/non_peft/test_mistral_non_peft.pyindex 0ace3dd352f..02549d9d831 100644--- a/tests/saving/non_peft/test_mistral_non_peft.py+++ b/tests/saving/non_peft/test_mistral_non_peft.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastLanguageModelfrom transformers import AutoModelForCausalLMfrom peft import PeftModeldiff --git a/tests/saving/non_peft/test_whisper_non_peft.py b/tests/saving/non_peft/test_whisper_non_peft.pyindex 91425d77e48..eb318403d28 100644--- a/tests/saving/non_peft/test_whisper_non_peft.py+++ b/tests/saving/non_peft/test_whisper_non_peft.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastLanguageModel, FastModelfrom transformers import AutoModelForCausalLM, WhisperForConditionalGenerationfrom peft import PeftModeldiff --git a/tests/saving/test_fix_sentencepiece_gguf_robustness.py b/tests/saving/test_fix_sentencepiece_gguf_robustness.pyindex 2b9cc87a604..dd1cc3e02be 100644--- a/tests/saving/test_fix_sentencepiece_gguf_robustness.py+++ b/tests/saving/test_fix_sentencepiece_gguf_robustness.py@@ -4,7 +4,14 @@ import osos.environ.setdefault("PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION", "python")-from transformers.utils import sentencepiece_model_pb2+# Same accessor unsloth.tokenizer_utils uses. The legacy+# `transformers.utils.sentencepiece_model_pb2` is generated against protobuf+# 3.x and raises on protobuf >= 4 ("Descriptors cannot be created directly"),+# or collides with sentencepiece's own copy ("duplicate file name+# sentencepiece_model.proto") once that one is loaded first.+from transformers.convert_slow_tokenizer import import_protobuf++sentencepiece_model_pb2 = import_protobuf()from unsloth.tokenizer_utils import fix_sentencepiece_ggufdiff --git a/tests/saving/test_fix_sentencepiece_tokenizer_guard.py b/tests/saving/test_fix_sentencepiece_tokenizer_guard.pyindex 1ee523d57bc..fa29032aaca 100644--- a/tests/saving/test_fix_sentencepiece_tokenizer_guard.py+++ b/tests/saving/test_fix_sentencepiece_tokenizer_guard.py@@ -5,7 +5,15 @@ import osos.environ.setdefault("PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION", "python")import transformers-from transformers.utils import sentencepiece_model_pb2++# Same accessor unsloth.tokenizer_utils uses. The legacy+# `transformers.utils.sentencepiece_model_pb2` is generated against protobuf+# 3.x and raises on protobuf >= 4 ("Descriptors cannot be created directly"),+# or collides with sentencepiece's own copy ("duplicate file name+# sentencepiece_model.proto") once that one is loaded first.+from transformers.convert_slow_tokenizer import import_protobuf++sentencepiece_model_pb2 = import_protobuf()from unsloth.tokenizer_utils import fix_sentencepiece_tokenizerdiff --git a/tests/saving/text_to_speech_models/test_csm.py b/tests/saving/text_to_speech_models/test_csm.pyindex 7c1a7a275bb..43663ca0eda 100644--- a/tests/saving/text_to_speech_models/test_csm.py+++ b/tests/saving/text_to_speech_models/test_csm.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastLanguageModel, FastModelfrom transformers import CsmForConditionalGenerationimport torchdiff --git a/tests/saving/text_to_speech_models/test_lasa.py b/tests/saving/text_to_speech_models/test_lasa.pyindex eea69ddd0ae..416d0506609 100644--- a/tests/saving/text_to_speech_models/test_lasa.py+++ b/tests/saving/text_to_speech_models/test_lasa.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastLanguageModel, FastModelfrom transformers import CsmForConditionalGenerationimport torchdiff --git a/tests/saving/text_to_speech_models/test_orpheus.py b/tests/saving/text_to_speech_models/test_orpheus.pyindex 99feeeda134..cb27a5bf63f 100644--- a/tests/saving/text_to_speech_models/test_orpheus.py+++ b/tests/saving/text_to_speech_models/test_orpheus.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastLanguageModel, FastModelfrom transformers import CsmForConditionalGenerationimport torchdiff --git a/tests/saving/text_to_speech_models/test_whisper.py b/tests/saving/text_to_speech_models/test_whisper.pyindex a3f41d1833a..a835b58f8c1 100644--- a/tests/saving/text_to_speech_models/test_whisper.py+++ b/tests/saving/text_to_speech_models/test_whisper.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastLanguageModel, FastModelfrom transformers import WhisperForConditionalGeneration, WhisperProcessorimport torchdiff --git a/tests/saving/vision_models/test_index_file_sharded_model.py b/tests/saving/vision_models/test_index_file_sharded_model.pyindex 1a3c1f14931..79a00af4afb 100644--- a/tests/saving/vision_models/test_index_file_sharded_model.py+++ b/tests/saving/vision_models/test_index_file_sharded_model.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastVisionModel, is_bf16_supportedfrom unsloth.trainer import UnslothVisionDataCollatordiff --git a/tests/saving/vision_models/test_push_to_hub_merged.py b/tests/saving/vision_models/test_push_to_hub_merged.pyindex 513546efb42..7dc06f35224 100644--- a/tests/saving/vision_models/test_push_to_hub_merged.py+++ b/tests/saving/vision_models/test_push_to_hub_merged.py@@ -1,3 +1,16 @@+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+## Import required librariesfrom unsloth import FastVisionModel, is_bf16_supporteddiff --git a/tests/saving/vision_models/test_save_merge_qwen2.5vl32B_model_ocr_benchmark.py b/tests/saving/vision_models/test_save_merge_qwen2_5vl32B_model_ocr_benchmark.pysimilarity index 95%rename from tests/saving/vision_models/test_save_merge_qwen2.5vl32B_model_ocr_benchmark.pyrename to tests/saving/vision_models/test_save_merge_qwen2_5vl32B_model_ocr_benchmark.pyindex 65c876e7663..76556606bfd 100644--- a/tests/saving/vision_models/test_save_merge_qwen2.5vl32B_model_ocr_benchmark.py+++ b/tests/saving/vision_models/test_save_merge_qwen2_5vl32B_model_ocr_benchmark.py@@ -1,4 +1,17 @@# -*- coding: utf-8 -*-+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastVisionModeldiff --git a/tests/saving/vision_models/test_save_merge_vision_model_ocr_benchmark.py b/tests/saving/vision_models/test_save_merge_vision_model_ocr_benchmark.pyindex 3305dbc53ca..327940412a1 100644--- a/tests/saving/vision_models/test_save_merge_vision_model_ocr_benchmark.py+++ b/tests/saving/vision_models/test_save_merge_vision_model_ocr_benchmark.py@@ -1,4 +1,17 @@# -*- coding: utf-8 -*-+# tests/saving scripts run their whole body at import, so plain pytest+# collection would download checkpoints and train. Skip unless opted in.+import sys as _sys+from pathlib import Path as _Path++_sys.path.insert(0, str(_Path(__file__).resolve().parents[3]))+from tests.utils.os_utils import require_opt_in as _require_opt_in++_require_opt_in(+ "UNSLOTH_RUN_SAVING_SCRIPTS",+ "GPU + Hub saving script; its body runs at import.",+)+from unsloth import FastVisionModeldiff --git a/tests/test_collection_hygiene.py b/tests/test_collection_hygiene.pynew file mode 100644index 00000000000..f1589d77bd5--- /dev/null+++ b/tests/test_collection_hygiene.py@@ -0,0 +1,92 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.++"""`pytest tests` must collect cleanly.++A collection ERROR is not a failing test: pytest reports "Interrupted" and+never runs the rest of the suite, so one bad module hides thousands of good+ones. These guard the three ways modules under tests/ used to break collection.+"""++from __future__ import annotations++import ast+import subprocess+import sys+from pathlib import Path++import pytest++TESTS_DIR = Path(__file__).resolve().parent+REPO_ROOT = TESTS_DIR.parent+SAVING_DIR = TESTS_DIR / "saving"+++def _test_modules() -> list[Path]:+ return sorted(TESTS_DIR.rglob("test_*.py"))+++def _has_test_items(tree: ast.Module) -> bool:+ for node in tree.body:+ if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and node.name.startswith(+ "test_"+ ):+ return True+ if isinstance(node, ast.ClassDef) and node.name.startswith("Test"):+ return True+ return False+++def test_no_test_module_filename_contains_a_dot():+ """A dot in the stem is a package separator to pytest's importer.++ tests/saving/language_models/test_merged_model_perplexity_qwen_2.5.py was+ imported as ...test_merged_model_perplexity_qwen_2.5 and died with+ "No module named 'test_merged_model_perplexity_qwen_2'".+ """+ dotted = [str(p.relative_to(REPO_ROOT)) for p in _test_modules() if "." in p.stem]+ assert not dotted, f"test module filenames must not contain '.': {dotted}"+++def test_saving_scripts_opt_in_before_running_at_import():+ """Files under tests/saving with no test items are standalone GPU scripts.++ Their whole body runs at import, so bare collection downloads checkpoints,+ trains and pushes to the Hub. Each must call require_opt_in() so it is a+ visible SKIP instead.+ """+ ungated = []+ for path in sorted(SAVING_DIR.rglob("test_*.py")):+ source = path.read_text(encoding = "utf-8")+ if _has_test_items(ast.parse(source)):+ continue+ if "require_opt_in(" not in source:+ ungated.append(str(path.relative_to(REPO_ROOT)))+ assert not ungated, f"tests/saving scripts missing the require_opt_in gate: {ungated}"+++def test_raw_text_does_not_leave_its_datasets_mock_in_sys_modules():+ """tests/test_raw_text.py stubs `datasets` to import unsloth.dataprep.raw_text.++ It used to leave the stub in sys.modules for the rest of the session, so+ every later `from datasets import IterableDataset` raised ImportError and+ tests/utils/test_packing.py failed to collect.+ """+ pytest.importorskip("datasets")+ child = (+ "import runpy, sys\n"+ f"sys.path.insert(0, {str(REPO_ROOT)!r})\n"+ f"runpy.run_path({str(TESTS_DIR / 'test_raw_text.py')!r}, run_name='test_raw_text')\n"+ "from datasets import Dataset, IterableDataset\n"+ "print('DATASETS_OK', Dataset.__module__)\n"+ )+ result = subprocess.run(+ [sys.executable, "-c", child],+ capture_output = True,+ text = True,+ check = False,+ )+ assert (+ "DATASETS_OK" in result.stdout+ ), f"exit {result.returncode}\nstdout:\n{result.stdout}\nstderr:\n{result.stderr}"+ assert "DATASETS_OK datasets." in result.stdout, result.stdoutdiff --git a/tests/test_model_registry.py b/tests/test_model_registry.pyindex 76f462c5cfb..3974357f4c0 100644--- a/tests/test_model_registry.py+++ b/tests/test_model_registry.py@@ -6,7 +6,8 @@ import sysfrom dataclasses import dataclassimport pytest-from huggingface_hub import ModelInfo as HfModelInfo+from huggingface_hub import HfApi+from huggingface_hub.errors import HfHubHTTPError, RepositoryNotFoundErrorfrom unsloth.registry import register_models, search_modelsfrom unsloth.registry._deepseek import register_deepseek_models@@ -16,7 +17,6 @@ from unsloth.registry._mistral import register_mistral_modelsfrom unsloth.registry._phi import register_phi_modelsfrom unsloth.registry._qwen import register_qwen_modelsfrom unsloth.registry.registry import MODEL_REGISTRY, QUANT_TAG_MAP, QuantType-from unsloth.utils.hf_hub import get_model_infoMODEL_NAMES = ["llama",@@ -42,12 +42,41 @@ class ModelTestParam:register_models: callable+class HubUnavailable(Exception):+ """The Hub could not answer, so the registry cannot be judged from here."""+++def _model_is_missing(api: HfApi, model_id: str) -> bool:+ """True when the Hub says the repo does not exist.++ Only RepositoryNotFoundError means "not on the Hub". The suite runs+ unauthenticated in CI, where the Hub answers a private/deleted repo with+ 401 "Invalid username or password" and huggingface_hub maps that to+ RepositoryNotFoundError. A *gated* repo is not in that bucket: its metadata+ is public, so model_info returns 200 and this returns False.++ Anything else (429 rate limit, 5xx, DNS/TLS/timeouts) is a broken+ connection to the Hub, not a broken registry, and must not be reported as+ 129 missing models.+ """+ try:+ api.model_info(model_id, expand = ["lastModified"])+ except RepositoryNotFoundError:+ return True+ except Exception as exc:+ raise HubUnavailable(f"{model_id}: {type(exc).__name__}: {exc}") from exc+ return False++def _test_model_uploaded(model_ids: list[str]):+ api = HfApi()missing_models = []for _id in model_ids:- model_info: HfModelInfo = get_model_info(_id)- if not model_info:- missing_models.append(_id)+ try:+ if _model_is_missing(api, _id):+ missing_models.append(_id)+ except HubUnavailable as exc:+ pytest.skip(f"Hugging Face Hub unavailable: {exc}")return missing_models@@ -162,3 +191,46 @@ def test_register_models_registers_no_upstream_originals():# Deepseek is still registered via the normal path, just without originals.deepseek_lines = [line for line in out.splitlines() if line.startswith("NUM_DEEPSEEK")]assert deepseek_lines and int(deepseek_lines[0].split()[1]) > 0, out + result.stderr+++class _FakeApi:+ def __init__(self, error):+ self.error = error++ def model_info(+ self,+ model_id,+ expand = None,+ ):+ if self.error is not None:+ raise self.error+ return object()+++def test_missing_repo_is_reported_missing():+ """A repo the Hub says does not exist is a registry error."""+ api = _FakeApi(RepositoryNotFoundError("404 Client Error. Repository Not Found"))+ assert _model_is_missing(api, "unsloth/does-not-exist")+++def test_present_repo_is_not_reported_missing():+ assert not _model_is_missing(_FakeApi(None), "unsloth/Qwen2.5-7B")+++ "error",+ [+ HfHubHTTPError("429 Client Error: Too Many Requests"),+ ConnectionError("Failed to establish a new connection"),+ TimeoutError("read timed out"),+ ],+ ids = ["rate_limited", "connection_refused", "timeout"],+)+def test_unreachable_hub_skips_instead_of_reporting_missing(monkeypatch, error):+ """A hub outage must not be reported as every registered model missing."""+ with pytest.raises(HubUnavailable):+ _model_is_missing(_FakeApi(error), "unsloth/Qwen2.5-7B")++ monkeypatch.setattr(sys.modules[__name__], "HfApi", lambda: _FakeApi(error))+ with pytest.raises(pytest.skip.Exception):+ _test_model_uploaded(["unsloth/Qwen2.5-7B"])diff --git a/tests/test_raw_text.py b/tests/test_raw_text.pyindex 5c0155a0a08..4ba55c86423 100644--- a/tests/test_raw_text.py+++ b/tests/test_raw_text.py@@ -37,7 +37,6 @@ class MockDataset:datasets_mock = type(sys)("datasets")datasets_mock.__spec__ = importlib.util.spec_from_loader("datasets", loader = None)datasets_mock.Dataset = MockDataset-sys.modules["datasets"] = datasets_mock# Import raw_text directly to avoid unsloth/__init__.py dependencies.current_dir = os.path.dirname(__file__)@@ -45,7 +44,20 @@ raw_text_path = os.path.join(os.path.dirname(current_dir), "unsloth", "dataprep"spec = importlib.util.spec_from_file_location("raw_text", raw_text_path)raw_text_module = importlib.util.module_from_spec(spec)-spec.loader.exec_module(raw_text_module)++# The mock is only in place while raw_text executes its `from datasets import+# Dataset`. Leaving it in sys.modules poisoned every later test module in the+# same session: `from datasets import IterableDataset` then raised ImportError+# and tests/utils/test_packing.py failed to collect.+_real_datasets = sys.modules.get("datasets")+sys.modules["datasets"] = datasets_mock+try:+ spec.loader.exec_module(raw_text_module)+finally:+ if _real_datasets is None:+ del sys.modules["datasets"]+ else:+ sys.modules["datasets"] = _real_datasetsRawTextDataLoader = raw_text_module.RawTextDataLoaderTextPreprocessor = raw_text_module.TextPreprocessordiff --git a/tests/utils/os_utils.py b/tests/utils/os_utils.pyindex 86bc0c62490..cafb313bc40 100644--- a/tests/utils/os_utils.py+++ b/tests/utils/os_utils.py@@ -13,6 +13,26 @@ def _missing_dependency(message):sys.exit(1)+TRUTHY = ("1", "true", "yes", "on")+++def require_opt_in(env_var, reason):+ """Gate a module-level script so `pytest` skips it instead of executing it.++ Files under tests/saving are standalone scripts: the whole body runs at+ import, so pytest *collection* alone downloads checkpoints, trains and+ pushes to the Hub, and any failure surfaces as a collection ERROR that+ interrupts the entire run. Call this before the heavy imports so the module+ is a visible SKIP unless ``env_var`` is truthy. Running the file directly+ (``python tests/saving/...py``) is unaffected.+ """+ if os.environ.get(env_var, "").strip().lower() in TRUTHY:+ return+ if "pytest" in sys.modules:+ import pytest+ pytest.skip(f"{reason} Set {env_var}=1 to run.", allow_module_level = True)++def detect_package_manager():"""Detect the available package manager"""package_managers = {diff --git a/unsloth/registry/_qwen.py b/unsloth/registry/_qwen.pyindex bc84f901599..8041ff21030 100644--- a/unsloth/registry/_qwen.py+++ b/unsloth/registry/_qwen.py@@ -70,6 +70,9 @@ QwenQwQMeta = ModelMeta()# Qwen QVQ Preview Model Meta+# No QuantType.NONE: the unquantized mirror unsloth/QVQ-72B-Preview was removed+# from the Hub (only unsloth/QVQ-72B-Preview-bnb-4bit remains). The upstream+# Qwen/QVQ-72B-Preview is still registered via include_original_model.QwenQVQPreviewMeta = ModelMeta(org = "Qwen",base_name = "QVQ",@@ -78,7 +81,7 @@ QwenQVQPreviewMeta = ModelMeta(model_sizes = ["72"],model_info_cls = QwenQVQPreviewModelInfo,is_multimodal = True,- quant_types = [QuantType.NONE, QuantType.BNB],+ quant_types = [QuantType.BNB],)