|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# This source code is licensed under the BSD-style license found in the |
| 6 | +# LICENSE file in the root directory of this source tree. |
| 7 | + |
| 8 | +if [ -z "${PYTHON_EXECUTABLE:-}" ]; |
| 9 | +then |
| 10 | + if [[ -z ${CONDA_DEFAULT_ENV:-} ]] || [[ ${CONDA_DEFAULT_ENV:-} == "base" ]] || [[ ! -x "$(command -v python)" ]]; |
| 11 | + then |
| 12 | + PYTHON_EXECUTABLE=python3 |
| 13 | + else |
| 14 | + PYTHON_EXECUTABLE=python |
| 15 | + fi |
| 16 | +fi |
| 17 | +echo "Using python executable: $PYTHON_EXECUTABLE" |
| 18 | + |
| 19 | +if [[ "$PYTHON_EXECUTABLE" == "python" ]]; |
| 20 | +then |
| 21 | + PIP_EXECUTABLE=pip |
| 22 | +elif [[ "$PYTHON_EXECUTABLE" == "python3" ]]; |
| 23 | +then |
| 24 | + PIP_EXECUTABLE=pip3 |
| 25 | +else |
| 26 | + PIP_EXECUTABLE=pip${PYTHON_SYS_VERSION} |
| 27 | +fi |
| 28 | +echo "Using pip executable: $PIP_EXECUTABLE" |
| 29 | + |
| 30 | +# Since torchchat often uses main-branch features of pytorch, only the nightly |
| 31 | +# pip versions will have the required features. The PYTORCH_NIGHTLY_VERSION value should |
| 32 | +# agree with the third-party/pytorch pinned submodule commit. |
| 33 | +# |
| 34 | +# NOTE: If a newly-fetched version of the executorch repo changes the value of |
| 35 | +# PYTORCH_NIGHTLY_VERSION, you should re-run this script to install the necessary |
| 36 | +# package versions. |
| 37 | +PYTORCH_NIGHTLY_VERSION=dev20250327 |
| 38 | + |
| 39 | +# Nightly version for torchvision |
| 40 | +VISION_NIGHTLY_VERSION=dev20250327 |
| 41 | + |
| 42 | +# Nightly version for torchtune |
| 43 | +TUNE_NIGHTLY_VERSION=dev20250327 |
| 44 | + |
| 45 | +# The pip repository that hosts nightly torch packages. cpu by default. |
| 46 | +# If cuda is available, based on presence of nvidia-smi, install the pytorch nightly |
| 47 | +# with cuda for faster execution on cuda GPUs. |
| 48 | +if [[ -x "$(command -v nvidia-smi)" ]]; |
| 49 | +then |
| 50 | + TORCH_NIGHTLY_URL="https://download.pytorch.org/whl/nightly/cu126" |
| 51 | +elif [[ -x "$(command -v rocminfo)" ]]; |
| 52 | +then |
| 53 | + TORCH_NIGHTLY_URL="https://download.pytorch.org/whl/nightly/rocm6.2" |
| 54 | +elif [[ -x "$(command -v xpu-smi)" ]]; |
| 55 | +then |
| 56 | + TORCH_NIGHTLY_URL="https://download.pytorch.org/whl/nightly/xpu" |
| 57 | +else |
| 58 | + TORCH_NIGHTLY_URL="https://download.pytorch.org/whl/nightly/cpu" |
| 59 | +fi |
| 60 | + |
| 61 | +# pip packages needed by exir. |
| 62 | +if [[ -x "$(command -v xpu-smi)" ]]; |
| 63 | +then |
| 64 | + REQUIREMENTS_TO_INSTALL=( |
| 65 | + torch=="2.8.0.${PYTORCH_NIGHTLY_VERSION}" |
| 66 | + torchvision=="0.22.0.${VISION_NIGHTLY_VERSION}" |
| 67 | + #torchtune=="0.7.0" # no 0.6.0 on xpu nightly |
| 68 | + ) |
| 69 | +else |
| 70 | + REQUIREMENTS_TO_INSTALL=( |
| 71 | + torch=="2.8.0.${PYTORCH_NIGHTLY_VERSION}" |
| 72 | + torchvision=="0.22.0.${VISION_NIGHTLY_VERSION}" |
| 73 | + torchtune=="0.7.0.${TUNE_NIGHTLY_VERSION}" |
| 74 | + ) |
| 75 | +fi |
| 76 | + |
| 77 | +# Uninstall triton, as nightly will depend on pytorch-triton, which is one and the same |
| 78 | +( |
| 79 | + set -x |
| 80 | + $PIP_EXECUTABLE uninstall -y triton |
| 81 | +) |
| 82 | + |
| 83 | +# Install the requirements. --extra-index-url tells pip to look for package |
| 84 | +# versions on the provided URL if they aren't available on the default URL. |
| 85 | +( |
| 86 | + set -x |
| 87 | + $PIP_EXECUTABLE install --extra-index-url "${TORCH_NIGHTLY_URL}" \ |
| 88 | + "${REQUIREMENTS_TO_INSTALL[@]}" |
| 89 | +) |
| 90 | + |
| 91 | +# Temporatory instal torchtune nightly from cpu nightly link since no torchtune nightly for xpu now |
| 92 | +# TODO: Change to install torchtune from xpu nightly link, once torchtune xpu nightly is ready |
| 93 | +if [[ -x "$(command -v xpu-smi)" ]]; |
| 94 | +then |
| 95 | +( |
| 96 | + set -x |
| 97 | + $PIP_EXECUTABLE install --extra-index-url "https://download.pytorch.org/whl/nightly/cpu" \ |
| 98 | + torchtune=="0.6.0.${TUNE_NIGHTLY_VERSION}" |
| 99 | +) |
| 100 | +fi |
| 101 | + |
| 102 | +bash install/install_torchao.sh |
| 103 | + |
| 104 | +# Delete since already patched in PT main |
| 105 | +if [[ -x "$(command -v nvidia-smi)" ]]; then |
| 106 | + ( |
| 107 | + set -x |
| 108 | + $PYTHON_EXECUTABLE torchchat/utils/scripts/patch_triton.py |
| 109 | + ) |
| 110 | +fi |
0 commit comments