opened
befelix
username_0
```
which has a hard-coded dimension that replaces the ellipsis according to the batch-dimension of the example tensor. In contrast, `jit.script` identifies the ellipsis and compiles the code to:
```python
def select(x: Tensor) -> Tensor:\n  return torch.select(x, -1, 0)\n'
```

## Motivation

While `jit.script` has come a long way, tracing is often still the easiest to get to jit'ed code. Having indexing operations with ellipsis traced as hard-coded indeces makes it more difficult to use tracing with different batch sizes and can lead to subtle indexing errors as in the example above.
[torch.jit.trace] Indexing with ellipsis fixes the batch dimension
issue
created
gmagogsfm
username_1
@username_3 @username_2 Any thoughts? It feels like a fundamental limitation of `trace` to me
comment
created
suo
username_2
The current implementation the tracer records operations at the `aten` level, so it only sees advanced indexing operations after they've been desugared into the actual `aten::select` call. So yeah, in that sense it's a fundamental limitation of the current approach.

Possible options, listed in no particular order of practicality:
1. We could create an aten op that captures the fact that advanced indexing was done, although that increases the complexity of the PT core to solve an implementation detail of the tracer.
2. We could use FX to trace this, although I'm not sure whether it captures this kind of higher-level indexing either (cc @username_3)
3. You can nest a scripted function within a traced one to "preserve" the indexing call (this might be ugly/hard to know where the scripted functions need to be inserted)
comment
created
gmagogsfm
username_1
Hi @username_0,

Optional #3 that @username_2 proposed can be done quickly in your code, could you give that a try? option #1 and #2 would take more time to develop than #3. So #3 is best shot to get unblocked.
comment
closed
gmagogsfm
username_1
issue
created
jamesr66a
username_3
@username_2 FX traces the surface-level `getitem` call so it's plausible:

```
import torch
import torch.fx

def idx(x, z):
  return x[..., z]

traced = torch.fx.symbolic_trace(idx)
print(traced.graph)
"""
graph(x, z):
    %getitem : [#users=1] = call_function[target=operator.getitem](args = (%x, (Ellipsis, %z)), kwargs = {})
    return getitem
"""
```
comment