Skip to content

Commit 2f9298d

Browse files
ooctipusMayankm96
andauthored
Simplifies cross platform installation setup.py (isaac-sim#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: Mayank Mittal <12863862+Mayankm96@users.noreply.github.com>
1 parent dddd51d commit 2f9298d

3 files changed

Lines changed: 75 additions & 56 deletions

File tree

isaaclab.bat

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,33 @@ if not exist "%isaac_path%" (
3838
)
3939
goto :eof
4040

41+
rem --- Ensure CUDA PyTorch helper ------------------------------------------
42+
:ensure_cuda_torch
43+
rem expects: !python_exe! set by :extract_python_exe
44+
setlocal EnableExtensions EnableDelayedExpansion
45+
set "TORCH_VER=2.7.0"
46+
set "TV_VER=0.22.0"
47+
set "CUDA_TAG=cu128"
48+
set "PYTORCH_INDEX=https://download.pytorch.org/whl/%CUDA_TAG%"
49+
50+
rem Do we already have torch?
51+
call "!python_exe!" -m pip show torch >nul 2>&1
52+
if errorlevel 1 (
53+
echo [INFO] Installing PyTorch !TORCH_VER! with CUDA !CUDA_TAG!...
54+
call "!python_exe!" -m pip install "torch==!TORCH_VER!" "torchvision==!TV_VER!" --index-url "!PYTORCH_INDEX!"
55+
) else (
56+
for /f "tokens=2" %%V in ('"!python_exe!" -m pip show torch ^| findstr /B /C:"Version:"') do set "TORCH_CUR=%%V"
57+
echo [INFO] Found PyTorch version !TORCH_CUR!.
58+
if /I not "!TORCH_CUR!"=="!TORCH_VER!+!CUDA_TAG!" (
59+
echo [INFO] Replacing PyTorch !TORCH_CUR! -> !TORCH_VER!+!CUDA_TAG!...
60+
call "!python_exe!" -m pip uninstall -y torch torchvision torchaudio >nul 2>&1
61+
call "!python_exe!" -m pip install "torch==!TORCH_VER!" "torchvision==!TV_VER!" --index-url "!PYTORCH_INDEX!"
62+
) else (
63+
echo [INFO] PyTorch !TORCH_VER!+!CUDA_TAG! already installed.
64+
)
65+
)
66+
endlocal & exit /b 0
67+
4168
rem -----------------------------------------------------------------------
4269
rem Returns success (exit code 0) if Isaac Sim's version starts with "4.5"
4370
rem -----------------------------------------------------------------------
@@ -334,23 +361,7 @@ if "%arg%"=="-i" (
334361
call :extract_python_exe
335362
rem check if pytorch is installed and its version
336363
rem install pytorch with cuda 12.8 for blackwell support
337-
call !python_exe! -m pip list | findstr /C:"torch" >nul
338-
if %errorlevel% equ 0 (
339-
for /f "tokens=2" %%i in ('!python_exe! -m pip show torch ^| findstr /C:"Version:"') do (
340-
set torch_version=%%i
341-
)
342-
if not "!torch_version!"=="2.7.0+cu128" (
343-
echo [INFO] Uninstalling PyTorch version !torch_version!...
344-
call !python_exe! -m pip uninstall -y torch torchvision torchaudio
345-
echo [INFO] Installing PyTorch 2.7.0 with CUDA 12.8 support...
346-
call !python_exe! -m pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128
347-
) else (
348-
echo [INFO] PyTorch 2.7.0 is already installed.
349-
)
350-
) else (
351-
echo [INFO] Installing PyTorch 2.7.0 with CUDA 12.8 support...
352-
call !python_exe! -m pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128
353-
)
364+
call :ensure_cuda_torch
354365

355366
for /d %%d in ("%ISAACLAB_PATH%\source\*") do (
356367
set ext_folder="%%d"
@@ -372,30 +383,21 @@ if "%arg%"=="-i" (
372383
)
373384
rem install the rl-frameworks specified
374385
call !python_exe! -m pip install -e %ISAACLAB_PATH%\source\isaaclab_rl[!framework_name!]
386+
rem in rare case if some packages or flaky setup override default torch installation, ensure right torch is
387+
rem installed again
388+
call :ensure_cuda_torch
389+
rem update the vscode settings
390+
rem once we have a docker container, we need to disable vscode settings
391+
call :update_vscode_settings
392+
shift
375393
shift
376394
) else if "%arg%"=="--install" (
377395
rem install the python packages in source directory
378396
echo [INFO] Installing extensions inside the Isaac Lab repository...
379397
call :extract_python_exe
380398
rem check if pytorch is installed and its version
381399
rem install pytorch with cuda 12.8 for blackwell support
382-
call !python_exe! -m pip list | findstr /C:"torch" >nul
383-
if %errorlevel% equ 0 (
384-
for /f "tokens=2" %%i in ('!python_exe! -m pip show torch ^| findstr /C:"Version:"') do (
385-
set torch_version=%%i
386-
)
387-
if not "!torch_version!"=="2.7.0+cu128" (
388-
echo [INFO] Uninstalling PyTorch version !torch_version!...
389-
call !python_exe! -m pip uninstall -y torch torchvision torchaudio
390-
echo [INFO] Installing PyTorch 2.7.0 with CUDA 12.8 support...
391-
call !python_exe! -m pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128
392-
) else (
393-
echo [INFO] PyTorch 2.7.0 is already installed.
394-
)
395-
) else (
396-
echo [INFO] Installing PyTorch 2.7.0 with CUDA 12.8 support...
397-
call !python_exe! -m pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128
398-
)
400+
call :ensure_cuda_torch
399401

400402
for /d %%d in ("%ISAACLAB_PATH%\source\*") do (
401403
set ext_folder="%%d"
@@ -417,6 +419,9 @@ if "%arg%"=="-i" (
417419
)
418420
rem install the rl-frameworks specified
419421
call !python_exe! -m pip install -e %ISAACLAB_PATH%\source\isaaclab_rl[!framework_name!]
422+
rem in rare case if some packages or flaky setup override default torch installation, ensure right torch is
423+
rem installed again
424+
call :ensure_cuda_torch
420425
rem update the vscode settings
421426
rem once we have a docker container, we need to disable vscode settings
422427
call :update_vscode_settings

isaaclab.sh

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,30 @@ is_docker() {
9696
[[ "$(hostname)" == *"."* ]]
9797
}
9898

99+
ensure_cuda_torch() {
100+
local py="$1"
101+
local -r TORCH_VER="2.7.0"
102+
local -r TV_VER="0.22.0"
103+
local -r CUDA_TAG="cu128"
104+
local -r PYTORCH_INDEX="https://download.pytorch.org/whl/${CUDA_TAG}"
105+
local torch_ver
106+
107+
if "$py" -m pip show torch >/dev/null 2>&1; then
108+
torch_ver="$("$py" -m pip show torch 2>/dev/null | awk -F': ' '/^Version/{print $2}')"
109+
echo "[INFO] Found PyTorch version ${torch_ver}."
110+
if [[ "$torch_ver" != "${TORCH_VER}+${CUDA_TAG}" ]]; then
111+
echo "[INFO] Replacing PyTorch ${torch_ver}${TORCH_VER}+${CUDA_TAG}..."
112+
"$py" -m pip uninstall -y torch torchvision torchaudio >/dev/null 2>&1 || true
113+
"$py" -m pip install "torch==${TORCH_VER}" "torchvision==${TV_VER}" --index-url "${PYTORCH_INDEX}"
114+
else
115+
echo "[INFO] PyTorch ${TORCH_VER}+${CUDA_TAG} already installed."
116+
fi
117+
else
118+
echo "[INFO] Installing PyTorch ${TORCH_VER}+${CUDA_TAG}..."
119+
"$py" -m pip install "torch==${TORCH_VER}" "torchvision==${TV_VER}" --index-url "${PYTORCH_INDEX}"
120+
fi
121+
}
122+
99123
# extract isaac sim path
100124
extract_isaacsim_path() {
101125
# Use the sym-link path to Isaac Sim directory
@@ -364,21 +388,7 @@ while [[ $# -gt 0 ]]; do
364388
python_exe=$(extract_python_exe)
365389
# check if pytorch is installed and its version
366390
# install pytorch with cuda 12.8 for blackwell support
367-
if ${python_exe} -m pip list 2>/dev/null | grep -q "torch"; then
368-
torch_version=$(${python_exe} -m pip show torch 2>/dev/null | grep "Version:" | awk '{print $2}')
369-
echo "[INFO] Found PyTorch version ${torch_version} installed."
370-
if [[ "${torch_version}" != "2.7.0+cu128" ]]; then
371-
echo "[INFO] Uninstalling PyTorch version ${torch_version}..."
372-
${python_exe} -m pip uninstall -y torch torchvision torchaudio
373-
echo "[INFO] Installing PyTorch 2.7.0 with CUDA 12.8 support..."
374-
${python_exe} -m pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128
375-
else
376-
echo "[INFO] PyTorch 2.7.0 is already installed."
377-
fi
378-
else
379-
echo "[INFO] Installing PyTorch 2.7.0 with CUDA 12.8 support..."
380-
${python_exe} -m pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128
381-
fi
391+
ensure_cuda_torch ${python_exe}
382392
# recursively look into directories and install them
383393
# this does not check dependencies between extensions
384394
export -f extract_python_exe
@@ -404,6 +414,9 @@ while [[ $# -gt 0 ]]; do
404414
${python_exe} -m pip install -e ${ISAACLAB_PATH}/source/isaaclab_rl["${framework_name}"]
405415
${python_exe} -m pip install -e ${ISAACLAB_PATH}/source/isaaclab_mimic["${framework_name}"]
406416

417+
# in some rare cases, torch might not be installed properly by setup.py, add one more check here
418+
# can prevent that from happening
419+
ensure_cuda_torch ${python_exe}
407420
# check if we are inside a docker container or are building a docker image
408421
# in that case don't setup VSCode since it asks for EULA agreement which triggers user interaction
409422
if is_docker; then

source/isaaclab/setup.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"""Installation script for the 'isaaclab' python package."""
77

88
import os
9-
import platform
109
import toml
1110

1211
from setuptools import setup
@@ -47,12 +46,14 @@
4746
"flaky",
4847
]
4948

50-
# Additional dependencies that are only available on Linux platforms
51-
if platform.system() == "Linux":
52-
INSTALL_REQUIRES += [
53-
"pin-pink==3.1.0", # required by isaaclab.isaaclab.controllers.pink_ik
54-
"dex-retargeting==0.4.6", # required by isaaclab.devices.openxr.retargeters.humanoid.fourier.gr1_t2_dex_retargeting_utils
55-
]
49+
# Append Linux x86_64–only deps via PEP 508 markers
50+
X64 = "platform_machine in 'x86_64,AMD64'"
51+
INSTALL_REQUIRES += [
52+
# required by isaaclab.isaaclab.controllers.pink_ik
53+
f"pin-pink==3.1.0 ; platform_system == 'Linux' and ({X64})",
54+
# required by isaaclab.devices.openxr.retargeters.humanoid.fourier.gr1_t2_dex_retargeting_utils
55+
f"dex-retargeting==0.4.6 ; platform_system == 'Linux' and ({X64})",
56+
]
5657

5758
PYTORCH_INDEX_URL = ["https://download.pytorch.org/whl/cu128"]
5859

0 commit comments

Comments
 (0)