Spaces:
Runtime error
Runtime error
Commit
·
3a89468
1
Parent(s):
226e278
Replace install_croco function with a direct pip installation command for the curope model dependency in app.py, streamlining the installation process and removing the previous compilation logic.
Browse files
app.py
CHANGED
|
@@ -1,129 +1,13 @@
|
|
| 1 |
import subprocess
|
| 2 |
import sys
|
| 3 |
-
import spaces
|
| 4 |
-
import torch
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
"""
|
| 11 |
-
Compile curope CUDA extension using torch.utils.cpp_extension.load()
|
| 12 |
-
This approach works better with zerogpu than subprocess calls.
|
| 13 |
-
"""
|
| 14 |
-
try:
|
| 15 |
-
import os
|
| 16 |
-
import shutil
|
| 17 |
-
from torch.utils.cpp_extension import load
|
| 18 |
-
|
| 19 |
-
# Path to the curope source files
|
| 20 |
-
curope_path = "./extern/CUT3R/src/croco/models/curope"
|
| 21 |
-
|
| 22 |
-
# Check if source files exist
|
| 23 |
-
cpp_file = os.path.join(curope_path, "curope.cpp")
|
| 24 |
-
cu_file = os.path.join(curope_path, "kernels.cu")
|
| 25 |
-
|
| 26 |
-
if not os.path.exists(cpp_file) or not os.path.exists(cu_file):
|
| 27 |
-
print(f"Source files not found: {cpp_file}, {cu_file}")
|
| 28 |
-
return False
|
| 29 |
-
|
| 30 |
-
print(f"Found source files: {cpp_file}, {cu_file}")
|
| 31 |
-
|
| 32 |
-
# Define source files
|
| 33 |
-
sources = [cpp_file, cu_file]
|
| 34 |
-
|
| 35 |
-
# Get CUDA architectures - be more conservative
|
| 36 |
-
if torch.cuda.is_available():
|
| 37 |
-
try:
|
| 38 |
-
# Get the current GPU architecture
|
| 39 |
-
capability = torch.cuda.get_device_capability()
|
| 40 |
-
arch_code = f"compute_{capability[0]}{capability[1]}"
|
| 41 |
-
sm_code = f"sm_{capability[0]}{capability[1]}"
|
| 42 |
-
all_cuda_archs = ['-gencode', f'arch={arch_code},code={sm_code}']
|
| 43 |
-
print(f"Using CUDA architecture: {arch_code}")
|
| 44 |
-
except:
|
| 45 |
-
# Fallback to common architectures
|
| 46 |
-
all_cuda_archs = [
|
| 47 |
-
'-gencode', 'arch=compute_70,code=sm_70',
|
| 48 |
-
'-gencode', 'arch=compute_80,code=sm_80',
|
| 49 |
-
]
|
| 50 |
-
else:
|
| 51 |
-
print("CUDA not available!")
|
| 52 |
-
return False
|
| 53 |
-
|
| 54 |
-
# Create build directory in current working directory
|
| 55 |
-
build_dir = os.path.abspath("./curope_build_temp")
|
| 56 |
-
if os.path.exists(build_dir):
|
| 57 |
-
shutil.rmtree(build_dir)
|
| 58 |
-
os.makedirs(build_dir, exist_ok=True)
|
| 59 |
-
print(f"Using build directory: {build_dir}")
|
| 60 |
-
|
| 61 |
-
# Compile the extension
|
| 62 |
-
print("Starting CUDA compilation...")
|
| 63 |
-
curope = load(
|
| 64 |
-
name="curope",
|
| 65 |
-
sources=sources,
|
| 66 |
-
extra_cflags=["-O3"],
|
| 67 |
-
extra_cuda_cflags=["-O3", "--use_fast_math"] + all_cuda_archs,
|
| 68 |
-
verbose=True,
|
| 69 |
-
build_directory=build_dir,
|
| 70 |
-
with_cuda=True
|
| 71 |
-
)
|
| 72 |
-
|
| 73 |
-
print("Successfully compiled curope CUDA extension")
|
| 74 |
-
|
| 75 |
-
# Clean up build directory
|
| 76 |
-
try:
|
| 77 |
-
shutil.rmtree(build_dir)
|
| 78 |
-
except:
|
| 79 |
-
pass
|
| 80 |
-
|
| 81 |
-
return True
|
| 82 |
-
|
| 83 |
-
except Exception as e:
|
| 84 |
-
print(f"Method 1 failed: {e}")
|
| 85 |
-
print("Trying alternative compilation method...")
|
| 86 |
-
|
| 87 |
-
# Alternative method: use setup.py build_ext --inplace
|
| 88 |
-
try:
|
| 89 |
-
import subprocess
|
| 90 |
-
import sys
|
| 91 |
-
import os
|
| 92 |
-
|
| 93 |
-
# Change to curope directory
|
| 94 |
-
original_cwd = os.getcwd()
|
| 95 |
-
curope_path = "./extern/CUT3R/src/croco/models/curope"
|
| 96 |
-
os.chdir(curope_path)
|
| 97 |
-
|
| 98 |
-
# Set CUDA environment variables to ensure they're available
|
| 99 |
-
env = os.environ.copy()
|
| 100 |
-
if torch.cuda.is_available():
|
| 101 |
-
cuda_home = os.environ.get('CUDA_HOME') or os.environ.get('CUDA_PATH')
|
| 102 |
-
if cuda_home:
|
| 103 |
-
env['CUDA_HOME'] = cuda_home
|
| 104 |
-
env['CUDA_PATH'] = cuda_home
|
| 105 |
-
|
| 106 |
-
# Run setup.py build_ext --inplace within the GPU context
|
| 107 |
-
result = subprocess.run([
|
| 108 |
-
sys.executable, "setup.py", "build_ext", "--inplace"
|
| 109 |
-
], env=env, capture_output=True, text=True)
|
| 110 |
-
|
| 111 |
-
os.chdir(original_cwd)
|
| 112 |
-
|
| 113 |
-
if result.returncode == 0:
|
| 114 |
-
print("Successfully compiled curope using setup.py")
|
| 115 |
-
return True
|
| 116 |
-
else:
|
| 117 |
-
print(f"Setup.py compilation failed: {result.stderr}")
|
| 118 |
-
return False
|
| 119 |
-
|
| 120 |
-
except Exception as e2:
|
| 121 |
-
print(f"Alternative method also failed: {e2}")
|
| 122 |
-
import traceback
|
| 123 |
-
traceback.print_exc()
|
| 124 |
-
return False
|
| 125 |
|
| 126 |
-
|
|
|
|
| 127 |
|
| 128 |
from typing import List, Literal
|
| 129 |
# from pathlib import Path
|
|
|
|
| 1 |
import subprocess
|
| 2 |
import sys
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
subprocess.check_call([
|
| 5 |
+
sys.executable, "-m", "pip", "install", "-e",
|
| 6 |
+
"./extern/CUT3R/src/croco/models/curope"
|
| 7 |
+
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
import spaces
|
| 10 |
+
import torch
|
| 11 |
|
| 12 |
from typing import List, Literal
|
| 13 |
# from pathlib import Path
|