File size: 7,664 Bytes
8ff8722 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | #!/usr/bin/env python3
"""
Verification script to check if the project is ready for Zero GPU deployment
"""
import os
import sys
import re
def check_file_exists(filepath, required=True):
"""Check if a file exists"""
exists = os.path.exists(filepath)
status = "β
" if exists else ("β" if required else "β οΈ")
print(f"{status} {filepath}: {'Found' if exists else 'Missing'}")
return exists
def check_pytorch_version():
"""Check PyTorch version in requirements.txt"""
print("\nπ¦ Checking PyTorch version...")
with open("requirements.txt", "r") as f:
content = f.read()
# Look for torch version
torch_match = re.search(r"torch==(\d+\.\d+\.\d+)", content)
if torch_match:
version = torch_match.group(1)
if version == "2.2.0":
print(f"β
PyTorch version {version} is compatible with Zero GPU")
return True
else:
print(f"β PyTorch version {version} may not be compatible with Zero GPU")
print(" Recommended: torch==2.2.0")
return False
else:
print("β PyTorch version not found in requirements.txt")
return False
def check_spaces_not_in_requirements():
"""Check that spaces is NOT in requirements.txt"""
print("\nπ¦ Checking spaces library...")
with open("requirements.txt", "r") as f:
content = f.read()
if "spaces" in content:
print("β 'spaces' found in requirements.txt - should be removed!")
print(" HF Spaces provides this automatically")
return False
else:
print("β
'spaces' correctly not in requirements.txt")
return True
def check_gpu_decorators():
"""Check for @spaces.GPU decorators"""
print("\nπ― Checking GPU decorators...")
files_to_check = ["mvp.py"]
decorator_pattern = r"@spaces\.GPU"
for filepath in files_to_check:
if not os.path.exists(filepath):
print(f"β οΈ {filepath} not found")
continue
with open(filepath, "r") as f:
content = f.read()
decorators = re.findall(decorator_pattern, content)
if decorators:
print(f"β
{filepath}: Found {len(decorators)} @spaces.GPU decorators")
# Check specific functions
functions = ["run_model", "reconstruct", "detect_objects"]
for func in functions:
# Check if function has decorator
pattern = rf"@spaces\.GPU.*?\ndef {func}\("
if re.search(pattern, content, re.DOTALL):
print(f" β
{func}() has GPU decorator")
else:
print(f" β οΈ {func}() might be missing GPU decorator")
else:
print(f"β {filepath}: No GPU decorators found")
return False
return True
def check_model_manager():
"""Check for ModelManager implementation"""
print("\nπ§ Checking ModelManager...")
with open("mvp.py", "r") as f:
content = f.read()
if "class ModelManager" in content:
print("β
ModelManager class found")
# Check for key methods
methods = ["get_vggt_model", "get_metric3d_model", "get_clip_model", "clear_cache"]
for method in methods:
if f"def {method}" in content:
print(f" β
{method}() method found")
else:
print(f" β {method}() method missing")
# Check for global instance
if "model_manager = ModelManager()" in content:
print(" β
Global model_manager instance created")
else:
print(" β οΈ Global model_manager instance not found")
return True
else:
print("β ModelManager class not found")
return False
def check_environment_variables():
"""Check for Zero GPU environment variable handling"""
print("\nπ Checking environment variable handling...")
files = ["app.py", "mvp.py"]
for filepath in files:
with open(filepath, "r") as f:
content = f.read()
checks = {
"IS_HF_SPACE": "HF Space detection",
"IS_ZERO_GPU": "Zero GPU mode detection",
"MAX_IMAGES": "Image limit configuration",
"BATCH_SIZE": "Batch size configuration",
}
print(f"\n {filepath}:")
for var, description in checks.items():
if var in content:
print(f" β
{var}: {description}")
else:
print(f" β οΈ {var}: {description} not found")
def check_readme_header():
"""Check README header for HF Spaces"""
print("\nπ Checking README configuration...")
if os.path.exists("README_HF.md"):
with open("README_HF.md", "r") as f:
content = f.read()
if content.startswith("---"):
# Extract YAML header
header_end = content.find("---", 3)
if header_end > 0:
header = content[3:header_end]
required_fields = {
"title:": "Title field",
"emoji:": "Emoji field",
"sdk: gradio": "Gradio SDK",
"app_file: app.py": "App file specification",
}
print("β
README_HF.md has YAML header")
for field, description in required_fields.items():
if field in header:
print(f" β
{description}")
else:
print(f" β {description} missing")
else:
print("β README_HF.md YAML header not properly closed")
else:
print("β README_HF.md missing YAML header")
else:
print("β README_HF.md not found")
def main():
"""Run all verification checks"""
print("=" * 60)
print("π Zoo3D Zero GPU Deployment Verification")
print("=" * 60)
# Check critical files
print("\nπ Checking required files...")
check_file_exists("app.py")
check_file_exists("mvp.py")
check_file_exists("requirements.txt")
check_file_exists("packages.txt")
check_file_exists("README_HF.md")
check_file_exists("ZERO_GPU_README.md", required=False)
check_file_exists("test_zero_gpu.py", required=False)
# Check configurations
pytorch_ok = check_pytorch_version()
spaces_ok = check_spaces_not_in_requirements()
decorators_ok = check_gpu_decorators()
model_manager_ok = check_model_manager()
check_environment_variables()
check_readme_header()
# Summary
print("\n" + "=" * 60)
print("π Summary")
print("=" * 60)
critical_checks = [pytorch_ok, spaces_ok, decorators_ok, model_manager_ok]
if all(critical_checks):
print("β
Project is ready for Zero GPU deployment!")
print("\nNext steps:")
print("1. Copy README_HF.md to README.md when deploying")
print("2. Push to Hugging Face Spaces with Zero GPU hardware")
print("3. Monitor logs for any runtime issues")
return 0
else:
print("β Some issues need to be fixed before deployment")
print("\nCritical issues to resolve:")
if not pytorch_ok:
print("- Update PyTorch to version 2.2.0")
if not spaces_ok:
print("- Remove 'spaces' from requirements.txt")
if not decorators_ok:
print("- Add @spaces.GPU decorators to GPU functions")
if not model_manager_ok:
print("- Implement ModelManager for lazy loading")
return 1
if __name__ == "__main__":
sys.exit(main()) |