在GCP可抢占虚拟机上的启动脚本中运行conda命令

2024-06-02 13:51:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在一个可抢占的谷歌虚拟机上运行一个深度学习模型。我正在使用anaconda和TensorFlow来运行我的代码。当我ssh到机器中并手动运行python脚本时,它工作得很好。考虑到机器是可抢占的,我创建了一个云调度器,如果每15分钟抢占一次,它就可以启动实例。现在,我正在编写一个启动脚本,以从终止点恢复模型

我安装了anaconda,以便在名为tf的conda环境中,所有用户和tensorflow都可以访问它。 这是我的启动脚本

#! /bin/bash
sudo -u subhashnerella bash -c 'cd ~/Project;. ./startup.sh'

运行位于用户“subhashnerella”主页/项目中的startup.sh

内部startup.sh

#! /bin/bash
eval "$(conda shell.bash hook)"
conda activate tf
python start.py

在这里,我激活了conda环境并运行start.py来训练我的模型

测试启动脚本时出现的错误

(base) subhashnerella@instance-1:~$ sudo google_metadata_script_runner --script-type startup --debug
startup-script: INFO Starting startup scripts.
startup-script: INFO Found startup-script in metadata.
startup-script: INFO startup-script: ./startup.sh: line 2: conda: command not found
startup-script: INFO startup-script: ./startup.sh: line 2: $'\r': command not found
startup-script: INFO startup-script: ./startup.sh: line 3: conda: command not found
startup-script: INFO startup-script: ./startup.sh: line 4: python: command not found
startup-script: INFO startup-script: ./startup.sh: line 5: $'\r': command not found
startup-script: INFO startup-script: ./startup.sh: line 6: $'\r': command not found
startup-script: INFO startup-script: Return code 127.
startup-script: INFO Finished running startup scripts.

它无法检测conda命令和python。我该如何解决这个问题


Tags: 模型info脚本bash机器shlinescript