unsloth/tests
Daniel Han 43d9473004
tests: import_fixes drift detectors (HARD GATE on Core matrix) (#5414)
* tests: import_fixes drift detectors (HARD GATE on Core matrix)

Ports zoo PR #637's drift-detector pattern to unsloth as a new
test file + Core matrix step.

Background
  unsloth/import_fixes.py is a 1932-line catalog of hand-rolled
  patches for upstream regressions: protobuf MessageFactory drift,
  datasets 4.4.x recursion, TRL tuple-vs-bool _*_available caching,
  transformers PreTrainedModel.enable_input_require_grads source
  pattern flip, triton CompiledKernel num_ctas missing, peft
  weight-converter ctor compat, torch/torchvision pairing, vllm
  guided_decoding params, etc. Today each fix runs unconditionally
  at unsloth import; that's defensively correct but it means:
    a fix becoming a no-op (upstream silently fixed itself) is
      invisible.
    a fix becoming needed-but-broken (upstream drifted in a new
      way the workaround doesn't match) only surfaces as a
      downstream crash.

tests/test_import_fixes_drift.py (18 tests)
  One drift detector per fix_* / patch_* function in import_fixes.py.
  Each test asserts the HEALTHY upstream shape absent the regression.
  When the pathology is currently ACTIVE, fires
  pytest.fail("DRIFT DETECTED: <fix function> needed because
  <observation>") -- NEVER pytest.skip. CI must go RED so the
  maintainer triages on the next PR.

  First run on the current install surfaces 3 active drifts:
    peft.utils.transformers_weight_conversion unimportable
      (transformers.conversion_mapping missing) -- patch_peft_
      weight_converter_compatibility will silently no-op.
    triton 3.5.1 CompiledKernel lacks num_ctas + cluster_dims --
      fix_triton_compiled_kernel_missing_attrs is live-needed.
    vllm exposes only StructuredOutputsParams, not
      GuidedDecodingParams -- fix_vllm_guided_decoding_params
      is live-needed.

CI wiring (.github/workflows/consolidated-tests-ci.yml)
  New step `import_fixes drift detectors (18 tests, HARD GATE)`
  added to the Core matrix BEFORE the Bucket-A tests, so the matrix
  cell fails fast on a real upstream regression. No
  continue-on-error: a drift detection MUST go red.

This mirrors the same change just landed on
unslothai/unsloth-zoo#637 (commit ff5a3d8). Same fail-loud-on-drift
semantic; same set of fix functions covered; same 1:1 mapping
between test + import_fixes.py source-of-truth function.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* chore: trim verbose docstrings in import_fixes drift detectors

Strictly comment / docstring trims. AST-verified comment-only.

* Module header: 36 lines -> 7 lines.
* Per-test docstring: collapse each 7-15 line prose block to a 1-3
  line lead naming the import_fixes.py function + line range plus
  the one-sentence why; pytest.fail messages stay verbatim so a
  red CI cell still names the upstream regression.
* Helper docstrings (_safe_version, _is_custom_torch_build): drop.
* Inline narrative comments inside test bodies: drop.
* Section dividers and licence header: untouched.

Net: 700 -> 537 lines, zero behaviour changes.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-05-14 04:33:46 -07:00
..
notebooks CI: scope GITHUB_TOKEN permissions, add MLX CI, unblock ~60 skipped tests (#5312) 2026-05-11 03:19:13 -07:00
python fix: unblock 4 tests deselected/skipped in #5312 (real bugs) (#5359) 2026-05-11 02:39:17 -07:00
qlora Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks" 2025-12-01 07:24:58 -08:00
saving chore: fix typo cleanup across tests and backend strings (#5152) 2026-04-24 12:51:27 +01:00
security security: NOT affected by Mini Shai-Hulud (May-12 wave) -- forward-looking hardening only (#5397) 2026-05-13 04:58:12 -07:00
sh fix(tests/sh): accept pinned tokenizers line after #5359 (#5361) 2026-05-11 02:58:20 -07:00
studio studio: security and hardening pass (auth rate-limit, sandbox, path containment, schema validation, headers) (#5375) 2026-05-13 06:12:18 -07:00
utils feat: Add cactus QAT scheme support (#4679) 2026-04-15 07:40:03 -07:00
version_compat CI: scope GITHUB_TOKEN permissions, add MLX CI, unblock ~60 skipped tests (#5312) 2026-05-11 03:19:13 -07:00
vllm_compat CI: scope GITHUB_TOKEN permissions, add MLX CI, unblock ~60 skipped tests (#5312) 2026-05-11 03:19:13 -07:00
__init__.py Qwen 3, Bug Fixes (#2445) 2025-04-30 22:38:39 -07:00
_zoo_aggressive_cuda_spoof.py CI: scope GITHUB_TOKEN permissions, add MLX CI, unblock ~60 skipped tests (#5312) 2026-05-11 03:19:13 -07:00
conftest.py chore: trim verbose comments added in PR #5416 (commit 12295c1f) (#5418) 2026-05-14 04:25:23 -07:00
run_all.sh fix: add tokenizers to no-torch deps and TORCH_CONSTRAINT for arm64 macOS py313+ (#4748) 2026-04-01 06:12:17 -07:00
test_cli_export_unpacking.py studio: stream export worker output into the export dialog (#4897) 2026-04-14 08:55:43 -07:00
test_gemma4_chat_template.py update gema4 chat templates (#5116) 2026-04-22 09:04:08 -07:00
test_get_model_name.py feat: Add support for OLMo-3 model (#4678) 2026-04-15 07:39:11 -07:00
test_import_fixes_drift.py tests: import_fixes drift detectors (HARD GATE on Core matrix) (#5414) 2026-05-14 04:33:46 -07:00
test_loader_glob_skip.py Add unit tests for HfFileSystem glob skip guard (#4854) 2026-04-06 08:54:36 -07:00
test_model_registry.py Revert "[FIX] Vllm guided decoding params (#3662)" 2025-12-01 05:43:45 -08:00
test_multi_image_grpo_chunking.py Multi Image GRPO (#5197) 2026-05-13 04:27:49 -07:00
test_peft_weight_converter_compat.py Patch checkpoint reload init functions to strip unsupported args (#5167) 2026-04-29 02:50:49 -07:00
test_raw_text.py Add Studio PR-time CI: pin enforcement, frontend, backend, wheel smoke (#5298) 2026-05-06 04:41:57 -07:00
test_resolve_model_class.py fix: guard resolve_model_class fallback against unresolvable transformers AutoModel entries (#5155) 2026-04-24 05:59:17 -07:00
test_studio_install_workspace_guard.py studio: security and hardening pass (auth rate-limit, sandbox, path containment, schema validation, headers) (#5375) 2026-05-13 06:12:18 -07:00
test_studio_root_resilience.py install: support STUDIO_HOME / UNSLOTH_STUDIO_HOME for custom install paths (#5190) 2026-05-05 23:17:40 -07:00