|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 | from music_assistant_models.enums import MediaType |
8 | | -from music_assistant_models.errors import MusicAssistantError |
| 8 | +from music_assistant_models.errors import MusicAssistantError, SetupFailedError |
9 | 9 | from zeroconf import InterfaceChoice, IPVersion |
10 | 10 |
|
11 | 11 | from music_assistant.helpers import uri, util |
@@ -393,3 +393,42 @@ def test_get_zeroconf_args_all_interfaces() -> None: |
393 | 393 | assert result["ip_version"] == IPVersion.All |
394 | 394 | assert isinstance(result["interfaces"], list) |
395 | 395 | assert "192.168.1.10" in result["interfaces"] |
| 396 | + |
| 397 | + |
| 398 | +@pytest.mark.parametrize( |
| 399 | + ("machine", "capability", "should_raise"), |
| 400 | + [ |
| 401 | + ("x86_64", "DEFAULT", True), |
| 402 | + ("AMD64", "DEFAULT", True), |
| 403 | + ("x86_64", "NO AVX", True), |
| 404 | + ("x86_64", "AVX2", False), |
| 405 | + ("x86_64", "AVX512", False), |
| 406 | + # a future torch capability string we don't know about yet must fail open |
| 407 | + ("x86_64", "AVX10", False), |
| 408 | + ], |
| 409 | +) |
| 410 | +def test_verify_cpu_supports_ml_inference_x86( |
| 411 | + machine: str, capability: str, should_raise: bool |
| 412 | +) -> None: |
| 413 | + """x86 CPUs require AVX2/AVX512 for torch's FBGEMM quantized inference.""" |
| 414 | + with ( |
| 415 | + patch("music_assistant.helpers.util.platform.machine", return_value=machine), |
| 416 | + patch("torch.backends.cpu.get_cpu_capability", return_value=capability), |
| 417 | + ): |
| 418 | + if should_raise: |
| 419 | + with pytest.raises(SetupFailedError): |
| 420 | + util.verify_cpu_supports_ml_inference() |
| 421 | + else: |
| 422 | + util.verify_cpu_supports_ml_inference() |
| 423 | + |
| 424 | + |
| 425 | +def test_verify_cpu_supports_ml_inference_arm() -> None: |
| 426 | + """ARM machines pass without consulting torch (QNNPACK backend works there).""" |
| 427 | + with ( |
| 428 | + patch("music_assistant.helpers.util.platform.machine", return_value="aarch64"), |
| 429 | + patch( |
| 430 | + "torch.backends.cpu.get_cpu_capability", |
| 431 | + side_effect=AssertionError("torch must not be consulted on ARM"), |
| 432 | + ), |
| 433 | + ): |
| 434 | + util.verify_cpu_supports_ml_inference() |
0 commit comments