oneflow icon indicating copy to clipboard operation
oneflow copied to clipboard

Undefined LLVM function while trying to load oneflow

Open irshadcc opened this issue 1 year ago • 2 comments

Summary

Undefined LLVM function/symbol while trying to load oneflow library

Traceback (most recent call last):
  File "/oneflow/examples/mnist.py", line 1, in <module>
    import oneflow as flow
  File "/oneflow/python/oneflow/__init__.py", line 26, in <module>
    import oneflow._oneflow_internal
ImportError: /oneflow/build/liboneflow.so: undefined symbol: _ZN4llvm15itaniumDemangleEPKc

Code to reproduce bug

  1. Follow the process in README.md to build the project from source code in container
  2. Use the below MNIST model training script
import oneflow as flow
import oneflow.nn as nn
from flowvision import transforms
from flowvision import datasets


BATCH_SIZE=64

DEVICE = "cuda" if flow.cuda.is_available() else "cpu"
print("Using {} device".format(DEVICE))

training_data = datasets.FashionMNIST(
    root="data",
    train=True,
    transform=transforms.ToTensor(),
    download=True,
    source_url="https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/mnist/Fashion-MNIST/",

)
test_data = datasets.FashionMNIST(
    root="data",
    train=False,
    transform=transforms.ToTensor(),
    download=True,
    source_url="https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/mnist/Fashion-MNIST/",
)

train_dataloader = flow.utils.data.DataLoader(
    training_data, BATCH_SIZE, shuffle=True
)
test_dataloader = flow.utils.data.DataLoader(
    test_data, BATCH_SIZE, shuffle=False
)

for x, y in train_dataloader:
    print("x.shape:", x.shape)
    print("y.shape:", y.shape)
    break


class NeuralNetwork(nn.Module):
    def __init__(self):
        super(NeuralNetwork, self).__init__()
        self.flatten = nn.Flatten()
        self.linear_relu_stack = nn.Sequential(
            nn.Linear(28*28, 512),
            nn.ReLU(),
            nn.Linear(512, 512),
            nn.ReLU(),
            nn.Linear(512, 10),
        )

    def forward(self, x):
        x = self.flatten(x)
        logits = self.linear_relu_stack(x)
        return logits

model = NeuralNetwork().to(DEVICE)
print(model)

loss_fn = nn.CrossEntropyLoss().to(DEVICE)
optimizer = flow.optim.SGD(model.parameters(), lr=1e-3)

def train(iter, model, loss_fn, optimizer):
    size = len(iter.dataset)
    for batch, (x, y) in enumerate(iter):
        x = x.to(DEVICE)
        y = y.to(DEVICE)

        # Compute prediction error
        pred = model(x)
        loss = loss_fn(pred, y)

        # Backpropagation
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()

        current = batch * BATCH_SIZE
        if batch % 100 == 0:
            print(f"loss: {loss:>7f}  [{current:>5d}/{size:>5d}]")

epochs = 5
for t in range(epochs):
    print(f"Epoch {t+1}\n-------------------------------")
    train(train_dataloader, model, loss_fn, optimizer)
print("Done!")

System Information

  • What is your OneFlow installation (pip, source, dockerhub): source (CPU Build with debug symbols)
  • OS: Fedora - Linux 6.2.14-100.fc36.x86_64
  • OneFlow version (run python3 -m oneflow --doctor): Can't get the output since the loading step fails.
  • Python version: Python 3.10
  • CUDA driver version: None (CPU Build)
  • GPU models: None
  • Other info:

irshadcc avatar Jul 02 '23 06:07 irshadcc

I met this problem too when import oneflow I built using source code following README

nm liboneflow.so | grep _ZN4llvm15itaniumDemangleEPKc
                 U _ZN4llvm15itaniumDemangleEPKc

raymond1123 avatar Sep 04 '23 06:09 raymond1123

one_flow_cmake Looks a the LLVMDemangle library is also needed in the `one_flow_third_party_libs'.

zhangboyue avatar Sep 05 '23 12:09 zhangboyue