Singularity-Container + Python + PyTorch:为什么'import torch'在 Arch Linux 主机上工作,但在 Centos 7 主机上失败?



我正在尝试构建一个奇点容器,以便在基于centos7的集群上运行Python脚本。容器在我的主机上按预期运行,我也用它来创建容器,但一旦导入PyTorch,就会在集群上失败。

这个问题可以通过这个最小定义文件的容器构建来重现:

debug.def:

Bootstrap: arch
%runscript
exec /usr/bin/python3 -c 'import torch; print(torch.__version__)'
%post
#--------------------------------------------------------------------------
# Basic setup from
# https://github.com/sylabs/singularity/blob/master/examples/arch/Singularity
#--------------------------------------------------------------------------
# Set time zone. Use whatever you prefer instead of UTC.
ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime
# Set the package mirror server(s). This is only for the output image's
# mirrorlist. `pacstrap' can only use your hosts's package mirrors.
echo 'Server = https://mirrors.kernel.org/archlinux/$repo/os/$arch' > /etc/pacman.d/mirrorlist
pacman -Sy --noconfirm gawk sed grep
# Set locale. Use whatever you prefer instead of en_US.
echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen
locale-gen
echo 'LANG=en_US.UTF-8' > /etc/locale.conf
pacman -S --noconfirm python python-pytorch
pacman -S --noconfirm pacman-contrib
paccache -r -k0

它是用sudo singularity build debug.sif debug.def构建的。容器和我的主机都在Arch Linux上运行。

在我的主机上执行容器输出PyTorch版本:

schellsn@host $ singularity run debug.sif
1.3.1

在集群上运行会导致以下错误:

schellsn@cluster tmp$ singularity run debug.sif
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.8/site-packages/torch/__init__.py", line 81, in <module>
from torch._C import *
ImportError: libQt5Core.so.5: cannot open shared object file: No such file or directory

我不明白为什么找不到文件,因为它应该包含在容器中:

schellsn@cluster tmp$ singularity shell debug.sif 
Singularity debug.sif:~/tmp> ls -l /usr/lib | grep libQt5Core
-rw-r--r--  1 root root      1166 Nov 11 23:40 libQt5Core.prl
lrwxrwxrwx  1 root root        20 Nov 11 23:40 libQt5Core.so -> libQt5Core.so.5.13.2
lrwxrwxrwx  1 root root        20 Nov 11 23:40 libQt5Core.so.5 -> libQt5Core.so.5.13.2
lrwxrwxrwx  1 root root        20 Nov 11 23:40 libQt5Core.so.5.13 -> libQt5Core.so.5.13.2
-rwxr-xr-x  1 root root   5275240 Nov 11 23:40 libQt5Core.so.5.13.2

我假设在导入时,搜索中不包括相应的路径,并且由于某些环境设置泄漏到容器中,所以在我的主机上不会出现此问题。我还尝试使用Sylabs Remote Builder,但它似乎无法构建Arch容器($PATH中找不到pacstrap(。尝试在其中一个节点上构建容器会导致同样的问题Pacstrappacman不可用。

我已经无计可施了,如果能给我任何解释这种行为的暗示,我将不胜感激!为什么找不到共享库?如何修复?

更新#1:

以下是LD_LIBRARY_PATH环境变量的内容(响应@tsnowlan(。

Arch Linux主机:

schellsn@host tmp$ echo $LD_LIBRARY_PATH
:/usr/local/cuda/lib:/usr/local/cuda/lib64:/usr/local/cuda/lib:/usr/local/cuda/lib64
schellsn@host tmp$ singularity shell evpt_debug.sif
Singularity evpt_debug.sif: ~/tmp> echo $LD_LIBRARY_PATH
:/usr/local/cuda/lib:/usr/local/cuda/lib64:/usr/local/cuda/lib:/usr/local/cuda/lib64:/.singularity.d/libs

CentOS 7集群节点:

schellsn@cluster tmp$ echo $LD_LIBRARY_PATH
schellsn@cluster tmp$ singularity shell debug.sif 
Singularity debug.sif:~/tmp> echo $LD_LIBRARY_PATH
/.singularity.d/libs

更新#2:

我确实安装了一个新的干净的VM(也在运行arch(,它也在那里重建了容器。这个容器显示了同样的问题;它在我的主机上运行,但不在Centos7群集上运行。

我遇到了同样的问题:CentOS 7主机和Arch Linux容器(Python 3.8.1/Pytorch 1.3.1(。下面的链接似乎暂时解决了我的问题。

https://superuser.com/questions/1347723/arch-on-wsl-libqt5core-so-5-not-found-despite-being-installed

编辑:从链接来看,这个命令对我有效

sudo strip --remove-section=.note.ABI-tag /usr/lib64/libQt5Core.so.5

作为一种解决方法,我现在从一个def文件构建容器,该文件使用带有Ubuntu 18.04映像的库引导代理,而不是Arch引导代理。生成的容器在我的Arch Host和CentOS 7集群上运行。

相关内容

最新更新