unsloth/tests
Daniel Han 1942e58171 tests/studio: comprehensive hardware dispatch matrix
Drives every supported hardware profile from a single test host by
spoofing platform, torch.cuda, torch.xpu, torch.version.hip, and
sys.modules['mlx'] so we can exercise the CUDA, ROCm, XPU, MLX, and CPU
dispatch paths deterministically without owning the actual hardware.

Profiles covered (parametrized; add a row to PROFILES to extend):

  nvidia_cuda           Linux x86_64 + cuda available, hip=None
  amd_rocm              Linux x86_64 + cuda available, hip="6.1"
                        (PyTorch ROCm aliases torch.cuda over HIP)
  intel_xpu             Linux x86_64 + cuda off, xpu available
  apple_silicon_mlx     Darwin arm64 + cuda/xpu off + mlx in sys.modules
  apple_silicon_no_mlx  Darwin arm64 + everything off (Mac chat-only fallback)
  linux_arm64_with_mlx  Linux arm64 + mlx in sys.modules -- canary that the
                        system check still guards against accidental hijack
  cpu_only              Linux x86_64 + nothing -- pure CPU fallback

For each profile the suite asserts:

  1. unsloth._IS_MLX (re-evaluated under the spoof) matches expectation.
  2. utils.hardware.detect_hardware() returns the right DeviceType and
     IS_ROCM flag.
  3. utils.hardware.is_apple_silicon() agrees with the platform spoof.

Plus two negative-space canaries:

  test_cuda_takes_priority_over_mlx_when_both_available
      With CUDA AND MLX both present, dispatch must pick CUDA.
      Protects existing GPU users from a future refactor that
      reorders the dispatch.
  test_xpu_takes_priority_over_mlx_when_both_available
      Same canary for Intel/XPU vs MLX.

All 23 tests pass on Linux+CUDA in 1.8s with no real hardware required.
Future regressions in either the unsloth _IS_MLX gate or Studio's
detect_hardware priority order will fail loudly here.
2026-05-06 10:32:00 +00:00
..
python feat(studio): MLX training tab on Apple Silicon (LoRA / full FT, VLM, export) (#5265) 2026-05-05 23:54:58 -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
sh Default Studio host to 127.0.0.1 and prompt before auto-start (#5267) 2026-05-04 13:03:16 +04:00
studio tests/studio: comprehensive hardware dispatch matrix 2026-05-06 10:32:00 +00:00
utils feat: Add cactus QAT scheme support (#4679) 2026-04-15 07:40:03 -07:00
__init__.py Qwen 3, Bug Fixes (#2445) 2025-04-30 22:38:39 -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_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_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 fix: check find() return value before adding offset in try_fix_tokenizer (#4923) 2026-04-09 06:15:46 -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 install: support STUDIO_HOME / UNSLOTH_STUDIO_HOME for custom install paths (#5190) 2026-05-05 23:17:40 -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