Skip to content

Commit

Permalink
feat: add with_torch option (#11)
Browse files Browse the repository at this point in the history
fix #9

Signed-off-by: Eloy Coto <[email protected]>
  • Loading branch information
eloycoto authored Apr 22, 2024
1 parent 62cd1f1 commit 2c7f9a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ Usage: fix-python --venv .venv [--libs libs.nix] [--no-default-libs]
--libs: path to a Nix file which returns a list of derivations
--no-default-libs: don't patch C++ standard libraries, glibc, and zlib by default
--gpu: enable GPU support
--with-torch: fix pytorch dependencies issues
--verbose: increase verbosity
```
17 changes: 16 additions & 1 deletion fix-python
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if [ "$1" = "--help" ]; then
echo "--libs: path to a Nix file which returns a list of derivations"
echo "--no-default-libs: don't patch C++ standard libraries, glibc, and zlib by default"
echo "--gpu: enable GPU support"
echo "--with-torch: fix pytorch dependencies issues"
echo "--verbose: increase verbosity"
exit 0
fi
Expand All @@ -46,6 +47,9 @@ while [ $# -gt 0 ]; do
--gpu)
enable_gpu="1"
;;
--with-torch)
enable_torch="1"
;;
--verbose)
verbose="1"
;;
Expand Down Expand Up @@ -141,7 +145,18 @@ cat <<< "$binary_files" \
interpreter_name="$(basename "$old_interpreter")"
new_interpreter="$(echo "$new_rpath" | tr ':' '\n' | xargs -I {} find {} -name "$interpreter_name" | head -1)"
patchelf --set-interpreter "$new_interpreter" "$file" || true
fi
fi
echo
done

# `libtorch_global_deps.so` depends on libstdc++ but does not properly declare it, fix it manually see
# https://github.com/eth-sri/lmql/blob/main/scripts/flake.d/overrides.nix#L28-L40
if [ "$enable_torch" ]; then
torch_files=$(find "$(realpath "$VENV_PATH")" -name libtorch_global_deps.so)
cat <<< "$torch_files" \
| while read -r file
do
echo "Patching torch file: $file"
patchelf $file --add-needed libstdc++.so
done
fi

0 comments on commit 2c7f9a8

Please sign in to comment.