Oneflow-Inc / oneflow

OneFlow is a deep learning framework designed to be user-friendly, scalable and efficient.
http://www.oneflow.org
Apache License 2.0
5.9k stars 666 forks source link

Undefined LLVM function while trying to load oneflow #10298

Open irshadcc opened 1 year ago

irshadcc commented 1 year ago

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

raymond1123 commented 1 year ago

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

nm liboneflow.so | grep _ZN4llvm15itaniumDemangleEPKc
                 U _ZN4llvm15itaniumDemangleEPKc
zhangboyue commented 1 year ago

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