abreza commited on
Commit
51981f2
·
1 Parent(s): 1e29c76

fix: add MultiScaleDeformableAttention CUDA extension and enhance CUDA toolkit setup

Browse files
.gitattributes CHANGED
@@ -95,3 +95,5 @@ pretrained_weights/insightface/models/buffalo_l/2d106det.onnx filter=lfs diff=lf
95
  pretrained_weights/insightface/models/buffalo_l/det_10g.onnx filter=lfs diff=lfs merge=lfs -text
96
  pretrained_weights/liveportrait/landmark.onnx filter=lfs diff=lfs merge=lfs -text
97
  pretrained_weights/liveportrait_animals/**/*.pth filter=lfs diff=lfs merge=lfs -text
 
 
 
95
  pretrained_weights/insightface/models/buffalo_l/det_10g.onnx filter=lfs diff=lfs merge=lfs -text
96
  pretrained_weights/liveportrait/landmark.onnx filter=lfs diff=lfs merge=lfs -text
97
  pretrained_weights/liveportrait_animals/**/*.pth filter=lfs diff=lfs merge=lfs -text
98
+
99
+ MultiScaleDeformableAttention.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
app.py CHANGED
@@ -12,6 +12,10 @@ from src.config.argument_config import ArgumentConfig
12
  from src.config.inference_config import InferenceConfig
13
  import spaces
14
 
 
 
 
 
15
  CUDA_RUN_URL = (
16
  "https://developer.download.nvidia.com/compute/cuda/11.8.0/"
17
  "local_installers/cuda_11.8.0_520.61.05_linux.run"
@@ -22,27 +26,34 @@ TORCH_WHL_INDEX = "https://download.pytorch.org/whl/torch_stable.html"
22
 
23
  def ensure_cuda_toolkit():
24
  """Download & install the CUDA toolkit *silently* if it is not present."""
 
25
  if pathlib.Path(f"{CUDA_HOME_PATH}/bin/nvcc").exists():
 
26
  return # toolkit already installed
27
 
 
28
  run_file = f"/tmp/{pathlib.Path(CUDA_RUN_URL).name}"
29
  subprocess.run(["wget", "-q", CUDA_RUN_URL, "-O", run_file], check=True)
 
30
  subprocess.run(["chmod", "+x", run_file], check=True)
 
31
  subprocess.run([run_file, "--silent", "--toolkit"], check=True)
 
32
 
33
  # --- environment variables expected by CUDA extensions -------------------
 
34
  os.environ["CUDA_HOME"] = CUDA_HOME_PATH
35
  os.environ["PATH"] = f"{CUDA_HOME_PATH}/bin:" + os.environ.get("PATH", "")
36
  os.environ["LD_LIBRARY_PATH"] = (
37
  f"{CUDA_HOME_PATH}/lib64:" + os.environ.get("LD_LIBRARY_PATH", "")
38
  )
39
  os.environ["TORCH_CUDA_ARCH_LIST"] = "8.0;8.6"
 
40
 
41
 
42
  def build_xpose_ops():
43
  """Build the MultiScaleDeformableAttention CUDA extension with enhanced error handling."""
44
  try:
45
- # Check if already built to avoid rebuilding
46
  import MultiScaleDeformableAttention
47
  print("MultiScaleDeformableAttention already installed")
48
  return True
@@ -53,21 +64,17 @@ def build_xpose_ops():
53
  current_dir, "src/utils/dependencies/XPose/models/UniPose/ops")
54
  try:
55
  os.chdir(ops_dir)
56
- # Set environment variables to help with compilation
57
  os.environ["TORCH_CUDA_ARCH_LIST"] = "8.0;8.6"
58
- os.environ["MAX_JOBS"] = "1" # Limit to avoid memory issues
59
 
60
  try:
61
- # Try building with fewer optimizations
62
  subprocess.run(
63
- [sys.executable, "setup.py", "build", "install", "--user"],
64
  check=True,
65
  env={**os.environ, "CFLAGS": "-O0", "CXXFLAGS": "-O0"}
66
  )
67
  print("MultiScaleDeformableAttention built successfully")
68
 
69
  try:
70
- # Verify it was properly built
71
  import MultiScaleDeformableAttention
72
  built_success = True
73
  except ImportError:
@@ -77,17 +84,14 @@ def build_xpose_ops():
77
  except subprocess.CalledProcessError as e:
78
  print(f"Build error: {e}")
79
 
80
- # If the standard build fails, try with minimal compilation
81
  try:
