mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-08-29 22:20:36 +02:00
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
"""Web-application contracts for configurable model loading."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.operator_ui
|
|
def test_ui_resolves_auto_explicit_bfloat16_and_invalid_hardware():
|
|
"""Exercise app helpers in isolation from Gradio's import-time sockets."""
|
|
script = r'''
|
|
from unittest.mock import Mock
|
|
import torch
|
|
import app
|
|
|
|
app.dev.get_device = lambda _requested="auto": "cuda:0"
|
|
app.dev.supports_bfloat16 = lambda _device=None: True
|
|
app.dev.supports_bitsandbytes = lambda _device=None: True
|
|
|
|
automatic = Mock(return_value="4bit")
|
|
app._should_quantize = automatic
|
|
settings = app._resolve_ui_load_settings(
|
|
"Qwen/Qwen3.8-27B", True, "Auto (default)", "Auto (default)",
|
|
)
|
|
assert settings.quantization == "4bit"
|
|
assert settings.dtype == "float16"
|
|
automatic.assert_called_once_with(
|
|
"Qwen/Qwen3.8-27B", is_preset=True, dtype="float16",
|
|
)
|
|
|
|
automatic = Mock(side_effect=AssertionError("automatic policy must not run"))
|
|
app._should_quantize = automatic
|
|
settings = app._resolve_ui_load_settings(
|
|
"Qwen/Qwen3.8-27B", True, "None", "BF16",
|
|
)
|
|
assert settings.quantization is None
|
|
assert settings.dtype == "bfloat16"
|
|
assert app._checkpoint_load_kwargs(settings) == {"torch_dtype": torch.bfloat16}
|
|
automatic.assert_not_called()
|
|
|
|
app.dev.supports_bfloat16 = lambda _device=None: False
|
|
try:
|
|
app._resolve_ui_load_settings("org/model", False, "None", "BF16")
|
|
except ValueError as exc:
|
|
assert "BF16 is not supported" in str(exc)
|
|
assert "FP16 or FP32" in str(exc)
|
|
else:
|
|
raise AssertionError("unsupported BF16 must fail before pipeline construction")
|
|
'''
|
|
result = subprocess.run(
|
|
[sys.executable, "-c", script],
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=60,
|
|
check=False,
|
|
)
|
|
assert result.returncode == 0, result.stdout + result.stderr
|