Unverified Commit 2f9298d7 authored by ooctipus's avatar ooctipus Committed by GitHub

Simplifies cross platform installation setup.py (#3294)

# Description

This PR 

1. makes sure(skip if already satisfy, else install) the right torch is
installed before and after pip installing isaaclab packages as
sometime(rare case) due to flaky setup.py and unknown library
dependencies changes pytorch version gets overriden.

2. only install pink and retargeters in linux x86 or amd64 machines


## Type of change

<!-- As you go through the list, delete the ones that are not
applicable. -->

- Bug fix (non-breaking change which fixes an issue)

## Screenshots

Please attach before and after screenshots of the change if applicable.

<!--
Example:

| Before | After |
| ------ | ----- |
| _gif/png before_ | _gif/png after_ |

To upload images to a PR -- simply drag and drop an image while in edit
mode and it should upload the image directly. You can then paste that
source into the above before/after sections.
-->

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->

---------
Co-authored-by: 's avatarMayank Mittal <12863862+Mayankm96@users.noreply.github.com>
parent dddd51db
...@@ -38,6 +38,33 @@ if not exist "%isaac_path%" ( ...@@ -38,6 +38,33 @@ if not exist "%isaac_path%" (
) )
goto :eof goto :eof
rem --- Ensure CUDA PyTorch helper ------------------------------------------
:ensure_cuda_torch
rem expects: !python_exe! set by :extract_python_exe
setlocal EnableExtensions EnableDelayedExpansion
set "TORCH_VER=2.7.0"
set "TV_VER=0.22.0"
set "CUDA_TAG=cu128"
set "PYTORCH_INDEX=https://download.pytorch.org/whl/%CUDA_TAG%"
rem Do we already have torch?
call "!python_exe!" -m pip show torch >nul 2>&1
if errorlevel 1 (
echo [INFO] Installing PyTorch !TORCH_VER! with CUDA !CUDA_TAG!...
call "!python_exe!" -m pip install "torch==!TORCH_VER!" "torchvision==!TV_VER!" --index-url "!PYTORCH_INDEX!"
) else (
for /f "tokens=2" %%V in ('"!python_exe!" -m pip show torch ^| findstr /B /C:"Version:"') do set "TORCH_CUR=%%V"
echo [INFO] Found PyTorch version !TORCH_CUR!.
if /I not "!TORCH_CUR!"=="!TORCH_VER!+!CUDA_TAG!" (
echo [INFO] Replacing PyTorch !TORCH_CUR! -> !TORCH_VER!+!CUDA_TAG!...
call "!python_exe!" -m pip uninstall -y torch torchvision torchaudio >nul 2>&1
call "!python_exe!" -m pip install "torch==!TORCH_VER!" "torchvision==!TV_VER!" --index-url "!PYTORCH_INDEX!"
) else (
echo [INFO] PyTorch !TORCH_VER!+!CUDA_TAG! already installed.
)
)
endlocal & exit /b 0
rem ----------------------------------------------------------------------- rem -----------------------------------------------------------------------
rem Returns success (exit code 0) if Isaac Sim's version starts with "4.5" rem Returns success (exit code 0) if Isaac Sim's version starts with "4.5"
rem ----------------------------------------------------------------------- rem -----------------------------------------------------------------------
...@@ -334,23 +361,7 @@ if "%arg%"=="-i" ( ...@@ -334,23 +361,7 @@ if "%arg%"=="-i" (
call :extract_python_exe call :extract_python_exe
rem check if pytorch is installed and its version rem check if pytorch is installed and its version
rem install pytorch with cuda 12.8 for blackwell support rem install pytorch with cuda 12.8 for blackwell support
call !python_exe! -m pip list | findstr /C:"torch" >nul call :ensure_cuda_torch
if %errorlevel% equ 0 (
for /f "tokens=2" %%i in ('!python_exe! -m pip show torch ^| findstr /C:"Version:"') do (
set torch_version=%%i
)
if not "!torch_version!"=="2.7.0+cu128" (
echo [INFO] Uninstalling PyTorch version !torch_version!...
call !python_exe! -m pip uninstall -y torch torchvision torchaudio
echo [INFO] Installing PyTorch 2.7.0 with CUDA 12.8 support...
call !python_exe! -m pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128
) else (
echo [INFO] PyTorch 2.7.0 is already installed.
)
) else (
echo [INFO] Installing PyTorch 2.7.0 with CUDA 12.8 support...
call !python_exe! -m pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128
)
for /d %%d in ("%ISAACLAB_PATH%\source\*") do ( for /d %%d in ("%ISAACLAB_PATH%\source\*") do (
set ext_folder="%%d" set ext_folder="%%d"
...@@ -372,6 +383,13 @@ if "%arg%"=="-i" ( ...@@ -372,6 +383,13 @@ if "%arg%"=="-i" (
) )
rem install the rl-frameworks specified rem install the rl-frameworks specified
call !python_exe! -m pip install -e %ISAACLAB_PATH%\source\isaaclab_rl[!framework_name!] call !python_exe! -m pip install -e %ISAACLAB_PATH%\source\isaaclab_rl[!framework_name!]
rem in rare case if some packages or flaky setup override default torch installation, ensure right torch is
rem installed again
call :ensure_cuda_torch
rem update the vscode settings
rem once we have a docker container, we need to disable vscode settings
call :update_vscode_settings
shift
shift shift
) else if "%arg%"=="--install" ( ) else if "%arg%"=="--install" (
rem install the python packages in source directory rem install the python packages in source directory
...@@ -379,23 +397,7 @@ if "%arg%"=="-i" ( ...@@ -379,23 +397,7 @@ if "%arg%"=="-i" (
call :extract_python_exe call :extract_python_exe
rem check if pytorch is installed and its version rem check if pytorch is installed and its version
rem install pytorch with cuda 12.8 for blackwell support rem install pytorch with cuda 12.8 for blackwell support
call !python_exe! -m pip list | findstr /C:"torch" >nul call :ensure_cuda_torch
if %errorlevel% equ 0 (
for /f "tokens=2" %%i in ('!python_exe! -m pip show torch ^| findstr /C:"Version:"') do (
set torch_version=%%i
)
if not "!torch_version!"=="2.7.0+cu128" (
echo [INFO] Uninstalling PyTorch version !torch_version!...
call !python_exe! -m pip uninstall -y torch torchvision torchaudio
echo [INFO] Installing PyTorch 2.7.0 with CUDA 12.8 support...
call !python_exe! -m pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128
) else (
echo [INFO] PyTorch 2.7.0 is already installed.
)
) else (
echo [INFO] Installing PyTorch 2.7.0 with CUDA 12.8 support...
call !python_exe! -m pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128
)
for /d %%d in ("%ISAACLAB_PATH%\source\*") do ( for /d %%d in ("%ISAACLAB_PATH%\source\*") do (
set ext_folder="%%d" set ext_folder="%%d"
...@@ -417,6 +419,9 @@ if "%arg%"=="-i" ( ...@@ -417,6 +419,9 @@ if "%arg%"=="-i" (
) )
rem install the rl-frameworks specified rem install the rl-frameworks specified
call !python_exe! -m pip install -e %ISAACLAB_PATH%\source\isaaclab_rl[!framework_name!] call !python_exe! -m pip install -e %ISAACLAB_PATH%\source\isaaclab_rl[!framework_name!]
rem in rare case if some packages or flaky setup override default torch installation, ensure right torch is
rem installed again
call :ensure_cuda_torch
rem update the vscode settings rem update the vscode settings
rem once we have a docker container, we need to disable vscode settings rem once we have a docker container, we need to disable vscode settings
call :update_vscode_settings call :update_vscode_settings
......
...@@ -96,6 +96,30 @@ is_docker() { ...@@ -96,6 +96,30 @@ is_docker() {
[[ "$(hostname)" == *"."* ]] [[ "$(hostname)" == *"."* ]]
} }
ensure_cuda_torch() {
local py="$1"
local -r TORCH_VER="2.7.0"
local -r TV_VER="0.22.0"
local -r CUDA_TAG="cu128"
local -r PYTORCH_INDEX="https://download.pytorch.org/whl/${CUDA_TAG}"
local torch_ver
if "$py" -m pip show torch >/dev/null 2>&1; then
torch_ver="$("$py" -m pip show torch 2>/dev/null | awk -F': ' '/^Version/{print $2}')"
echo "[INFO] Found PyTorch version ${torch_ver}."
if [[ "$torch_ver" != "${TORCH_VER}+${CUDA_TAG}" ]]; then
echo "[INFO] Replacing PyTorch ${torch_ver}${TORCH_VER}+${CUDA_TAG}..."
"$py" -m pip uninstall -y torch torchvision torchaudio >/dev/null 2>&1 || true
"$py" -m pip install "torch==${TORCH_VER}" "torchvision==${TV_VER}" --index-url "${PYTORCH_INDEX}"
else
echo "[INFO] PyTorch ${TORCH_VER}+${CUDA_TAG} already installed."
fi
else
echo "[INFO] Installing PyTorch ${TORCH_VER}+${CUDA_TAG}..."
"$py" -m pip install "torch==${TORCH_VER}" "torchvision==${TV_VER}" --index-url "${PYTORCH_INDEX}"
fi
}
# extract isaac sim path # extract isaac sim path
extract_isaacsim_path() { extract_isaacsim_path() {
# Use the sym-link path to Isaac Sim directory # Use the sym-link path to Isaac Sim directory
...@@ -364,21 +388,7 @@ while [[ $# -gt 0 ]]; do ...@@ -364,21 +388,7 @@ while [[ $# -gt 0 ]]; do
python_exe=$(extract_python_exe) python_exe=$(extract_python_exe)
# check if pytorch is installed and its version # check if pytorch is installed and its version
# install pytorch with cuda 12.8 for blackwell support # install pytorch with cuda 12.8 for blackwell support
if ${python_exe} -m pip list 2>/dev/null | grep -q "torch"; then ensure_cuda_torch ${python_exe}
torch_version=$(${python_exe} -m pip show torch 2>/dev/null | grep "Version:" | awk '{print $2}')
echo "[INFO] Found PyTorch version ${torch_version} installed."
if [[ "${torch_version}" != "2.7.0+cu128" ]]; then
echo "[INFO] Uninstalling PyTorch version ${torch_version}..."
${python_exe} -m pip uninstall -y torch torchvision torchaudio
echo "[INFO] Installing PyTorch 2.7.0 with CUDA 12.8 support..."
${python_exe} -m pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128
else
echo "[INFO] PyTorch 2.7.0 is already installed."
fi
else
echo "[INFO] Installing PyTorch 2.7.0 with CUDA 12.8 support..."
${python_exe} -m pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128
fi
# recursively look into directories and install them # recursively look into directories and install them
# this does not check dependencies between extensions # this does not check dependencies between extensions
export -f extract_python_exe export -f extract_python_exe
...@@ -404,6 +414,9 @@ while [[ $# -gt 0 ]]; do ...@@ -404,6 +414,9 @@ while [[ $# -gt 0 ]]; do
${python_exe} -m pip install -e ${ISAACLAB_PATH}/source/isaaclab_rl["${framework_name}"] ${python_exe} -m pip install -e ${ISAACLAB_PATH}/source/isaaclab_rl["${framework_name}"]
${python_exe} -m pip install -e ${ISAACLAB_PATH}/source/isaaclab_mimic["${framework_name}"] ${python_exe} -m pip install -e ${ISAACLAB_PATH}/source/isaaclab_mimic["${framework_name}"]
# in some rare cases, torch might not be installed properly by setup.py, add one more check here
# can prevent that from happening
ensure_cuda_torch ${python_exe}
# check if we are inside a docker container or are building a docker image # check if we are inside a docker container or are building a docker image
# in that case don't setup VSCode since it asks for EULA agreement which triggers user interaction # in that case don't setup VSCode since it asks for EULA agreement which triggers user interaction
if is_docker; then if is_docker; then
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
"""Installation script for the 'isaaclab' python package.""" """Installation script for the 'isaaclab' python package."""
import os import os
import platform
import toml import toml
from setuptools import setup from setuptools import setup
...@@ -47,12 +46,14 @@ INSTALL_REQUIRES = [ ...@@ -47,12 +46,14 @@ INSTALL_REQUIRES = [
"flaky", "flaky",
] ]
# Additional dependencies that are only available on Linux platforms # Append Linux x86_64–only deps via PEP 508 markers
if platform.system() == "Linux": X64 = "platform_machine in 'x86_64,AMD64'"
INSTALL_REQUIRES += [ INSTALL_REQUIRES += [
"pin-pink==3.1.0", # required by isaaclab.isaaclab.controllers.pink_ik # required by isaaclab.isaaclab.controllers.pink_ik
"dex-retargeting==0.4.6", # required by isaaclab.devices.openxr.retargeters.humanoid.fourier.gr1_t2_dex_retargeting_utils f"pin-pink==3.1.0 ; platform_system == 'Linux' and ({X64})",
] # required by isaaclab.devices.openxr.retargeters.humanoid.fourier.gr1_t2_dex_retargeting_utils
f"dex-retargeting==0.4.6 ; platform_system == 'Linux' and ({X64})",
]
PYTORCH_INDEX_URL = ["https://download.pytorch.org/whl/cu128"] PYTORCH_INDEX_URL = ["https://download.pytorch.org/whl/cu128"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment