Unverified Commit 92238362 authored by Jadeiin's avatar Jadeiin Committed by GitHub

Refactors ensure_cuda_torch function to use extracted python and pip commands (#3949)

# Description

<!--
Thank you for your interest in sending a pull request. Please make sure
to check the contribution guidelines.

Link:
https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html

💡 Please try to keep PRs small and focused. Large PRs are harder to
review and merge.
-->

Since the latest update in `isaaclab.sh` breaks installation with uv, I
modified `ensure_cuda_torch` to maintain compatiability with uv
installation method. Tested on my machine and it works

Fixes #3524

<!-- As a practice, it is recommended to open an issue to have
discussions on the proposed pull request.
This makes it easier for the community to keep track of what is being
developed or added, and if a given feature
is demanded by more than one party. -->

## 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 read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [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
- [x] 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 avatarKelly Guo <kellyg@nvidia.com>
parent e6815583
...@@ -150,6 +150,7 @@ Guidelines for modifications: ...@@ -150,6 +150,7 @@ Guidelines for modifications:
* Yujian Zhang * Yujian Zhang
* Yun Liu * Yun Liu
* Zehao Wang * Zehao Wang
* Zijian Li
* Ziqi Fan * Ziqi Fan
* Zoe McCarthy * Zoe McCarthy
* David Leon * David Leon
......
...@@ -102,9 +102,10 @@ is_arm() { ...@@ -102,9 +102,10 @@ is_arm() {
} }
ensure_cuda_torch() { ensure_cuda_torch() {
local py="$1" local python_exe=$(extract_python_exe)
local pip_install_command=$(extract_pip_command)
# base base index for torch local pip_uninstall_command=$(extract_pip_uninstall_command)
# base index for torch
local base_index="https://download.pytorch.org/whl" local base_index="https://download.pytorch.org/whl"
# choose pins per arch # choose pins per arch
...@@ -124,9 +125,15 @@ ensure_cuda_torch() { ...@@ -124,9 +125,15 @@ ensure_cuda_torch() {
# check current torch version (may be empty) # check current torch version (may be empty)
local cur="" local cur=""
if "$py" -m pip show torch >/dev/null 2>&1; then cur="$(${python_exe} - <<'PY' 2>/dev/null || true
cur="$("$py" -m pip show torch 2>/dev/null | awk -F': ' '/^Version/{print $2}')" try:
fi import torch
except Exception:
pass
else:
print(torch.__version__, end="")
PY
)"
# skip install if version is already satisfied # skip install if version is already satisfied
if [[ "$cur" == "$want_torch" ]]; then if [[ "$cur" == "$want_torch" ]]; then
...@@ -135,8 +142,8 @@ ensure_cuda_torch() { ...@@ -135,8 +142,8 @@ ensure_cuda_torch() {
# clean install torch # clean install torch
echo "[INFO] Installing torch==${torch_ver} and torchvision==${tv_ver} (cu${cuda_ver}) from ${index}..." echo "[INFO] Installing torch==${torch_ver} and torchvision==${tv_ver} (cu${cuda_ver}) from ${index}..."
"$py" -m pip uninstall -y torch torchvision torchaudio >/dev/null 2>&1 || true ${pip_uninstall_command} torch torchvision torchaudio >/dev/null 2>&1 || true
"$py" -m pip install -U --index-url "${index}" "torch==${torch_ver}" "torchvision==${tv_ver}" ${pip_install_command} -U --index-url "${index}" "torch==${torch_ver}" "torchvision==${tv_ver}"
} }
# extract isaac sim path # extract isaac sim path
...@@ -568,7 +575,7 @@ while [[ $# -gt 0 ]]; do ...@@ -568,7 +575,7 @@ while [[ $# -gt 0 ]]; do
begin_arm_install_sandbox begin_arm_install_sandbox
# install pytorch (version based on arch) # install pytorch (version based on arch)
ensure_cuda_torch ${python_exe} ensure_cuda_torch
# 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
...@@ -598,7 +605,7 @@ while [[ $# -gt 0 ]]; do ...@@ -598,7 +605,7 @@ while [[ $# -gt 0 ]]; do
# in some rare cases, torch might not be installed properly by setup.py, add one more check here # in some rare cases, torch might not be installed properly by setup.py, add one more check here
# can prevent that from happening # can prevent that from happening
ensure_cuda_torch ${python_exe} ensure_cuda_torch
# restore LD_PRELOAD if we cleared it # restore LD_PRELOAD if we cleared it
end_arm_install_sandbox end_arm_install_sandbox
......
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