Files
unslothai--unsloth/tests/saving/test_compressed_export_schemes.py
wehub-resource-sync e93507a09c
Lockfile supply-chain audit / lockfile supply-chain audit (push) Has been cancelled
Windows Studio GGUF CI / GPU prebuilt resolves without Visual Studio (push) Has been cancelled
Windows Studio GGUF CI / setup.ps1 unit tests (VS 2026 / CMake guard) (push) Has been cancelled
Windows Studio GGUF CI / real-VS detection (VS 2022) (push) Has been cancelled
Windows Studio GGUF CI / real-VS detection (VS 2026) (push) Has been cancelled
Windows Studio GGUF CI / VC++ runtime detect + install round-trip (windows-2025-vs2026) (push) Has been cancelled
Windows Studio GGUF CI / VC++ runtime detect + install round-trip (windows-latest) (push) Has been cancelled
Windows Studio Update CI / Studio Updating Tests (push) Has been cancelled
Wheel CI / Wheel build + content sanity + import smoke (push) Has been cancelled
Lint CI / Source lint (Python + shell + YAML + JSON + safety nets) (push) Has been cancelled
MLX CI on Mac M1 / dispatch (push) Has been cancelled
Security audit / advisory audit (pip + npm + cargo) (push) Has been cancelled
Security audit / pip scan-packages :: extras (push) Has been cancelled
Security audit / pip scan-packages :: studio (push) Has been cancelled
Security audit / pip scan-packages :: hf-stack (push) Has been cancelled
Security audit / npm scan-packages (Studio frontend tarballs) (push) Has been cancelled
Security audit / workflow-trigger lint (pull_request_target / cache-poisoning) (push) Has been cancelled
Security audit / pytest tests/security (push) Has been cancelled
Security audit / npm provenance + new install-script diff (push) Has been cancelled
Studio API CI / Studio API & Auth Tests (push) Has been cancelled
Backend CI / (Python 3.10) (push) Has been cancelled
Backend CI / (Python 3.11) (push) Has been cancelled
Backend CI / (Python 3.12) (push) Has been cancelled
Backend CI / (Python 3.13) (push) Has been cancelled
Backend CI / Repo tests (CPU) (push) Has been cancelled
Frontend CI / Frontend build + bundle sanity (push) Has been cancelled
Studio GGUF CI / OpenAI, Anthropic API tests (push) Has been cancelled
Studio GGUF CI / Tool calling Tests (push) Has been cancelled
Studio GGUF CI / JSON, images (push) Has been cancelled
Mac Studio GGUF CI / OpenAI, Anthropic API tests (push) Has been cancelled
Mac Studio GGUF CI / Tool calling Tests (push) Has been cancelled
Mac Studio GGUF CI / JSON, images (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-14) (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-15) (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-26) (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-15-intel) (push) Has been cancelled
Mac Studio API CI / Studio API & Auth Tests (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-26-intel) (push) Has been cancelled
Mac Studio UI CI / Chat UI Tests (push) Has been cancelled
Studio Tauri CI / Tauri Linux debug build (no codesign) (push) Has been cancelled
Mac Studio Update CI / Studio Updating Tests (push) Has been cancelled
Studio UI CI / Chat UI Tests (push) Has been cancelled
Windows Studio API CI / Studio API & Auth Tests (push) Has been cancelled
Windows Studio UI CI / Chat UI Tests (push) Has been cancelled
Studio Update CI / Studio Updating Tests (push) Has been cancelled
Core / Core (HF=default + TRL=default) (push) Has been cancelled
Core / Core (HF=4.57.6 + TRL<1) (push) Has been cancelled
Core / Core (HF=latest + TRL=latest) (push) Has been cancelled
Core / llama.cpp build + smoke (push) Has been cancelled
Windows Studio GGUF CI / OpenAI, Anthropic API tests (push) Has been cancelled
Windows Studio GGUF CI / Tool calling Tests (push) Has been cancelled
Windows Studio GGUF CI / JSON, images (push) Has been cancelled
Windows Studio GGUF CI / Studio install + inference without Visual Studio (push) Has been cancelled
Studio export capability / capability (macos-latest) (push) Has been cancelled
Studio export capability / capability (ubuntu-latest) (push) Has been cancelled
Studio export capability / capability (windows-latest) (push) Has been cancelled
Cross-platform parity / parity (macos-latest) (push) Has been cancelled
Cross-platform parity / parity (windows-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Studio load-orchestrator CI / test (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:59:56 +08:00

70 lines
3.0 KiB
Python

"""CPU-only, deterministic checks for the compressed-tensors export registry and the
`save_method` normalization logic.
No GPU, no model load, no torch math - just the pure routing logic - so a registry or
alias regression is caught fast on CPU-only CI.
"""
from __future__ import annotations
import pytest
from unsloth.save import COMPRESSED_EXPORT_SCHEMES, _normalize_compressed_method
def test_registry_entries_are_well_formed():
assert COMPRESSED_EXPORT_SCHEMES, "compressed export registry must not be empty"
for alias, value in COMPRESSED_EXPORT_SCHEMES.items():
assert (
isinstance(alias, str) and alias == alias.lower()
), f"alias must be a lowercase str: {alias!r}"
assert (
isinstance(value, tuple) and len(value) == 3
), f"{alias!r} must map to a (scheme, needs_calib, suffix) tuple"
scheme, needs_calib, suffix = value
assert isinstance(scheme, str) and scheme, f"{alias!r}: scheme must be a non-empty str"
assert isinstance(needs_calib, bool), f"{alias!r}: needs_calibration must be a bool"
assert isinstance(suffix, str) and suffix, f"{alias!r}: suffix must be a non-empty str"
# The suffix builds the sibling output dir "<save_dir>-<suffix>"; keep it path-safe.
assert not (
set(suffix) & set("/\\ ")
), f"{alias!r}: suffix {suffix!r} must be filesystem-safe"
def test_every_alias_round_trips_case_and_separator_insensitive():
for alias, value in COMPRESSED_EXPORT_SCHEMES.items():
assert _normalize_compressed_method(alias) == value
assert _normalize_compressed_method(alias.upper()) == value
# users may pass dashes / surrounding whitespace
assert _normalize_compressed_method(f" {alias.replace('_', '-')} ") == value
@pytest.mark.parametrize(
"method", ["merged_16bit", "16bit", "merged_4bit", "lora", "", None, 123, ["fp8"]]
)
def test_standard_save_methods_are_not_treated_as_compressed(method):
assert _normalize_compressed_method(method) is None
@pytest.mark.parametrize(
"method", ["fp8_turbo", "nvfp4_xl", "w4a99", "mxfp3", "int8_banana", "fp4_max"]
)
def test_near_miss_compressed_names_raise(method):
# Names that clearly intend a compressed scheme but are unsupported must fail loudly,
# not fall through to the generic "unknown save_method" path.
with pytest.raises(RuntimeError):
_normalize_compressed_method(method)
def test_calibration_flags_match_known_schemes():
# Only static FP8 and NVFP4 require calibration data; everything else is data-free.
assert _normalize_compressed_method("fp8")[1] is False
assert _normalize_compressed_method("fp8_static")[1] is True
assert _normalize_compressed_method("nvfp4")[1] is True
assert _normalize_compressed_method("mxfp4")[1] is False
def test_core_aliases_present():
for alias in ("fp8", "fp8_dynamic", "fp8_static", "mxfp4", "nvfp4", "int8", "w4a16", "w8a8"):
assert alias in COMPRESSED_EXPORT_SCHEMES, f"expected core alias {alias!r} in registry"