Python应用多副本配置步骤
- 安装pyinstaller打包库。
yum install pyinstaller - 安装其他Python依赖库。
pip install pyyaml pip install typing_extensions pip install pympler pip install ninja yum install patchelf - 进入需要打包的Python应用根目录,建立文件夹lib_py,并将该应用所依赖的所有.so文件和数据文件放置在lib_py目录下。
- 执行打包脚本py_install.sh。
#!/bin/bash set -e pyinstaller \ --name=app_name \ # Application name --onefile \ --add-binary="lib_py/*.so:lib_py" \ # Binary files required --add-data="lib_py:lib_py" \ # Data files required --hidden-import=app_name \ # If the entry file of the Python application imports this application, this line is required; otherwise, please ignore it. --hidden-import=torch \ app_entry.py # Entry python file echo "onefile build complete! Binary: dist/app_name" - 建立rankfile。
#示例 rank 0=localhost slot=0-35 rank 1=localhost slot=38-73 rank 2=localhost slot=76-111 rank 3=localhost slot=114-149 rank 4=localhost slot=152-187 rank 5=localhost slot=190-225 rank 6=localhost slot=228-263 rank 7=localhost slot=266-301
- mpirun多副本运行(以8进程36线程应用为例),建立脚本run.sh并执行。
#!/bin/bash export OMP_NUM_THREADS=36 export OMP_PROC_BIND=close mpirun \ -np 8 \ -rf rankfile \ -x OMP_NUM_THREADS \ bash -c ' exec ./dist/app_name … '# Provide the necessary runtime parameters at …补充:如果运行时出现内存消耗会异常增长导致无法运行,请将步骤4中:
--onefile修改为--onedir,并将运行脚本最后一行修改为:
exec ./dist/app_name/app_name … '# Provide the necessary runtime parameters at …(该方式存在性能衰减的风险,请根据实际情况按需求使用)。
父主题: 应用多副本配置