Skip to content

Commit 48e0f41

Browse files
psiddhfacebook-github-bot
authored andcommitted
Fix failing tests: partitioner Python 3.12 compat + Vulkan hardshrink skip (pytorch#19281)
Summary: Fix two test failures for the ai_infra_mobile_platform oncall: 1. test_partitioner_with_spec: Python 3.12 changed the AttributeError message for property setters from "can't set attribute 'spec'" to "property 'spec' of '...' object has no setter". Updated the assertRaisesRegex pattern to match both versions. 2. test_vulkan_backend_hardshrink (and 7 other swiftshader-incompatible tests): Replaced unconditional `unittest.skip` with a conditional `skip_if_swiftshader` decorator that detects swiftshader via env var (`ETVK_USING_SWIFTSHADER`), VK_ICD_FILENAMES, or loaded library check. Tests will now run on real Vulkan drivers (non-swiftshader environments) while still skipping in CI where swiftshader is used. Differential Revision: D103628836
1 parent 0a113f8 commit 48e0f41

2 files changed

Lines changed: 33 additions & 12 deletions

File tree

backends/vulkan/test/test_vulkan_delegate.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# pyre-unsafe
88

99
import ctypes
10+
import os
1011
import unittest
1112
from typing import Tuple
1213

@@ -41,6 +42,29 @@
4142
except:
4243
pass
4344

45+
def _is_using_swiftshader() -> bool:
46+
try:
47+
if os.environ.get("ETVK_USING_SWIFTSHADER", "0") in ("1", "True"):
48+
return True
49+
vk_icd = os.environ.get("VK_ICD_FILENAMES", "")
50+
if "swiftshader" in vk_icd.lower():
51+
return True
52+
RTLD_NOLOAD = 4
53+
for lib_name in ("libvk_swiftshader.so", "libvk_swiftshader_fbcode.so"):
54+
try:
55+
ctypes.CDLL(lib_name, mode=RTLD_NOLOAD)
56+
return True
57+
except Exception:
58+
continue
59+
return False
60+
except Exception:
61+
return True
62+
63+
skip_if_swiftshader = unittest.skipIf(
64+
_is_using_swiftshader(),
65+
"Not compatible with swiftshader",
66+
)
67+
4468

4569
def lower_module(
4670
model: torch.nn.Module, sample_inputs: Tuple[torch.Tensor], dynamic_shapes=None
@@ -590,6 +614,7 @@ def forward(self, x):
590614

591615
self.lower_unary_module_and_test_output(SqrtModule())
592616

617+
@skip_if_swiftshader
593618
def test_vulkan_backend_hardshrink(self):
594619
class HardshrinkModule(torch.nn.Module):
595620
def __init__(self):
@@ -1028,7 +1053,7 @@ def forward(self, x):
10281053
sample_inputs,
10291054
)
10301055

1031-
@unittest.skip("layer norm compute shader not working with swiftshader")
1056+
@skip_if_swiftshader
10321057
def test_vulkan_backend_native_layer_norm(self):
10331058
class NativeLayerNormModule(torch.nn.Module):
10341059
def __init__(self):
@@ -1459,9 +1484,7 @@ def forward(self, x):
14591484
sample_inputs,
14601485
)
14611486

1462-
@unittest.skip(
1463-
"Softmax shader with shared memory does not work with swiftshader due to potential swiftshader bug"
1464-
)
1487+
@skip_if_swiftshader
14651488
def test_vulkan_backend_softmax(self):
14661489
class SoftmaxModule(torch.nn.Module):
14671490
def __init__(self):
@@ -1480,9 +1503,7 @@ def forward(self, x):
14801503
sample_inputs,
14811504
)
14821505

1483-
@unittest.skip(
1484-
"Softmax shader with shared memory does not work with swiftshader due to potential swiftshader bug"
1485-
)
1506+
@skip_if_swiftshader
14861507
def test_vulkan_backend_logsoftmax(self):
14871508
class LogSoftmaxModule(torch.nn.Module):
14881509
def __init__(self):
@@ -2364,7 +2385,7 @@ def apply_quantization(self):
23642385
quantized_linear_module_gemm, sample_inputs_gemm, atol=1e-2, rtol=1e-2
23652386
)
23662387

2367-
@unittest.skip("Cannot run on swiftshader due to no integer dot product support")
2388+
@skip_if_swiftshader
23682389
def test_vulkan_backend_xnnpack_pt2e_quantized_linear_sequence(self):
23692390
"""
23702391
Test a sequence of linear layers quantized with XNNPACK quantization config.
@@ -2439,7 +2460,7 @@ def forward(self, x):
24392460
rtol=1e-1,
24402461
)
24412462

2442-
@unittest.skip("Cannot run on swiftshader due to no integer dot product support")
2463+
@skip_if_swiftshader
24432464
def test_vulkan_backend_xnnpack_pt2e_quantized_conv_sequence(self):
24442465
"""
24452466
Test a sequence of convolution layers quantized with PT2E quantization.
@@ -2530,7 +2551,7 @@ def forward(self, x):
25302551
rtol=1e-1,
25312552
)
25322553

2533-
@unittest.skip("Cannot run on swiftshader due to no integer dot product support")
2554+
@skip_if_swiftshader
25342555
def test_vulkan_backend_xnnpack_pt2e_quantized_conv_sequence_all_reduced(self):
25352556
"""
25362557
Test a sequence of convolution layers quantized with PT2E quantization.
@@ -2610,7 +2631,7 @@ def forward(self, x):
26102631
rtol=1e-1,
26112632
)
26122633

2613-
@unittest.skip("Cannot run on swiftshader due to no 8-bit int support")
2634+
@skip_if_swiftshader
26142635
def test_vulkan_backend_torchao_8da4w_quantized_linear(self):
26152636
"""
26162637
Test TorchAO 8da4w quantization (int8 dynamic activation + int4 weight) with Vulkan backend.

exir/backend/test/test_partitioner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def partition(
106106

107107
with self.assertRaisesRegex(
108108
AttributeError,
109-
"can't set attribute 'spec'",
109+
"can't set attribute 'spec'|has no setter",
110110
):
111111
my_partitioner.spec = {"new_key": "new_value"}
112112

0 commit comments

Comments
 (0)