Spaces:
Paused
Paused
Upload 3 files
Browse files- app.py +3 -17
- post_install.py +29 -97
- requirements.txt +4 -2
app.py
CHANGED
|
@@ -21,25 +21,11 @@ if os.path.exists(packages_dir):
|
|
| 21 |
def check_complex_dependencies():
|
| 22 |
"""Check if complex dependencies are available"""
|
| 23 |
try:
|
|
|
|
|
|
|
| 24 |
import nvdiffrast
|
| 25 |
import pytorch3d
|
| 26 |
-
|
| 27 |
-
try:
|
| 28 |
-
import torch_sparse
|
| 29 |
-
import torch_scatter
|
| 30 |
-
return True
|
| 31 |
-
except ImportError:
|
| 32 |
-
# If torch_sparse/scatter not available, check if the code is configured to work without them
|
| 33 |
-
try:
|
| 34 |
-
with open("NeuralJacobianFields/PoissonSystem.py", 'r') as f:
|
| 35 |
-
content = f.read()
|
| 36 |
-
if "USE_TORCH_SPARSE = False" in content:
|
| 37 |
-
print("torch-sparse not available but code is configured to work without it")
|
| 38 |
-
return True
|
| 39 |
-
else:
|
| 40 |
-
return False
|
| 41 |
-
except:
|
| 42 |
-
return False
|
| 43 |
except ImportError:
|
| 44 |
return False
|
| 45 |
|
|
|
|
| 21 |
def check_complex_dependencies():
|
| 22 |
"""Check if complex dependencies are available"""
|
| 23 |
try:
|
| 24 |
+
import torch_sparse
|
| 25 |
+
import torch_scatter
|
| 26 |
import nvdiffrast
|
| 27 |
import pytorch3d
|
| 28 |
+
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
except ImportError:
|
| 30 |
return False
|
| 31 |
|
post_install.py
CHANGED
|
@@ -22,80 +22,33 @@ def run_command(command, cwd=None):
|
|
| 22 |
return True
|
| 23 |
|
| 24 |
def install_torch_sparse():
|
| 25 |
-
"""Install torch-sparse with
|
| 26 |
print("Installing torch-sparse...")
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
torch_version = torch.__version__
|
| 32 |
-
print(f"Current PyTorch version: {torch_version}")
|
| 33 |
-
|
| 34 |
-
# Extract major.minor version
|
| 35 |
-
version_parts = torch_version.split('.')
|
| 36 |
-
torch_major_minor = f"{version_parts[0]}.{version_parts[1]}"
|
| 37 |
-
|
| 38 |
-
# Check CUDA version
|
| 39 |
-
cuda_version = "cu126" # Default for PyTorch 2.7.1
|
| 40 |
-
if "+cu" in torch_version:
|
| 41 |
-
cuda_version = torch_version.split("+")[1]
|
| 42 |
-
|
| 43 |
-
print(f"Detected CUDA version: {cuda_version}")
|
| 44 |
-
|
| 45 |
-
# Try different CUDA versions for torch-sparse
|
| 46 |
-
cuda_versions_to_try = [cuda_version, "cu121", "cu118", "cu117"]
|
| 47 |
-
|
| 48 |
-
for cuda_ver in cuda_versions_to_try:
|
| 49 |
-
print(f"Trying torch-sparse with CUDA {cuda_ver}...")
|
| 50 |
-
if run_command(f"pip install torch-sparse -f https://data.pyg.org/whl/torch-{torch_major_minor}+{cuda_ver}.html"):
|
| 51 |
-
print(f"Successfully installed torch-sparse with CUDA {cuda_ver}")
|
| 52 |
-
return True
|
| 53 |
-
|
| 54 |
-
# If all pre-built wheels fail, try from source
|
| 55 |
-
print("All pre-built wheels failed, trying from source...")
|
| 56 |
-
if run_command("pip install torch-sparse"):
|
| 57 |
-
return True
|
| 58 |
-
|
| 59 |
-
return False
|
| 60 |
-
except Exception as e:
|
| 61 |
-
print(f"Error installing torch-sparse: {e}")
|
| 62 |
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
def install_torch_scatter():
|
| 65 |
-
"""Install torch-scatter with
|
| 66 |
print("Installing torch-scatter...")
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
cuda_version = "cu126" # Default for PyTorch 2.7.1
|
| 76 |
-
if "+cu" in torch_version:
|
| 77 |
-
cuda_version = torch_version.split("+")[1]
|
| 78 |
-
|
| 79 |
-
print(f"Detected CUDA version: {cuda_version}")
|
| 80 |
-
|
| 81 |
-
# Try different CUDA versions for torch-scatter
|
| 82 |
-
cuda_versions_to_try = [cuda_version, "cu121", "cu118", "cu117"]
|
| 83 |
-
|
| 84 |
-
for cuda_ver in cuda_versions_to_try:
|
| 85 |
-
print(f"Trying torch-scatter with CUDA {cuda_ver}...")
|
| 86 |
-
if run_command(f"pip install torch-scatter -f https://data.pyg.org/whl/torch-{torch_major_minor}+{cuda_ver}.html"):
|
| 87 |
-
print(f"Successfully installed torch-scatter with CUDA {cuda_ver}")
|
| 88 |
-
return True
|
| 89 |
-
|
| 90 |
-
# If all pre-built wheels fail, try from source
|
| 91 |
-
print("All pre-built wheels failed, trying from source...")
|
| 92 |
-
if run_command("pip install torch-scatter"):
|
| 93 |
-
return True
|
| 94 |
-
|
| 95 |
-
return False
|
| 96 |
-
except Exception as e:
|
| 97 |
-
print(f"Error installing torch-scatter: {e}")
|
| 98 |
-
return False
|
| 99 |
|
| 100 |
def install_nvdiffrast():
|
| 101 |
"""Install nvdiffrast"""
|
|
@@ -131,7 +84,9 @@ def install_pytorch3d():
|
|
| 131 |
# Install PyTorch3D with CUDA support
|
| 132 |
pytorch3d_dir = packages_dir / "pytorch3d"
|
| 133 |
if not run_command("FORCE_CUDA=1 pip install .", cwd=pytorch3d_dir):
|
| 134 |
-
|
|
|
|
|
|
|
| 135 |
|
| 136 |
return True
|
| 137 |
|
|
@@ -161,15 +116,13 @@ def main():
|
|
| 161 |
print("Starting post-installation for Garment3DGen...")
|
| 162 |
|
| 163 |
# Install complex dependencies
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
# Disable torch-sparse in the code
|
| 168 |
-
disable_torch_sparse()
|
| 169 |
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
|
| 174 |
if not install_nvdiffrast():
|
| 175 |
print("Failed to install nvdiffrast")
|
|
@@ -184,28 +137,7 @@ def main():
|
|
| 184 |
sys.exit(1)
|
| 185 |
|
| 186 |
print("Post-installation completed successfully!")
|
| 187 |
-
if not torch_sparse_success:
|
| 188 |
-
print("Note: Using PyTorch's built-in sparse operations instead of torch-sparse")
|
| 189 |
print("All dependencies are now available.")
|
| 190 |
|
| 191 |
-
def disable_torch_sparse():
|
| 192 |
-
"""Disable torch-sparse in the code by modifying the configuration"""
|
| 193 |
-
try:
|
| 194 |
-
# Modify the PoissonSystem.py to disable torch-sparse
|
| 195 |
-
poisson_file = "NeuralJacobianFields/PoissonSystem.py"
|
| 196 |
-
if os.path.exists(poisson_file):
|
| 197 |
-
with open(poisson_file, 'r') as f:
|
| 198 |
-
content = f.read()
|
| 199 |
-
|
| 200 |
-
# Replace USE_TORCH_SPARSE = True with False
|
| 201 |
-
content = content.replace("USE_TORCH_SPARSE = True", "USE_TORCH_SPARSE = False")
|
| 202 |
-
|
| 203 |
-
with open(poisson_file, 'w') as f:
|
| 204 |
-
f.write(content)
|
| 205 |
-
|
| 206 |
-
print("Disabled torch-sparse in NeuralJacobianFields/PoissonSystem.py")
|
| 207 |
-
except Exception as e:
|
| 208 |
-
print(f"Warning: Could not disable torch-sparse: {e}")
|
| 209 |
-
|
| 210 |
if __name__ == "__main__":
|
| 211 |
main()
|
|
|
|
| 22 |
return True
|
| 23 |
|
| 24 |
def install_torch_sparse():
|
| 25 |
+
"""Install torch-sparse with compatible PyTorch version"""
|
| 26 |
print("Installing torch-sparse...")
|
| 27 |
|
| 28 |
+
# First, install a compatible PyTorch version
|
| 29 |
+
print("Installing compatible PyTorch version...")
|
| 30 |
+
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/cu118"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
return False
|
| 32 |
+
|
| 33 |
+
# Now install torch-sparse with the compatible version
|
| 34 |
+
print("Installing torch-sparse with PyTorch 2.0.1...")
|
| 35 |
+
if run_command("pip install torch-sparse -f https://data.pyg.org/whl/torch-2.0.1+cu118.html"):
|
| 36 |
+
print("Successfully installed torch-sparse")
|
| 37 |
+
return True
|
| 38 |
+
|
| 39 |
+
return False
|
| 40 |
|
| 41 |
def install_torch_scatter():
|
| 42 |
+
"""Install torch-scatter with compatible PyTorch version"""
|
| 43 |
print("Installing torch-scatter...")
|
| 44 |
|
| 45 |
+
# Install torch-scatter with the compatible PyTorch version
|
| 46 |
+
print("Installing torch-scatter with PyTorch 2.0.1...")
|
| 47 |
+
if run_command("pip install torch-scatter -f https://data.pyg.org/whl/torch-2.0.1+cu118.html"):
|
| 48 |
+
print("Successfully installed torch-scatter")
|
| 49 |
+
return True
|
| 50 |
+
|
| 51 |
+
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
def install_nvdiffrast():
|
| 54 |
"""Install nvdiffrast"""
|
|
|
|
| 84 |
# Install PyTorch3D with CUDA support
|
| 85 |
pytorch3d_dir = packages_dir / "pytorch3d"
|
| 86 |
if not run_command("FORCE_CUDA=1 pip install .", cwd=pytorch3d_dir):
|
| 87 |
+
# Try without FORCE_CUDA if it fails
|
| 88 |
+
if not run_command("pip install .", cwd=pytorch3d_dir):
|
| 89 |
+
return False
|
| 90 |
|
| 91 |
return True
|
| 92 |
|
|
|
|
| 116 |
print("Starting post-installation for Garment3DGen...")
|
| 117 |
|
| 118 |
# Install complex dependencies
|
| 119 |
+
if not install_torch_sparse():
|
| 120 |
+
print("Failed to install torch-sparse")
|
| 121 |
+
sys.exit(1)
|
|
|
|
|
|
|
| 122 |
|
| 123 |
+
if not install_torch_scatter():
|
| 124 |
+
print("Failed to install torch-scatter")
|
| 125 |
+
sys.exit(1)
|
| 126 |
|
| 127 |
if not install_nvdiffrast():
|
| 128 |
print("Failed to install nvdiffrast")
|
|
|
|
| 137 |
sys.exit(1)
|
| 138 |
|
| 139 |
print("Post-installation completed successfully!")
|
|
|
|
|
|
|
| 140 |
print("All dependencies are now available.")
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
if __name__ == "__main__":
|
| 143 |
main()
|
requirements.txt
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
-
# Core dependencies - compatible
|
| 2 |
-
|
|
|
|
|
|
|
| 3 |
clip
|
| 4 |
imageio
|
| 5 |
cython
|
|
|
|
| 1 |
+
# Core dependencies - using compatible PyTorch version for HF Spaces
|
| 2 |
+
torch==2.0.1
|
| 3 |
+
torchvision==0.15.2
|
| 4 |
+
torchaudio==2.0.2
|
| 5 |
clip
|
| 6 |
imageio
|
| 7 |
cython
|