82
  print("Attempting simplified build...")
83
  subprocess.run(
84
- [sys.executable, "setup.py", "build", "install", "--user",
85
- "--global-option=--disable-cuda"],
86
  check=True
87
  )
88
  print("Simplified build completed")
89
 
90
- # Verify import works
91
  try:
92
  import MultiScaleDeformableAttention
93
  print("MultiScaleDeformableAttention imported after simplified build")
 
12
  from src.config.inference_config import InferenceConfig
13
  import spaces
14
 
15
+ ROOT = pathlib.Path(__file__).resolve().parent
16
+ OPS_DIR = ROOT / "src" / "utils" / "dependencies" / "XPose" / "models" / "UniPose" / "ops"
17
+ sys.path.insert(0, str(OPS_DIR))
18
+
19
  CUDA_RUN_URL = (
20
  "https://developer.download.nvidia.com/compute/cuda/11.8.0/"
21
  "local_installers/cuda_11.8.0_520.61.05_linux.run"
 
26
 
27
  def ensure_cuda_toolkit():
28
  """Download & install the CUDA toolkit *silently* if it is not present."""
29
+ print("Checking for CUDA toolkit...")
30
  if pathlib.Path(f"{CUDA_HOME_PATH}/bin/nvcc").exists():
31
+ print(f"CUDA toolkit already installed at {CUDA_HOME_PATH}")
32
  return # toolkit already installed
33
 
34
+ print(f"CUDA toolkit not found. Downloading from {CUDA_RUN_URL}...")
35
  run_file = f"/tmp/{pathlib.Path(CUDA_RUN_URL).name}"
36
  subprocess.run(["wget", "-q", CUDA_RUN_URL, "-O", run_file], check=True)
37
+ print(f"Download complete. Making installer executable...")
38
  subprocess.run(["chmod", "+x", run_file], check=True)
39
+ print("Installing CUDA toolkit (this may take a while)...")
40
  subprocess.run([run_file, "--silent", "--toolkit"], check=True)
41
+ print("CUDA toolkit installation complete.")
42
 
43
  # --- environment variables expected by CUDA extensions -------------------
44
+ print("Setting up CUDA environment variables...")
45
  os.environ["CUDA_HOME"] = CUDA_HOME_PATH
46
  os.environ["PATH"] = f"{CUDA_HOME_PATH}/bin:" + os.environ.get("PATH", "")
47
  os.environ["LD_LIBRARY_PATH"] = (
48
  f"{CUDA_HOME_PATH}/lib64:" + os.environ.get("LD_LIBRARY_PATH", "")
49
  )
50
  os.environ["TORCH_CUDA_ARCH_LIST"] = "8.0;8.6"
51
+ print("CUDA environment setup complete.")
52
 
53
 
54
  def build_xpose_ops():
55
  """Build the MultiScaleDeformableAttention CUDA extension with enhanced error handling."""
56
  try:
 
57
  import MultiScaleDeformableAttention
58
  print("MultiScaleDeformableAttention already installed")
59
  return True
 
64
  current_dir, "src/utils/dependencies/XPose/models/UniPose/ops")
65
  try:
66
  os.chdir(ops_dir)
 
67
  os.environ["TORCH_CUDA_ARCH_LIST"] = "8.0;8.6"
 
68
 
69
  try:
 
70
  subprocess.run(
71
+ [sys.executable, "setup.py", "build", "install"],
72
  check=True,
73
  env={**os.environ, "CFLAGS": "-O0", "CXXFLAGS": "-O0"}
74
  )
75
  print("MultiScaleDeformableAttention built successfully")
76
 
77
  try:
 
78
  import MultiScaleDeformableAttention
79
  built_success = True
80
  except ImportError:
 
84
  except subprocess.CalledProcessError as e:
85
  print(f"Build error: {e}")
86
 
 
87
  try:
88
  print("Attempting simplified build...")
89
  subprocess.run(
90
+ [sys.executable, "setup.py", "build", "install"],
 
91
  check=True
92
  )
93
  print("Simplified build completed")
94
 
 
95
  try:
96
  import MultiScaleDeformableAttention
97
  print("MultiScaleDeformableAttention imported after simplified build")
src/utils/dependencies/XPose/models/UniPose/ops/MultiScaleDeformableAttention.cpython-310-x86_64-linux-gnu.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2e522d249550dbec7577971415180c6685de6e5e864f89e780398ce8f32e71ad
3
+ size 9901144