Skip to content

Commit afc7957

Browse files
msluszniakSS-JIA
authored andcommitted
Vulkan: do not partition constant_pad_nd with a symbolic pad
A pad amount derived from a dynamic dimension is serialized as a VALUELIST of Int/SymInt, and Pad.cpp reads the list with get_int_list(), which requires a literal IntList. The partitioner claims the node regardless, so the model lowers and then aborts at prepack: Exception raised from toIntList at .../graph/containers/Value.h:272: (isIntList()) is false! Expected value to have type IntList, got VALUELIST This is reachable from ordinary code. Any model that pads a dynamic sequence up to the static length its LSTM wants hits it, which is how kokoro's synthesizer fails: `F.pad(x, (0, 0, 0, target - seq_len))`. Supporting it properly is more than swapping in extract_int_or_symint_list(), the way Split.cpp, View.cpp and Expand.cpp read their symbolic lists. add_constant_pad_nd_node() folds the amounts into a per-dim offset and bakes that into a params buffer at build time, so the dispatch would use stale offsets even if the list were read symbolically; the buffer has to be refreshed on resize first. Decline the node until then, so it falls back rather than aborting. The existing test_vulkan_backend_constant_pad_nd pads by a literal (1, 2, 3, 4, 5, 6), so no test covered a symbolic pad. The new case aborts on main and falls back cleanly with this change.
1 parent 5c5c9ee commit afc7957

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

‎backends/vulkan/op_registry.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,12 +1507,34 @@ def register_arange():
15071507
# =============================================================================
15081508

15091509

1510+
def _check_pad_is_static(node: torch.fx.Node) -> bool:
1511+
"""Only support constant_pad_nd when the pad amounts are static.
1512+
1513+
A symbolic pad list is serialized as a VALUELIST rather than an INTLIST, and
1514+
Pad.cpp reads it with get_int_list(), which throws "Expected value to have
1515+
type IntList, got VALUELIST instead".
1516+
1517+
Supporting it properly is more than swapping in
1518+
extract_int_or_symint_list(), the way Split.cpp, View.cpp and Expand.cpp
1519+
read their symbolic lists: add_constant_pad_nd_node() folds the amounts into
1520+
a per-dim offset and bakes that into a params buffer at BUILD time, so the
1521+
dispatch would still use stale offsets even if the list were read
1522+
symbolically. The buffer has to be refreshed on resize first. Decline the
1523+
node until then.
1524+
"""
1525+
pad = node.args[1]
1526+
if not isinstance(pad, (list, tuple)):
1527+
return False
1528+
return all(isinstance(p, int) for p in pad)
1529+
1530+
15101531
@update_features(exir_ops.edge.aten.constant_pad_nd.default)
15111532
def register_constant_pad_nd():
15121533
return OpFeatures(
15131534
inputs_storage=utils.ANY_STORAGE,
15141535
inputs_dtypes=utils.FP_INT_BOOL_T,
15151536
supports_resize=True,
1537+
are_node_inputs_supported_fn=_check_pad_is_static,
15161538
)
15171539

15181540

‎backends/vulkan/test/test_vulkan_delegate.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,32 @@ def forward(self, x):
14791479
sample_inputs,
14801480
)
14811481

1482+
def test_vulkan_backend_constant_pad_nd_symbolic_pad(self):
1483+
"""A pad amount derived from a dynamic dim, as LSTM padding produces.
1484+
1485+
Without the guard this partitions and then aborts at prepack with
1486+
"Expected value to have type IntList, got VALUELIST instead", because
1487+
the pad list is serialized as a VALUELIST of Int/SymInt.
1488+
"""
1489+
1490+
class TestModule(torch.nn.Module):
1491+
def forward(self, x):
1492+
# Pad up to a static length, the shape every unrolled LSTM
1493+
# wants its input in.
1494+
return torch.nn.functional.pad(x, (0, 0, 0, 16 - x.shape[1]))
1495+
1496+
sample_inputs = (torch.randn(size=(1, 12, 8), dtype=torch.float32),)
1497+
seq = Dim("seq", min=2, max=16)
1498+
self.lower_module_and_test_output(
1499+
TestModule(),
1500+
sample_inputs,
1501+
dynamic_shapes={"x": {1: seq}},
1502+
test_inputs=[
1503+
(torch.randn(size=(1, 4, 8), dtype=torch.float32),),
1504+
(torch.randn(size=(1, 16, 8), dtype=torch.float32),),
1505+
],
1506+
)
1507+
14821508
def test_vulkan_backend_repeat(self):
14831509
class TestModule(torch.nn.Module):
14841510
def __init__(self):

0 commit comments

Comments
 (0)