Stylique commited on
Commit
12a663d
Β·
verified Β·
1 Parent(s): da53ed4

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +8 -1
  2. post_install.py +90 -13
  3. requirements.txt +1 -4
  4. test_installation.py +107 -0
app.py CHANGED
@@ -35,7 +35,14 @@ if not check_complex_dependencies():
35
  try:
36
  import subprocess
37
  subprocess.run([sys.executable, "post_install.py"], check=True)
38
- print("Post-install completed, restarting...")
 
 
 
 
 
 
 
39
  # Restart the process to pick up new dependencies
40
  os.execv(sys.executable, ['python'] + sys.argv)
41
  except Exception as e:
 
35
  try:
36
  import subprocess
37
  subprocess.run([sys.executable, "post_install.py"], check=True)
38
+ print("Post-install completed successfully!")
39
+
40
+ # Run test to verify installation
41
+ print("Running installation test...")
42
+ subprocess.run([sys.executable, "test_installation.py"], check=True)
43
+ print("Installation test passed!")
44
+
45
+ print("Restarting to pick up new dependencies...")
46
  # Restart the process to pick up new dependencies
47
  os.execv(sys.executable, ['python'] + sys.argv)
48
  except Exception as e:
post_install.py CHANGED
@@ -10,10 +10,10 @@ import subprocess
10
  import shutil
11
  from pathlib import Path
12
 
13
- def run_command(command, cwd=None):
14
  """Run a shell command and return the result"""
15
  print(f"Running: {command}")
16
- result = subprocess.run(command, shell=True, cwd=cwd, capture_output=True, text=True)
17
  if result.returncode != 0:
18
  print(f"Error running command: {command}")
19
  print(f"Error output: {result.stderr}")
@@ -21,18 +21,36 @@ def run_command(command, cwd=None):
21
  print(f"Success: {command}")
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
 
@@ -44,7 +62,7 @@ def install_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
 
@@ -83,12 +101,44 @@ def install_pytorch3d():
83
 
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
 
93
  def install_fashion_clip():
94
  """Setup Fashion-CLIP"""
@@ -136,8 +186,35 @@ def main():
136
  print("Failed to install Fashion-CLIP")
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()
 
10
  import shutil
11
  from pathlib import Path
12
 
13
+ def run_command(command, cwd=None, env=None):
14
  """Run a shell command and return the result"""
15
  print(f"Running: {command}")
16
+ result = subprocess.run(command, shell=True, cwd=cwd, capture_output=True, text=True, env=env)
17
  if result.returncode != 0:
18
  print(f"Error running command: {command}")
19
  print(f"Error output: {result.stderr}")
 
21
  print(f"Success: {command}")
22
  return True
23
 
24
+ def check_pytorch_cuda():
25
+ """Check if PyTorch is installed with correct CUDA version"""
26
+ try:
27
+ import torch
28
+ print(f"PyTorch version: {torch.__version__}")
29
+ print(f"CUDA available: {torch.cuda.is_available()}")
30
+ if torch.cuda.is_available():
31
+ print(f"CUDA version: {torch.version.cuda}")
32
+ print(f"cuDNN version: {torch.backends.cudnn.version()}")
33
+ return True
34
+ except Exception as e:
35
+ print(f"Error checking PyTorch: {e}")
36
+ return False
37
+
38
  def install_torch_sparse():
39
  """Install torch-sparse with compatible PyTorch version"""
40
  print("Installing torch-sparse...")
41
 
42
+ # First, install a compatible PyTorch version with CUDA 11.7 (as expected by PyTorch3D)
43
  print("Installing compatible PyTorch version...")
44
+ 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"):
45
  return False
46
 
47
+ # Check PyTorch installation
48
+ print("Checking PyTorch installation...")
49
+ check_pytorch_cuda()
50
+
51
  # Now install torch-sparse with the compatible version
52
  print("Installing torch-sparse with PyTorch 2.0.1...")
53
+ if run_command("pip install torch-sparse -f https://data.pyg.org/whl/torch-2.0.1+cu117.html"):
54
  print("Successfully installed torch-sparse")
55
  return True
56
 
 
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"):
66
  print("Successfully installed torch-scatter")
67
  return True
68
 
 
101
 
102
  # Install PyTorch3D with CUDA support
103
  pytorch3d_dir = packages_dir / "pytorch3d"
 
 
 
 
104
 
105
+ # Check what CUDA version is available
106
+ print("Checking available CUDA version...")
107
+ cuda_check = subprocess.run("nvcc --version", shell=True, capture_output=True, text=True)
108
+ if cuda_check.returncode == 0:
109
+ print(f"CUDA version info: {cuda_check.stdout}")
110
+
111
+ # Try different CUDA configurations
112
+ cuda_configs = [
113
+ # Try with CUDA 11.7 first (as expected by PyTorch)
114
+ {'CUDA_HOME': '/usr/local/cuda-11.7', 'CUDA_VERSION': '11.7'},
115
+ # Try with system CUDA
116
+ {'CUDA_HOME': '/usr/local/cuda', 'CUDA_VERSION': '12.3'},
117
+ # Try without specifying CUDA_HOME
118
+ {}
119
+ ]
120
+
121
+ for i, config in enumerate(cuda_configs):
122
+ env = os.environ.copy()
123
+ env['FORCE_CUDA'] = '1'
124
+ if config:
125
+ env['CUDA_HOME'] = config['CUDA_HOME']
126
+ env['CUDA_VERSION'] = config['CUDA_VERSION']
127
+ print(f"Trying PyTorch3D installation with {config}...")
128
+ else:
129
+ print("Trying PyTorch3D installation with default CUDA...")
130
+
131
+ if run_command("pip install .", cwd=pytorch3d_dir, env=env):
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():
144
  """Setup Fashion-CLIP"""
 
