oneflow
oneflow copied to clipboard
Segmentation fault (core dumped) in oneflow.Tensor.__add__(self, other)
Summary
OneFlow does not properly validate data types during tensor arithmetic involving int8 tensors. Specifically, performing an operation like int8_tensor + "a" (string) leads to a segmentation fault, rather than raising a TypeError. This is a severe robustness bug, as such input should never reach the backend and crash the process.
Code to reproduce bug
import oneflow as flow
import numpy as np
# Set fixed seed for reproducibility
np.random.seed(42)
# Create an int8 tensor representing ASCII characters
char_map = [ord(c) for c in "abcdefgh"]
char_tensor = flow.tensor(char_map, dtype=flow.int8)
print(char_tensor)
# Valid operations
char_tensor + 1
char_tensor + flow.tensor([1], dtype=flow.int8)
char_tensor * flow.tensor([2], dtype=flow.int8)
char_tensor.reshape(-1, 2)
print(char_tensor)
# Invalid operations
# This should raise an exception, not crash
print(char_tensor + 0.5) # Implicit promotion, should be fine
print(char_tensor + "a") # ❌ This causes segmentation fault
output:
tensor([ 97, 98, 99, 100, 101, 102, 103, 104], dtype=oneflow.int8)
tensor([ 97, 98, 99, 100, 101, 102, 103, 104], dtype=oneflow.int8)
tensor([ 97.5000, 98.5000, 99.5000, 100.5000, 101.5000, 102.5000, 103.5000, 104.5000], dtype=oneflow.float32)
Segmentation fault (core dumped)
System Information
OneFlow installation: pip OS: Ubuntu 20.04 OneFlow version (run python3 -m oneflow --doctor):
path: ['/root/miniconda3/envs/myconda/lib/python3.8/site-packages/oneflow']
version: 0.9.0
git_commit: 381b12c
cmake_build_type: Release
rdma: True
mlir: True
Python version: 3.8 CUDA driver version: 11.6 GPU models: NVIDIA A16