-
Notifications
You must be signed in to change notification settings - Fork 830
Description
tensors_have_same_dim_order() fails incorrectly for memory-compatible tensors with ambiguous dimensions
Problem Summary
ExecuTorch's dim order validation has an inconsistency where tensor_is_contiguous() and tensors_have_same_dim_order() use different validation approaches, causing false negatives for edge cases with ambiguous dimensions (C=1 or H=W=1).
Root Cause Analysis
- tensor_is_contiguous() - Memory layout validation ✅
- Checks actual stride patterns to determine if memory is contiguous
- Correctly handles edge cases where different dim_order labels produce identical memory
- tensors_have_same_dim_order() - Label-based validation ❌
- Checks if all tensors have identical dim_order labels (strict matching)
- Fails when tensors have compatible memory but different labels
- The Inconsistency
- Same tensor data can pass individual contiguous checks but fail cross-tensor validation
- Edge cases with ambiguous dimensions are incorrectly rejected
When This Happens
Ambiguous Dimension Cases:
C=1: Channel dimension = 1 makes NCHW/NHWC memory layouts identical
H=W=1: Spatial dimensions = 1 makes NCHW/NHWC memory layouts identical
Multiple dims = 1: Combined edge cases
========================
// Both tensors have IDENTICAL memory layout
Tensor nchw = tf_float_.ones({2, 1, 4, 4}); // dim_order: [0,1,2,3]
Tensor nhwc = tf_float_.full_channels_last({2, 1, 4, 4}, 1.0); // dim_order: [0,2,3,1]
// Memory layout: N₀N₁ H₀W₀W₁W₂W₃ H₁W₀W₁W₂W₃ H₂W₀W₁W₂W₃ H₃W₀W₁W₂W₃
// ↑ IDENTICAL for both tensors because C=1
// Individual validation:
tensor_is_contiguous(nchw) == true ✅
tensor_is_contiguous(nhwc) == true ✅
// Cross validation:
tensors_have_same_dim_order(nchw, nhwc) == false ❌ BUG!
========================
Also note that the existing unit test cases do not seem to cover these edge cases
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Status
Status