186
  print("Failed to install Fashion-CLIP")
187
  sys.exit(1)
188
 
189
+ # Final verification
190
+ print("\n=== Final Verification ===")
191
+ print("Checking all dependencies...")
192
+
193
+ try:
194
+ import torch
195
+ print(f"βœ“ PyTorch {torch.__version__} - CUDA: {torch.cuda.is_available()}")
196
+
197
+ import torch_sparse
198
+ print("βœ“ torch-sparse")
199
+
200
+ import torch_scatter
201
+ print("βœ“ torch-scatter")
202
+
203
+ import nvdiffrast
204
+ print("βœ“ nvdiffrast")
205
+
206
+ import pytorch3d
207
+ print("βœ“ PyTorch3D")
208
+
209
+ print("\nPost-installation completed successfully!")
210
+ print("All dependencies are now available.")
211
+
212
+ except ImportError as e:
213
+ print(f"βœ— Import error: {e}")
214
+ sys.exit(1)
215
+ except Exception as e:
216
+ print(f"βœ— Verification error: {e}")
217
+ sys.exit(1)
218
 
219
  if __name__ == "__main__":
220
  main()
requirements.txt CHANGED
@@ -1,7 +1,4 @@
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
 
1
+ # Core dependencies - PyTorch will be installed by post_install.py with correct CUDA version
 
 
 
2
  clip
3
  imageio
4
  cython
test_installation.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Test script to verify all dependencies are working correctly
4
+ """
5
+
6
+ import sys
7
+ import traceback
8
+
9
+ def test_imports():
10
+ """Test importing all required dependencies"""
11
+ print("Testing imports...")
12
+
13
+ try:
14
+ import torch
15
+ print(f"βœ“ PyTorch {torch.__version__}")
16
+ print(f" CUDA available: {torch.cuda.is_available()}")
17
+ if torch.cuda.is_available():
18
+ print(f" CUDA version: {torch.version.cuda}")
19
+ print(f" GPU count: {torch.cuda.device_count()}")
20
+ except Exception as e:
21
+ print(f"βœ— PyTorch import failed: {e}")
22
+ return False
23
+
24
+ try:
25
+ import torch_sparse
26
+ print("βœ“ torch-sparse")
27
+ except Exception as e:
28
+ print(f"βœ— torch-sparse import failed: {e}")
29
+ return False
30
+
31
+ try:
32
+ import torch_scatter
33
+ print("βœ“ torch-scatter")
34
+ except Exception as e:
35
+ print(f"βœ— torch-scatter import failed: {e}")
36
+ return False
37
+
38
+ try:
39
+ import nvdiffrast
40
+ print("βœ“ nvdiffrast")
41
+ except Exception as e:
42
+ print(f"βœ— nvdiffrast import failed: {e}")
43
+ return False
44
+
45
+ try:
46
+ import pytorch3d
47
+ print("βœ“ PyTorch3D")
48
+ except Exception as e:
49
+ print(f"βœ— PyTorch3D import failed: {e}")
50
+ return False
51
+
52
+ try:
53
+ import clip
54
+ print("βœ“ CLIP")
55
+ except Exception as e:
56
+ print(f"βœ— CLIP import failed: {e}")
57
+ return False
58
+
59
+ return True
60
+
61
+ def test_basic_functionality():
62
+ """Test basic functionality of key components"""
63
+ print("\nTesting basic functionality...")
64
+
65
+ try:
66
+ import torch
67
+ import torch_sparse
68
+ import torch_scatter
69
+
70
+ # Test basic tensor operations
71
+ x = torch.randn(10, 10)
72
+ y = torch.randn(10, 10)
73
+ z = x + y
74
+ print("βœ“ Basic tensor operations")
75
+
76
+ # Test sparse operations
77
+ indices = torch.randint(0, 10, (2, 20))
78
+ values = torch.randn(20)
79
+ sparse_tensor = torch.sparse_coo_tensor(indices, values, (10, 10))
80
+ print("βœ“ Sparse tensor creation")
81
+
82
+ except Exception as e:
83
+ print(f"βœ— Basic functionality test failed: {e}")
84
+ traceback.print_exc()
85
+ return False
86
+
87
+ return True
88
+
89
+ def main():
90
+ """Main test function"""
91
+ print("=== Garment3DGen Dependency Test ===\n")
92
+
93
+ # Test imports
94
+ if not test_imports():
95
+ print("\n❌ Import tests failed!")
96
+ sys.exit(1)
97
+
98
+ # Test basic functionality
99
+ if not test_basic_functionality():
100
+ print("\n❌ Functionality tests failed!")
101
+ sys.exit(1)
102
+
103
+ print("\nβœ… All tests passed! Dependencies are working correctly.")
104
+ print("The Garment3DGen application should be ready to run.")
105
+
106
+ if __name__ == "__main__":
107
+ main()