oneflow icon indicating copy to clipboard operation
oneflow copied to clipboard

[bug][nn.Graph] pack_padded_sequence → LSTM → pad_packed_sequence crashes during Graph build ("This is a oneflow bug")

Open tinywisdom opened this issue 2 months ago • 0 comments

Summary

When using variable-length RNN input with flow.nn.utils.rnn.pack_padded_sequence → nn.LSTM → flow.nn.utils.rnn.pad_packed_sequence inside nn.Graph, graph compilation fails with a generic:

RuntimeError: This is a oneflow bug, please submit an issue...

This happens during Graph build, not at runtime. (In eager mode this pipeline is expected to work.)

Code to reproduce bug

import oneflow as flow
import oneflow.nn as nn

class M(nn.Module):
    def __init__(self):
        super().__init__()
        self.lstm = nn.LSTM(256, 128, batch_first=True)

    def forward(self, x, xlen):
        packed = flow.nn.utils.rnn.pack_padded_sequence(
            x, xlen, batch_first=True, enforce_sorted=True
        )
        out, _ = self.lstm(packed)
        y, _ = flow.nn.utils.rnn.pad_packed_sequence(out, batch_first=True)
        return y

class G(nn.Graph):
    def __init__(self, m): super().__init__(); self.m = m
    def build(self, x, xlen): return self.m(x, xlen)

x = flow.randn(2, 12, 256)
xlen = flow.tensor([12, 10], dtype=flow.int64)
g = G(M())
g(x, xlen)  # -> RuntimeError: "This is a oneflow bug..."

Output

[ERROR](GRAPH:G_0:G) building graph got error.
...
packed = flow.nn.utils.rnn.pack_padded_sequence(...)
  File ".../oneflow/nn/utils/rnn.py", line 256, in pack_padded_sequence
    data, batch_sizes = flow._C.pack_padded_sequence(input, lengths, batch_first)
RuntimeError: Error: RuntimeError : This is a oneflow bug, please submit an issue ...

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 02 '25 01:10 tinywisdom