When converting a model to ExecuTorch using aten_dialect = export(model, (dummy_input_text, dummy_input_label, dummy_input_midi, dummy_input_duration_phn, dummy_input_duration_ruled_phn, dummy_input_duration_syb, dummy_input_slur), dynamic_shapes=dynamic_shapes) the following lines of code generate a torch.fx.experimental.symbolic_shapes.GuardOnDataDependentSymNode: Could not guard on data-dependent expression error.
`
def forward(self, query, key, value, pos_emb, mask):
"""Compute 'Scaled Dot Product Attention' with rel. positional encoding.
Args:
query (torch.Tensor): Query tensor (#batch, time1, size).
key (torch.Tensor): Key tensor (#batch, time2, size).
value (torch.Tensor): Value tensor (#batch, time2, size).
pos_emb (torch.Tensor): Positional embedding tensor
(#batch, 2*time1-1, size).
mask (torch.Tensor): Mask tensor (#batch, 1, time2) or
(#batch, time1, time2).
Returns:
torch.Tensor: Output tensor (#batch, time1, d_model).
"""
q, k, v = self.forward_qkv(query, key, value)
q = q.transpose(1, 2) # (batch, time1, head, d_k)
n_batch_pos = pos_emb.size(0)
torch._check(pos_emb.size(0) != -1)
torch._check(pos_emb.size(2) != -1)
torch._check(pos_emb.size(1) != -1)
embed = self.linear_pos(pos_emb)
p = embed.reshape(n_batch_pos, pos_emb.size(1), self.h, self.d_k)
p = p.transpose(1, 2) # (batch, head, 2*time1-1, d_k)
# (batch, head, time1, d_k)
q_with_bias_u = (q + self.pos_bias_u).transpose(1, 2)
# (batch, head, time1, d_k)
q_with_bias_v = (q + self.pos_bias_v).transpose(1, 2)
# compute attention score
# first compute matrix a and matrix c
# as described in https://arxiv.org/abs/1901.02860 Section 3.3
# (batch, head, time1, time2)
k = k.transpose(-2, -1)
matrix_ac = torch.matmul(q_with_bias_u, k) <<<------ error on this line
# compute matrix b and matrix d
# (batch, head, time1, 2*time1-1)
matrix_bd = torch.matmul(q_with_bias_v, p.transpose(-2, -1))
matrix_bd = self.rel_shift(matrix_bd)
scores = (matrix_ac + matrix_bd) / math.sqrt(
self.d_k
) # (batch, head, time1, time2)
return self.forward_attention(v, scores, mask)
I have tried adding torch._check and torch._check_is_size but it has made no difference. If it helps the shapes of the tensors q_with_bias_u and k are (1, 2, value dependant, 96) and k the shape (1, 2, 96, the same data dependent value).
Versions
Collecting environment information...
PyTorch version: 2.4.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A
OS: macOS 14.6.1 (arm64)
GCC version: Could not collect
Clang version: 15.0.0 (clang-1500.0.40.1)
CMake version: version 3.30.3
Libc version: N/A
Python version: 3.10.15 (main, Sep 7 2024, 00:20:06) [Clang 15.0.0 (clang-1500.3.9.4)] (64-bit runtime)
Python platform: macOS-14.6.1-arm64-arm-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
🐛 Describe the bug
When converting a model to ExecuTorch using
aten_dialect = export(model, (dummy_input_text, dummy_input_label, dummy_input_midi, dummy_input_duration_phn, dummy_input_duration_ruled_phn, dummy_input_duration_syb, dummy_input_slur), dynamic_shapes=dynamic_shapes)
the following lines of code generate a torch.fx.experimental.symbolic_shapes.GuardOnDataDependentSymNode: Could not guard on data-dependent expression error. `` The full error message is
I have tried adding torch._check and torch._check_is_size but it has made no difference. If it helps the shapes of the tensors q_with_bias_u and k are (1, 2, value dependant, 96) and k the shape (1, 2, 96, the same data dependent value).
Versions
Collecting environment information... PyTorch version: 2.4.0 Is debug build: False CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A
OS: macOS 14.6.1 (arm64) GCC version: Could not collect Clang version: 15.0.0 (clang-1500.0.40.1) CMake version: version 3.30.3 Libc version: N/A
Python version: 3.10.15 (main, Sep 7 2024, 00:20:06) [Clang 15.0.0 (clang-1500.3.9.4)] (64-bit runtime) Python platform: macOS-14.6.1-arm64-arm-64bit Is CUDA available: False CUDA runtime version: No CUDA CUDA_MODULE_LOADING set to: N/A GPU models and configuration: No CUDA Nvidia driver version: No CUDA cuDNN version: No CUDA HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True
CPU: Apple M2 Pro
Versions of relevant libraries: [pip3] audiolm-pytorch==1.1.4 [pip3] ema-pytorch==0.5.1 [pip3] executorch==0.3.0a0+7d77d78 [pip3] lion-pytorch==0.2.2 [pip3] numpy==1.23.5 [pip3] onnxruntime==1.18.1 [pip3] optree==0.12.1 [pip3] pytorch-wpe==0.0.1 [pip3] torch==2.4.0 [pip3] torch-complex==0.4.4 [pip3] torchaudio==2.4.0 [pip3] torchsr==1.0.4 [pip3] torchtext==0.18.0 [pip3] torchvision==0.19.0 [pip3] vector-quantize-pytorch==1.14.26 [conda] Could not collect