我使用 slurm 设置了一个 3 节点集群,1 个控制节点和 3 个计算节点(控制节点兼作计算节点)。所有节点都位于 Linux Mint 上,并且它们都通过共享文件系统和 tailscale 网络进行通信。 共享文件系统是 /opt/opt-shared/ 并在所有节点上启动时安装。
设置一个模块来激活和使用共享文件系统上存储的任何 conda env。这个想法是 miniconda3/ 目录保存所有 conda 文件,而 envs 位于共享文件系统中的特定文件夹中,因此当 slurm 脚本发送到队列时,任何节点都应该能够从该目录获取所需的任何内容。
当我将 slurm 脚本发送到队列时,根据发送脚本的用户,我会得到不同的行为。假设计算节点上的 root 用户 A 通过“sbatch”发送此测试脚本:
#!/bin/bash
#SBATCH --job-name=stress-test
#SBATCH --time=00:30:00
#SBATCH --cpus-per-task=16
#SBATCH --output=/opt/opt-shared/input-files/stresstest/out.out
#SBATCH --error=/opt/opt-shared/input-files/stresstest/error.err
source /etc/profile.d/modules.sh
module load conda
source activate stress
srun stress-ng --cpu 0 --cpu-method all --timeout 30s --metrics-brief
这完全按照我的预期运行,我什至可以指定节点= 3,或调用特定节点,一切都运行良好。然后,从非 root 用户 B 运行,我遇到了 error.err:
KeyError('pkgs_dirs') Traceback (most recent call last): File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/conda/exception_handler.py", line 17, in __call__ return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/conda/cli/main.py", line 92, in main_sourced context.__init__() File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/conda/base/context.py", line 456, in __init__ self._set_search_path( File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/conda/common/configuration.py", line 1426, in _set_search_path self._search_path = IndexedSet(self._expand_search_path(search_path, **kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/boltons/setutils.py", line 125, in __init__ self.update(other) File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/boltons/setutils.py", line 355, in update for o in other: File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/conda/common/configuration.py", line 1399, in _expand_search_path if path.is_file() and ( ^^^^^^^^^^^^^^ File "/opt/opt-shared/miniconda3/lib/python3.11/pathlib.py", line 1267, in is_file return S_ISREG(self.stat().st_mode) ^^^^^^^^^^^ File "/opt/opt-shared/miniconda3/lib/python3.11/pathlib.py", line 1013, in stat return os.stat(self, follow_symlinks=follow_symlinks) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PermissionError: [Errno 13] Permission denied: '/home/<userb>/.config/conda/.condarc' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/conda/exception_handler.py", line 165, in print_unexpected_error_report get_main_info_str(error_report["conda_info"]) File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/conda/cli/main_info.py", line 254, in get_main_info_str info_dict[f"_{key}"] = ("\n" + 26 * " ").join(map(str, info_dict[key])) ~~~~~~~~~^^^^^ KeyError: 'pkgs_dirs' ERROR REPORT <<<<<<<<<<<<<<<<<<<<<< Traceback (most recent call last): File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/conda/exception_handler.py", line 17, in __call__ return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/conda/cli/main.py", line 92, in main_sourced context.__init__() File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/conda/base/context.py", line 456, in __init__ self._set_search_path( File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/conda/common/configuration.py", line 1426, in _set_search_path self._search_path = IndexedSet(self._expand_search_path(search_path, **kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/boltons/setutils.py", line 125, in __init__ self.update(other) File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/boltons/setutils.py", line 355, in update for o in other: File "/opt/opt-shared/miniconda3/lib/python3.11/site-packages/conda/common/configuration.py", line 1399, in _expand_search_path if path.is_file() and ( ^^^^^^^^^^^^^^ File "/opt/opt-shared/miniconda3/lib/python3.11/pathlib.py", line 1267, in is_file return S_ISREG(self.stat().st_mode) ^^^^^^^^^^^ File "/opt/opt-shared/miniconda3/lib/python3.11/pathlib.py", line 1013, in stat return os.stat(self, follow_symlinks=follow_symlinks) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PermissionError: [Errno 13] Permission denied: '/home/<userb>/.config/conda/.condarc' `$ /opt/opt-shared/miniconda3/bin/conda shell.posix activate stress` environment variables: conda info could not be constructed. KeyError('pkgs_dirs') An unexpected error has occurred. Conda has prepared the above report. If you suspect this error is being caused by a malfunctioning plugin, consider using the --no-plugins option to turn off plugins. Example: conda --no-plugins install <package> Alternatively, you can set the CONDA_NO_PLUGINS environment variable on the command line to run the command without plugins enabled. Example: CONDA_NO_PLUGINS=true conda install <package>
如果相关的话,每个节点上的modules.sh实际上是共享文件系统上中央modules.sh文件的符号链接。怀疑这会改变什么,但你永远不知道。另外,可以成功发送作业的用户是最初安装 conda 的用户,如果我添加标志 [ #SBATCH --export=NONE ],即使对于该用户,这也会中断作业,这暗示了一些临时 shell环境变量由为计算节点上的特定作业创建的 shell 继承,但我找不到它可能是哪一个。
现在,为了摆脱任何权限恶作剧,我只需在 miniconda3/ 目录上执行
chmod -R 777
即可。这并没有改变任何事情。我尝试查看我的 NFS 挂载和导出设置,看看是否有任何其他权限挤压,但又什么也没有。
现在,当尝试使用以下命令手动运行 info 命令时:
/opt/opt-shared/miniconda3/bin/conda info
我发现了一些有趣的事情。如果我从计算节点正常手动运行此命令,我会收到相同的权限错误。但是,从计算节点以 sudo 身份运行我可以通过。与 sudo 一样运行“sbatch”命令时的情况相同。这些行为对我来说很奇怪,因为我认为 NFS 默认启用 root 压缩,而且还因为目录已经被 chmodded 为 777,所以是的,我不知道。更令人困惑的是,另一个节点上已经安装了 conda,因此存在大量令人困惑的冲突 - 现在我只关注第一个计算节点,因为这个节点是新格式化的。
作为附加信息,这是相应的模块文件:
#%Module1.0
set root /opt/opt-shared/miniconda3
prepend-path PATH $root/bin
如果有任何优秀的人可以帮助我设置这个 conda 模块,我将非常感激。就上下文而言,我在一个需要发送大量并发计算的研究团队工作,每个人都有自己的 conda 环境,因此这种设置似乎是处理事情的最佳方式。
我尝试更改共享文件系统所有权和权限,因为我收到的错误是权限错误。这没有帮助,仍然从计算节点收到权限错误。
我尝试手动梳理使用 conda 模块成功完成作业的用户的 shell 环境变量,并将其与失败的用户进行比较。这个想法是找到差异,也许可以在 slurm 脚本中手动导出必要的环境变量,而不是依赖于继承,但我无法确定哪个环境变量会像这样工作。
为了进一步隔离问题,我尝试在所有节点上的许多不同用户上手动运行 conda 命令,试图查看其中一台机器使用 NFS 共享文件系统的方式是否存在问题,但老实说,我所能找到的一切是给进程授予 sudo 权限解决了问题,我真的不明白。
我尝试在 slurm 脚本中回显一堆环境变量,以更好地了解计算节点如何尝试访问 conda 文件,但它们似乎都指向共享文件系统中的正确目录,所以再次没有运气。
如果您在一个用户的主目录中创建了 Conda 环境,然后将其移动到通用文件系统,请注意该安装中可能存在链接回原始用户主目录的硬编码路径。
移动 Conda 环境不能通过简单地
mv
' 来完成。请参阅Conda 文档的此页了解正确的方法。
由于
PermissionError
指的是 /home
中的目录,这可能就是问题所在。
还要确保安装 Conda 的目录的所有父级权限的所有父级都是正确的。将 Conda 目录设置为
chmod
(最好是 777
)本身是不够的。 755
命令可以提供帮助。