oneflow icon indicating copy to clipboard operation
oneflow copied to clipboard

[bug][graph] Advanced indexing assignment with negative indices crashes in Graph mode (RuntimeError: This is a oneflow bug …)

Open tinywisdom opened this issue 2 months ago • 0 comments

Summary

In OneFlow Graph mode, performing an advanced indexing assignment using two integer index tensors (containing negative indices) causes an internal runtime error.

The same code executes correctly in Eager mode.

Code to reproduce bug

import oneflow as flow
import oneflow.nn as nn
import numpy as np

class IndexAssign(nn.Module):
    def __init__(self):
        super().__init__()
        # Two 1D integer index tensors (with negative indices)
        self.register_buffer("idx0", flow.tensor([0, -1], dtype=flow.int64))  # rows
        self.register_buffer("idx1", flow.tensor([-2, 1], dtype=flow.int64))  # cols
        self.register_buffer("vals", flow.tensor([1.0, 5.0], dtype=flow.float32))

    def forward(self, x):  # x: (3, 3)
        y = x.clone()
        # Key trigger: advanced indexing assignment with negative indices
        y[self.idx0, self.idx1] = self.vals
        return y

def eager_then_graph():
    m = IndexAssign().eval()
    x = flow.randn(3, 3, dtype=flow.float32)

    # 1) Eager mode → OK
    y_eager = m(x)

    # 2) Graph mode → raises internal error
    class G(nn.Graph):
        def __init__(self, mod):
            super().__init__()
            self.m = mod
        def build(self, inp):
            return self.m(inp)

    g = G(m)
    y_graph = g(x)  # <-- triggers internal runtime error

if __name__ == "__main__":
    eager_then_graph()

Output

[ERROR](GRAPH:G_0:G) building graph got error.
Traceback (most recent call last):
  ...
  File "oneflow_mre_advanced_index_assign_graph_bug.py", line 33, in build
    return self.m(inp)
  ...
  File "oneflow_mre_advanced_index_assign_graph_bug.py", line 17, in forward
    y[self.idx0, self.idx1] = self.vals
RuntimeError: Error: RuntimeError : This is a oneflow bug, please submit an issue at 'https://github.com/Oneflow-Inc/oneflow/issues' including the log information of the error, the minimum reproduction code, and the system information.

System Information

  • OS: Ubuntu 22.04.4 LTS (x86_64)
  • OneFlow version : 1.0.0.dev20250921+cpu
  • Python version: 3.10.16

tinywisdom avatar Oct 08 '25 10:10 tinywisdom