pytorch - 💡(How to fix) Fix [inductor] torch.index_select on uint16 input silently succeeds while eager/aot_eager raise NotImplementedError

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

import torch import traceback

def f(x, idx): return torch.index_select(x, 0, idx)

x = torch.tensor([10, 20, 30, 40], dtype=torch.uint16) idx = torch.tensor([0, 2, 1], dtype=torch.int64)

print("x_dtype", x.dtype) print("idx_dtype", idx.dtype)

for name, runner in [ ("eager", f), ("compile_eager", torch.compile(f, backend="eager", fullgraph=True)), ("compile_aot_eager", torch.compile(f, backend="aot_eager", fullgraph=True)), ("compile_inductor", torch.compile(f, backend="inductor", fullgraph=True)), ]: try: out = runner(x, idx) print(name, "result:", out) except Exception as e: print(name, "error:", type(e).name, str(e).splitlines()[0]) traceback.print_exc(limit=5)

Code Example

import torch
import traceback

def f(x, idx):
    return torch.index_select(x, 0, idx)

x = torch.tensor([10, 20, 30, 40], dtype=torch.uint16)
idx = torch.tensor([0, 2, 1], dtype=torch.int64)

print("x_dtype", x.dtype)
print("idx_dtype", idx.dtype)

for name, runner in [
    ("eager", f),
    ("compile_eager", torch.compile(f, backend="eager", fullgraph=True)),
    ("compile_aot_eager", torch.compile(f, backend="aot_eager", fullgraph=True)),
    ("compile_inductor", torch.compile(f, backend="inductor", fullgraph=True)),
]:
    try:
        out = runner(x, idx)
        print(name, "result:", out)
    except Exception as e:
        print(name, "error:", type(e).__name__, str(e).splitlines()[0])
        traceback.print_exc(limit=5)

---

x_dtype torch.uint16
idx_dtype torch.int64
eager error: NotImplementedError "index_select" not implemented for 'UInt16'
compile_eager error: NotImplementedError "index_select" not implemented for 'UInt16'
compile_aot_eager error: NotImplementedError "index_select" not implemented for 'UInt16'
compile_inductor result: tensor([10, 30, 20], dtype=torch.uint16)
Traceback (most recent call last):
  File "/tmp/ipykernel_873/3325074809.py", line 20, in <cell line: 0>
    out = runner(x, idx)
          ^^^^^^^^^^^^^^
  File "/tmp/ipykernel_873/3325074809.py", line 5, in f
    return torch.index_select(x, 0, idx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
NotImplementedError: "index_select" not implemented for 'UInt16'
Traceback (most recent call last):
  File "/tmp/ipykernel_873/3325074809.py", line 20, in <cell line: 0>
    out = runner(x, idx)
          ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_dynamo/eval_frame.py", line 1143, in compile_wrapper
    result = fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^
  File "/tmp/ipykernel_873/3325074809.py", line 4, in f
    def f(x, idx):
  File "/usr/local/lib/python3.12/dist-packages/torch/_dynamo/eval_frame.py", line 1421, in _fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "<eval_with_key>.45", line 7, in forward
    index_select = torch.index_select(l_x_, 0, l_idx_);  l_x_ = l_idx_ = None
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
NotImplementedError: "index_select" not implemented for 'UInt16'
Traceback (most recent call last):
  File "/tmp/ipykernel_873/3325074809.py", line 20, in <cell line: 0>
    out = runner(x, idx)
          ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_dynamo/eval_frame.py", line 1143, in compile_wrapper
    result = fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^
  File "/tmp/ipykernel_873/3325074809.py", line 4, in f
    def f(x, idx):
  File "/usr/local/lib/python3.12/dist-packages/torch/_dynamo/eval_frame.py", line 1421, in _fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_functorch/aot_autograd.py", line 1277, in forward
    return compiled_fn(full_args)
           ^^^^^^^^^^^^^^^^^^^^^^
NotImplementedError: "index_select" not implemented for 'UInt16'

---

PyTorch version: 2.10.0+cpu
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

torch.index_select on a torch.uint16 input raises NotImplementedError in eager mode, and the same error is preserved by torch.compile(..., backend="eager") and torch.compile(..., backend="aot_eager").

However, torch.compile(..., backend="inductor", fullgraph=True) silently succeeds and returns a uint16 tensor. This looks like an Inductor-only eager-parity bug: Inductor appears to bypass the dtype legality check for index_select on UInt16.

import torch
import traceback

def f(x, idx):
    return torch.index_select(x, 0, idx)

x = torch.tensor([10, 20, 30, 40], dtype=torch.uint16)
idx = torch.tensor([0, 2, 1], dtype=torch.int64)

print("x_dtype", x.dtype)
print("idx_dtype", idx.dtype)

for name, runner in [
    ("eager", f),
    ("compile_eager", torch.compile(f, backend="eager", fullgraph=True)),
    ("compile_aot_eager", torch.compile(f, backend="aot_eager", fullgraph=True)),
    ("compile_inductor", torch.compile(f, backend="inductor", fullgraph=True)),
]:
    try:
        out = runner(x, idx)
        print(name, "result:", out)
    except Exception as e:
        print(name, "error:", type(e).__name__, str(e).splitlines()[0])
        traceback.print_exc(limit=5)

Output:

x_dtype torch.uint16
idx_dtype torch.int64
eager error: NotImplementedError "index_select" not implemented for 'UInt16'
compile_eager error: NotImplementedError "index_select" not implemented for 'UInt16'
compile_aot_eager error: NotImplementedError "index_select" not implemented for 'UInt16'
compile_inductor result: tensor([10, 30, 20], dtype=torch.uint16)
Traceback (most recent call last):
  File "/tmp/ipykernel_873/3325074809.py", line 20, in <cell line: 0>
    out = runner(x, idx)
          ^^^^^^^^^^^^^^
  File "/tmp/ipykernel_873/3325074809.py", line 5, in f
    return torch.index_select(x, 0, idx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
NotImplementedError: "index_select" not implemented for 'UInt16'
Traceback (most recent call last):
  File "/tmp/ipykernel_873/3325074809.py", line 20, in <cell line: 0>
    out = runner(x, idx)
          ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_dynamo/eval_frame.py", line 1143, in compile_wrapper
    result = fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^
  File "/tmp/ipykernel_873/3325074809.py", line 4, in f
    def f(x, idx):
  File "/usr/local/lib/python3.12/dist-packages/torch/_dynamo/eval_frame.py", line 1421, in _fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "<eval_with_key>.45", line 7, in forward
    index_select = torch.index_select(l_x_, 0, l_idx_);  l_x_ = l_idx_ = None
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
NotImplementedError: "index_select" not implemented for 'UInt16'
Traceback (most recent call last):
  File "/tmp/ipykernel_873/3325074809.py", line 20, in <cell line: 0>
    out = runner(x, idx)
          ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_dynamo/eval_frame.py", line 1143, in compile_wrapper
    result = fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^
  File "/tmp/ipykernel_873/3325074809.py", line 4, in f
    def f(x, idx):
  File "/usr/local/lib/python3.12/dist-packages/torch/_dynamo/eval_frame.py", line 1421, in _fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_functorch/aot_autograd.py", line 1277, in forward
    return compiled_fn(full_args)
           ^^^^^^^^^^^^^^^^^^^^^^
NotImplementedError: "index_select" not implemented for 'UInt16'

Versions

PyTorch version: 2.10.0+cpu

cc @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @aakhundov @coconutruben @jataylo

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING