pytorch / pytorch/pytorch

`torch.compile` (inductor) crashes on in-place complex foreach-divide (public `torch.foreach.div_` and private `torch._foreach_div_`)

Open
#197,376 0 comments 0 reactions 0 assignees View on GitHub
bot-triaged module: complex module: inductor module: mta oncall: pt2 release triage triage review
Dominant language
Python
Stars
103k
Forks
29.5k
PR merge metrics
PR metrics pending

Description

### 🐛 Describe the bug

In-place foreach-divide on a list of **complex** tensors runs correctly in eager but crashes
`torch.compile` (inductor) with an internal invariant assertion. This happens with **both** the
public beta `torch.foreach.div_` and the private `torch._foreach_div_` — same error:

```
torch._inductor.exc.InductorError: AssertionError: is not an OpOverload
```

## Minimal repro

```python
import torch

def fn(tensors):
torch.foreach.div_(tensors, 1j) # PUBLIC beta API; in-place foreach divide by a complex scalar

tensors = [torch.tensor([1 + 2j, 3 + 4j], dtype=torch.complex64)]

fn(tensors) # eager: OK -> [2-1j, 4-3j]
torch.compile(fn, backend="inductor")( # compiled: InductorError (getitem is not an OpOverload)
[torch.tensor([1 + 2j, 3 + 4j], dtype=torch.complex64)]
)

# The private torch._foreach_div_(tensors, 1j) crashes identically (same InductorError),
# so this is not specific to the private API.
```

Scope (what does / doesn't crash) — same for the public `torch.foreach.div_` and private `torch._foreach_div_`:

| variant | dtype | compiled |
|---|---|---|
| in-place `div_` | complex64 | **CRASH** |
| out-of-place `div` | complex64 | OK |
| in-place `div_` | float32 | OK |

Reproduces on **CPU and CUDA**. Also crashes for an in-place divide by a complex tensor list
(not just a scalar).

## Expected behavior

Compiling an in-place complex `_foreach_div_` should match eager (or raise a graceful error),
not hit an internal inductor invariant. The out-of-place and float paths already compile, so
the in-place complex lowering is the gap.

## Actual behavior

Eager divides in place correctly (`[2-1j, 4-3j]`). Under inductor the compilation fails with
`AssertionError: is not an OpOverload` before running.

### Versions

```
PyTorch version: 2.15.0a0+gite67e43b
Is debug build: True
CUDA used to build PyTorch: 12.6
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 12.3.0-1ubuntu1~22.04.3) 12.3.0
Clang version: 17.0.6
CMake version: version 4.0.0
Libc version: glibc-2.35

Python version: 3.12.13 | packaged by conda-forge (64-bit runtime)
Python platform: Linux-6.8.0-138-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.6.20
GPU 0: NVIDIA RTX A6000
Nvidia driver version: 580.82.07
cuDNN version: 9.3.0

[pip3] numpy==2.3.5
[pip3] torch==2.15.0a0+gite67e43b
[pip3] triton==3.7.1
```

cc @ezyang @anjali411 @dylanbespalko @mruberry @nikitaved @amjames @crcrpar @mcarilli @janeyx99 @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @aakhundov @coconutruben @jataylo

Contributor guide

Open the contributing guide

Research direction

Run the minimal repro through torch.compile with backend="inductor", testing both torch.foreach.div_ and torch._foreach_div_ alongside the listed eager, out-of-place, and float variants. Trace the inductor lowering for in-place complex foreach division; done means CPU and CUDA compilation succeeds without the getitem assertion and matches eager results.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.