|
37 | 37 | SKY_PYTHON_CMD = f'$({SKY_GET_PYTHON_PATH_CMD})'
|
38 | 38 | SKY_PIP_CMD = f'{SKY_PYTHON_CMD} -m pip'
|
39 | 39 | # Ray executable, e.g., /opt/conda/bin/ray
|
40 |
| -SKY_RAY_CMD = (f'$([ -s {SKY_RAY_PATH_FILE} ] && ' |
| 40 | +# We need to add SKY_PYTHON_CMD before ray executable because: |
| 41 | +# The ray executable is a python script with a header like: |
| 42 | +# #!/opt/conda/bin/python3 |
| 43 | +# When we create the skypilot-runtime venv, the previously installed ray |
| 44 | +# executable will be reused (due to --system-site-packages), and that will cause |
| 45 | +# running ray CLI commands to use the wrong python executable. |
| 46 | +SKY_RAY_CMD = (f'{SKY_PYTHON_CMD} $([ -s {SKY_RAY_PATH_FILE} ] && ' |
41 | 47 | f'cat {SKY_RAY_PATH_FILE} 2> /dev/null || which ray)')
|
| 48 | +# Separate env for SkyPilot runtime dependencies. |
| 49 | +SKY_REMOTE_PYTHON_ENV_NAME = 'skypilot-runtime' |
| 50 | +SKY_REMOTE_PYTHON_ENV = f'~/{SKY_REMOTE_PYTHON_ENV_NAME}' |
| 51 | +ACTIVATE_SKY_REMOTE_PYTHON_ENV = f'source {SKY_REMOTE_PYTHON_ENV}/bin/activate' |
42 | 52 |
|
43 | 53 | # The name for the environment variable that stores the unique ID of the
|
44 | 54 | # current task. This will stay the same across multiple recoveries of the
|
|
91 | 101 | # AWS's Deep Learning AMI's default conda environment.
|
92 | 102 | CONDA_INSTALLATION_COMMANDS = (
|
93 | 103 | 'which conda > /dev/null 2>&1 || '
|
94 |
| - '{ wget -nc https://repo.anaconda.com/miniconda/Miniconda3-py310_23.11.0-2-Linux-x86_64.sh -O Miniconda3-Linux-x86_64.sh && ' # pylint: disable=line-too-long |
| 104 | + '{ curl https://repo.anaconda.com/miniconda/Miniconda3-py310_23.11.0-2-Linux-x86_64.sh -o Miniconda3-Linux-x86_64.sh && ' # pylint: disable=line-too-long |
95 | 105 | 'bash Miniconda3-Linux-x86_64.sh -b && '
|
96 | 106 | 'eval "$(~/miniconda3/bin/conda shell.bash hook)" && conda init && '
|
97 | 107 | 'conda config --set auto_activate_base true && '
|
98 |
| - # Use $(echo ~) instead of ~ to avoid the error "no such file or directory". |
99 |
| - # Also, not using $HOME to avoid the error HOME variable not set. |
100 |
| - f'echo "$(echo ~)/miniconda3/bin/python" > {SKY_PYTHON_PATH_FILE}; }}; ' |
| 108 | + f'conda activate base; }}; ' |
101 | 109 | 'grep "# >>> conda initialize >>>" ~/.bashrc || '
|
102 | 110 | '{ conda init && source ~/.bashrc; };'
|
103 |
| - '(type -a python | grep -q python3) || ' |
104 |
| - 'echo \'alias python=python3\' >> ~/.bashrc;' |
105 |
| - '(type -a pip | grep -q pip3) || echo \'alias pip=pip3\' >> ~/.bashrc;' |
106 |
| - # Writes Python path to file if it does not exist or the file is empty. |
107 |
| - f'[ -s {SKY_PYTHON_PATH_FILE} ] || which python3 > {SKY_PYTHON_PATH_FILE};') |
| 111 | + # If Python version is larger then equal to 3.12, create a new conda env |
| 112 | + # with Python 3.10. |
| 113 | + # We don't use a separate conda env for SkyPilot dependencies because it is |
| 114 | + # costly to create a new conda env, and venv should be a lightweight and |
| 115 | + # faster alternative when the python version satisfies the requirement. |
| 116 | + '[[ $(python3 --version | cut -d " " -f 2 | cut -d "." -f 2) -ge 12 ]] && ' |
| 117 | + f'echo "Creating conda env with Python 3.10" && ' |
| 118 | + f'conda create -y -n {SKY_REMOTE_PYTHON_ENV_NAME} python=3.10 && ' |
| 119 | + f'conda activate {SKY_REMOTE_PYTHON_ENV_NAME};' |
| 120 | + # Create a separate conda environment for SkyPilot dependencies. |
| 121 | + f'[ -d {SKY_REMOTE_PYTHON_ENV} ] || ' |
| 122 | + f'{{ {SKY_PYTHON_CMD} -m venv {SKY_REMOTE_PYTHON_ENV} --system-site-packages && ' |
| 123 | + f'echo "$(echo {SKY_REMOTE_PYTHON_ENV})/bin/python" > {SKY_PYTHON_PATH_FILE}; }};' |
| 124 | +) |
108 | 125 |
|
109 | 126 | _sky_version = str(version.parse(sky.__version__))
|
110 | 127 | RAY_STATUS = f'RAY_ADDRESS=127.0.0.1:{SKY_REMOTE_RAY_PORT} {SKY_RAY_CMD} status'
|
|
142 | 159 | # mentioned above are resolved.
|
143 | 160 | 'export PATH=$PATH:$HOME/.local/bin; '
|
144 | 161 | # Writes ray path to file if it does not exist or the file is empty.
|
145 |
| - f'[ -s {SKY_RAY_PATH_FILE} ] || which ray > {SKY_RAY_PATH_FILE}; ' |
| 162 | + f'[ -s {SKY_RAY_PATH_FILE} ] || ' |
| 163 | + f'{{ {ACTIVATE_SKY_REMOTE_PYTHON_ENV} && ' |
| 164 | + f'which ray > {SKY_RAY_PATH_FILE} || exit 1; }}; ' |
146 | 165 | # END ray package check and installation
|
147 | 166 | f'{{ {SKY_PIP_CMD} list | grep "skypilot " && '
|
148 | 167 | '[ "$(cat ~/.sky/wheels/current_sky_wheel_hash)" == "{sky_wheel_hash}" ]; } || ' # pylint: disable=line-too-long
|
|
0 commit comments