Skip to content

Commit e0aceaa

Browse files
Fix const prop pass when a const prop tensor has zero stride, make it contiguous (#14725)
Summary: Found out that xnnpack lowering fails due to rejecting a zero stride tensor by executorch during to_backend phase. The fix is to identify such tensors and make them contiguous. For context: https://fb.workplace.com/groups/764610762549390/permalink/1868907967337731/ Differential Revision: D83631522
1 parent b1309e7 commit e0aceaa

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

exir/passes/constant_prop_pass.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ def get_propagated_const_tensor_dict(
164164
with torch.no_grad():
165165
# Execute the `node.target` and create a new propagated constant tensor.
166166
prop_constant_tensor = node.target(*args_data, **kwargs_data)
167+
168+
# ExecuTorch doesn't support zero strides, so we need to ensure the tensor is contiguous
169+
# if it has any zero strides from broadcasting/expansion operations
170+
if (
171+
isinstance(prop_constant_tensor, torch.Tensor)
172+
and 0 in prop_constant_tensor.stride()
173+
):
174+
prop_constant_tensor = prop_constant_tensor.contiguous()
167175
const_node_to_tensor[node] = prop_constant_tensor
168176

169177
return const_node_to_tensor

0 commit comments

Comments
 (0)