Skip to content

Commit

Permalink
[fbgemm_gpu] Add script to install torchrec
Browse files Browse the repository at this point in the history
- Add script to install torchrec
  • Loading branch information
q10 committed Jul 16, 2024
1 parent a7ef792 commit 0a4ef5b
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/scripts/utils_torchrec.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.


# shellcheck disable=SC1091,SC2128
. "$( dirname -- "$BASH_SOURCE"; )/utils_base.bash"
# shellcheck disable=SC1091,SC2128
. "$( dirname -- "$BASH_SOURCE"; )/utils_conda.bash"
# shellcheck disable=SC1091,SC2128
. "$( dirname -- "$BASH_SOURCE"; )/utils_pip.bash"

################################################################################
# TorchRec Setup Functions
################################################################################

install_torchrec_pip () {
local env_name="$1"
local torchrec_channel_version="$2"
local torchrec_variant_type_version="$3"
if [ "$torchrec_variant_type_version" == "" ]; then
echo "Usage: ${FUNCNAME[0]} ENV_NAME PYTORCH_CHANNEL[/VERSION] PYTORCH_VARIANT_TYPE[/VARIANT_VERSION]"
echo "Example(s):"
echo " ${FUNCNAME[0]} build_env test/2.1.0rc0 cpu # Install the CPU variant for a specific version"
echo " ${FUNCNAME[0]} build_env release cpu # Install the CPU variant, latest release version"
echo " ${FUNCNAME[0]} build_env nightly/0.9.0.dev20240716 cuda/12.1.0 # Install the CUDA 12.1 variant, nightly version"
return 1
else
echo "################################################################################"
echo "# Install TorchRec (PIP)"
echo "#"
echo "# [$(date --utc +%FT%T.%3NZ)] + ${FUNCNAME[0]} ${*}"
echo "################################################################################"
echo ""
fi

# shellcheck disable=SC2155
local env_prefix=$(env_name_or_prefix "${env_name}")

echo "[INSTALL] Installing TorchRec dependencies ..."
# shellcheck disable=SC2086
(exec_with_retries 3 conda install ${env_prefix} -c conda-forge -y \
lightning-utilities) || return 1

# Install the package from TorchRec PIP (not PyPI)
install_from_pytorch_pip "${env_name}" torchrec "${torchrec_channel_version}" "${torchrec_variant_type_version}" || return 1

# Exit this directory to prevent import clashing, since there might be an
# fbgemm_gpu/ subdirectory present
cd - || return 1

# Check that TorchRec is importable
(test_python_import_package "${env_name}" torchrec) || return 1

# Print out the actual installed TorchRec version
# shellcheck disable=SC2086,SC2155
local installed_torchrec_version=$(conda run ${env_prefix} python -c "import torchrec; print(torchrec.__version__)")
echo "[CHECK] NOTE: The installed version is: ${installed_torchrec_version}"

cd - || return 1
echo "[INSTALL] Successfully installed TorchRec through PyTorch PIP"
}

0 comments on commit 0a4ef5b

Please sign in to comment.