Skip to content

Segmentation Fault (Core Dumped) When Adding Tensor and nn.Linear Module in Eager Mode #10689

Description

@LiSsHhUuAaIi

Summary

I encountered a segmentation fault (core dumped) when running a model in OneFlow's eager mode. The error occurs when attempting to add a tensor (flow.relu(value)) and an nn.Linear module (self.linear) in the forward method. Instead of raising a proper Python exception for this type mismatch, OneFlow crashes with a segmentation fault.

Code to reproduce bug

import oneflow as flow
import oneflow.nn as nn

class TestModel(nn.Module):
    def __init__(self):
        super(TestModel, self).__init__()
        self.linear = nn.Linear(10, 5)

    def forward(self, value):
        # BUG: Attempting to add tensor (flow.relu(value)) and module (self.linear)
        # This should raise TypeError but causes segmentation fault
        return flow.relu(value) + self.linear

# Test data
input_tensor = flow.randn(1, 10)
model = TestModel()

try:
    # This should raise TypeError but instead causes segfault
    result = model(input_tensor)
    print("Success:", result)
except Exception as e:
    print("Caught exception:", e)

print("This line is unreachable due to segmentation fault")

Error Logs

Stack trace (most recent call last):
   Object "/home/miniconda3/envs/oneflow-test/lib/python3.10/site-packages/oneflow/_oneflow_internal.cpython-310-x86_64-linux-gnu.so", at 0x7f500ff21562, in 
   Object "/home/miniconda3/envs/oneflow-test/lib/python3.10/site-packages/oneflow/_oneflow_internal.cpython-310-x86_64-linux-gnu.so", at 0x7f500fd4f14f, in functional::add(_object*, _object*, _object*)
   Object "/home/miniconda3/envs/oneflow-test/lib/python3.10/site-packages/oneflow/../oneflow.libs/liboneflow-efdae59a.so", at 0x7f50004aa579, in functional::Add(TensorTuple const&, bool)
    ...
    ...
Segmentation fault (Address not mapped to object [0x79])
Segmentation fault (core dumped)

System Information

  • OS: Ubuntu 20.04.6 LTS
  • OneFlow version: '1.0.0.dev20251101+cpu'
  • Python version: Python 3.10.19

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions