apple / apple/coremltools

[ExecuTorch] Cannot Use Dynamic Index to Select

Open
#2,189 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
5.4k
Forks
850
Avg merge
4d 5h
Merged PRs (30d)
10

Description

This toy model fails in ExecuTorch
```
class M(torch.nn.Module):
def forward(self, float_arr, int_arr):
dynamic_index = int_arr[1]
float_arr[dynamic_index] = 12.95
return float_arr
```
due to
```
E torch._dynamo.exc.UserError: Consider annotating your code using torch._constrain_as_*(). Could not guard on data-dependent expression u0 (unhinted: u0). (Size-like symbols: none)
E
E Potential framework code culprit (scroll up for full backtrace):
E File ".223", line 8, in forward
E l_float_arr_[dynamic_index] = 12.95; setitem = l_float_arr_; dynamic_index = None
E
E For more information, run with TORCH_LOGS="dynamic"
E For extended logs when we create symbols, also add TORCHDYNAMO_EXTENDED_DEBUG_CREATE_SYMBOL="u0"
E If you suspect the guard was triggered from C++, add TORCHDYNAMO_EXTENDED_DEBUG_CPP=1
E For more debugging help, see https://docs.google.com/document/d/1HSuTTVvYH1pTew89Rtpeu84Ht3nQEFTYhAX3Ypa_xJs/edit?usp=sharing
E
E For C++ stack trace, run with TORCHDYNAMO_EXTENDED_DEBUG_CPP=1
E For more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#constrain-as-size-example
```
But some other dynamic indexing models are fine, e.g.
```
class IndexPutModel(torch.nn.Module):
def forward(self, x, position, val):
y = x.clone()
y[:, position] = val
return y
```

Contributor guide

Open the contributing guide

Research direction

Start by running the toy model in the issue and compare its dynamic indexing behavior with IndexPutModel. Trace the ExecuTorch conversion path that handles indexed assignment; done means the toy model converts and runs without the reported data-dependent-expression error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
backend, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.