Spaces:
Paused
Paused
Upload 4 files
Browse files- post_install.py +57 -6
post_install.py
CHANGED
|
@@ -39,10 +39,30 @@ def install_torch_sparse():
|
|
| 39 |
"""Install torch-sparse with compatible PyTorch version"""
|
| 40 |
print("Installing torch-sparse...")
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# Check PyTorch installation
|
| 48 |
print("Checking PyTorch installation...")
|
|
@@ -60,6 +80,14 @@ def install_torch_scatter():
|
|
| 60 |
"""Install torch-scatter with compatible PyTorch version"""
|
| 61 |
print("Installing torch-scatter...")
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
# Install torch-scatter with the compatible PyTorch version
|
| 64 |
print("Installing torch-scatter with PyTorch 2.0.1...")
|
| 65 |
if run_command("pip install torch-scatter -f https://data.pyg.org/whl/torch-2.0.1+cu117.html"):
|
|
@@ -72,6 +100,14 @@ def install_nvdiffrast():
|
|
| 72 |
"""Install nvdiffrast"""
|
| 73 |
print("Installing nvdiffrast...")
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
# Create packages directory if it doesn't exist
|
| 76 |
packages_dir = Path("packages")
|
| 77 |
packages_dir.mkdir(exist_ok=True)
|
|
@@ -92,6 +128,14 @@ def install_pytorch3d():
|
|
| 92 |
"""Install PyTorch3D"""
|
| 93 |
print("Installing PyTorch3D...")
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
packages_dir = Path("packages")
|
| 96 |
|
| 97 |
# Clone PyTorch3D
|
|
@@ -128,16 +172,23 @@ def install_pytorch3d():
|
|
| 128 |
else:
|
| 129 |
print("Trying PyTorch3D installation with default CUDA...")
|
| 130 |
|
| 131 |
-
|
|
|
|
| 132 |
print(f"Successfully installed PyTorch3D with config {i+1}")
|
| 133 |
return True
|
| 134 |
|
| 135 |
# If all CUDA configs fail, try without FORCE_CUDA
|
| 136 |
print("Trying PyTorch3D installation without FORCE_CUDA...")
|
| 137 |
-
if run_command("pip install .", cwd=pytorch3d_dir):
|
| 138 |
print("Successfully installed PyTorch3D without CUDA forcing")
|
| 139 |
return True
|
| 140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
return False
|
| 142 |
|
| 143 |
def install_fashion_clip():
|
|
|
|
| 39 |
"""Install torch-sparse with compatible PyTorch version"""
|
| 40 |
print("Installing torch-sparse...")
|
| 41 |
|
| 42 |
+
# Check if torch-sparse is already installed
|
| 43 |
+
try:
|
| 44 |
+
import torch_sparse
|
| 45 |
+
print("torch-sparse already installed")
|
| 46 |
+
return True
|
| 47 |
+
except ImportError:
|
| 48 |
+
pass
|
| 49 |
+
|
| 50 |
+
# Check if PyTorch is already installed with the correct version
|
| 51 |
+
try:
|
| 52 |
+
import torch
|
| 53 |
+
if torch.__version__.startswith("2.0.1") and "+cu117" in torch.__version__:
|
| 54 |
+
print(f"PyTorch {torch.__version__} already installed with correct CUDA version")
|
| 55 |
+
else:
|
| 56 |
+
print(f"PyTorch {torch.__version__} installed, but need to update to 2.0.1+cu117")
|
| 57 |
+
# First, install a compatible PyTorch version with CUDA 11.7 (as expected by PyTorch3D)
|
| 58 |
+
print("Installing compatible PyTorch version...")
|
| 59 |
+
if not run_command("pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cu117"):
|
| 60 |
+
return False
|
| 61 |
+
except ImportError:
|
| 62 |
+
# First, install a compatible PyTorch version with CUDA 11.7 (as expected by PyTorch3D)
|
| 63 |
+
print("Installing compatible PyTorch version...")
|
| 64 |
+
if not run_command("pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cu117"):
|
| 65 |
+
return False
|
| 66 |
|
| 67 |
# Check PyTorch installation
|
| 68 |
print("Checking PyTorch installation...")
|
|
|
|
| 80 |
"""Install torch-scatter with compatible PyTorch version"""
|
| 81 |
print("Installing torch-scatter...")
|
| 82 |
|
| 83 |
+
# Check if torch-scatter is already installed
|
| 84 |
+
try:
|
| 85 |
+
import torch_scatter
|
| 86 |
+
print("torch-scatter already installed")
|
| 87 |
+
return True
|
| 88 |
+
except ImportError:
|
| 89 |
+
pass
|
| 90 |
+
|
| 91 |
# Install torch-scatter with the compatible PyTorch version
|
| 92 |
print("Installing torch-scatter with PyTorch 2.0.1...")
|
| 93 |
if run_command("pip install torch-scatter -f https://data.pyg.org/whl/torch-2.0.1+cu117.html"):
|
|
|
|
| 100 |
"""Install nvdiffrast"""
|
| 101 |
print("Installing nvdiffrast...")
|
| 102 |
|
| 103 |
+
# Check if nvdiffrast is already installed
|
| 104 |
+
try:
|
| 105 |
+
import nvdiffrast
|
| 106 |
+
print("nvdiffrast already installed")
|
| 107 |
+
return True
|
| 108 |
+
except ImportError:
|
| 109 |
+
pass
|
| 110 |
+
|
| 111 |
# Create packages directory if it doesn't exist
|
| 112 |
packages_dir = Path("packages")
|
| 113 |
packages_dir.mkdir(exist_ok=True)
|
|
|
|
| 128 |
"""Install PyTorch3D"""
|
| 129 |
print("Installing PyTorch3D...")
|
| 130 |
|
| 131 |
+
# Check if PyTorch3D is already installed
|
| 132 |
+
try:
|
| 133 |
+
import pytorch3d
|
| 134 |
+
print(f"PyTorch3D already installed: {pytorch3d.__version__}")
|
| 135 |
+
return True
|
| 136 |
+
except ImportError:
|
| 137 |
+
pass
|
| 138 |
+
|
| 139 |
packages_dir = Path("packages")
|
| 140 |
|
| 141 |
# Clone PyTorch3D
|
|
|
|
| 172 |
else:
|
| 173 |
print("Trying PyTorch3D installation with default CUDA...")
|
| 174 |
|
| 175 |
+
# Use --no-build-isolation to allow access to installed torch
|
| 176 |
+
if run_command("pip install . --no-build-isolation", cwd=pytorch3d_dir, env=env):
|
| 177 |
print(f"Successfully installed PyTorch3D with config {i+1}")
|
| 178 |
return True
|
| 179 |
|
| 180 |
# If all CUDA configs fail, try without FORCE_CUDA
|
| 181 |
print("Trying PyTorch3D installation without FORCE_CUDA...")
|
| 182 |
+
if run_command("pip install . --no-build-isolation", cwd=pytorch3d_dir):
|
| 183 |
print("Successfully installed PyTorch3D without CUDA forcing")
|
| 184 |
return True
|
| 185 |
|
| 186 |
+
# If source installation fails, try pre-built wheel
|
| 187 |
+
print("Trying PyTorch3D installation with pre-built wheel...")
|
| 188 |
+
if run_command("pip install pytorch3d --no-build-isolation"):
|
| 189 |
+
print("Successfully installed PyTorch3D from pre-built wheel")
|
| 190 |
+
return True
|
| 191 |
+
|
| 192 |
return False
|
| 193 |
|
| 194 |
def install_fashion_clip():
|