Skip to content

Commit d2dc716

Browse files
Fix const prop pass when a const prop tensor has zero stride, make it contiguous
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 b265324 commit d2dc716

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

exir/passes/constant_prop_pass.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ 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 isinstance(prop_constant_tensor, torch.Tensor) and 0 in prop_constant_tensor.stride():
171+
prop_constant_tensor = prop_constant_tensor.contiguous()
167172
const_node_to_tensor[node] = prop_constant_tensor
168173

169174
return const_node_to_tensor

0 commit comments

Comments
 (0)