Add manual dependency installation script to fix sentencepiece import issues
Browse files- install_dependencies.py +109 -0
install_dependencies.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Manual dependency installation script for Hugging Face Spaces.
|
| 4 |
+
|
| 5 |
+
This script installs missing dependencies that might not be properly
|
| 6 |
+
installed through requirements.txt. Run this in the Space terminal.
|
| 7 |
+
|
| 8 |
+
Author: Louis Chua Bean Chong
|
| 9 |
+
License: GPL-3.0
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import subprocess
|
| 13 |
+
import sys
|
| 14 |
+
import os
|
| 15 |
+
|
| 16 |
+
def run_command(command, description):
|
| 17 |
+
"""
|
| 18 |
+
Run a shell command and handle errors.
|
| 19 |
+
|
| 20 |
+
Args:
|
| 21 |
+
command: Command to run
|
| 22 |
+
description: Description of what the command does
|
| 23 |
+
"""
|
| 24 |
+
print(f"\nπ§ {description}")
|
| 25 |
+
print(f"Running: {command}")
|
| 26 |
+
|
| 27 |
+
try:
|
| 28 |
+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
| 29 |
+
if result.returncode == 0:
|
| 30 |
+
print(f"β
Success: {description}")
|
| 31 |
+
if result.stdout.strip():
|
| 32 |
+
print(f"Output: {result.stdout.strip()}")
|
| 33 |
+
else:
|
| 34 |
+
print(f"β Failed: {description}")
|
| 35 |
+
print(f"Error: {result.stderr.strip()}")
|
| 36 |
+
return False
|
| 37 |
+
except Exception as e:
|
| 38 |
+
print(f"β Exception: {e}")
|
| 39 |
+
return False
|
| 40 |
+
|
| 41 |
+
return True
|
| 42 |
+
|
| 43 |
+
def main():
|
| 44 |
+
"""Install all required dependencies manually."""
|
| 45 |
+
print("π Manual Dependency Installation for OpenLLM Training")
|
| 46 |
+
print("=" * 60)
|
| 47 |
+
|
| 48 |
+
# Check Python version
|
| 49 |
+
print(f"π Python version: {sys.version}")
|
| 50 |
+
print(f"π Working directory: {os.getcwd()}")
|
| 51 |
+
|
| 52 |
+
# Core dependencies that might be missing
|
| 53 |
+
dependencies = [
|
| 54 |
+
("sentencepiece>=0.1.99", "SentencePiece tokenization library (CRITICAL for OpenLLM)"),
|
| 55 |
+
("transformers>=4.30.0", "Hugging Face Transformers library"),
|
| 56 |
+
("datasets>=2.12.0", "Hugging Face Datasets library"),
|
| 57 |
+
("tokenizers>=0.13.0", "Fast tokenization library"),
|
| 58 |
+
("huggingface_hub>=0.34.0", "Hugging Face Hub integration"),
|
| 59 |
+
("accelerate>=0.20.0", "Distributed training acceleration"),
|
| 60 |
+
("torch>=2.0.0", "PyTorch deep learning framework"),
|
| 61 |
+
("gradio==4.44.1", "Gradio UI framework (fixed version)"),
|
| 62 |
+
("numpy>=1.24.0", "Numerical computing library"),
|
| 63 |
+
("pandas>=2.0.0", "Data manipulation library"),
|
| 64 |
+
("tqdm>=4.65.0", "Progress bars"),
|
| 65 |
+
("requests>=2.31.0", "HTTP library"),
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
print(f"\nπ¦ Installing {len(dependencies)} dependencies...")
|
| 69 |
+
|
| 70 |
+
success_count = 0
|
| 71 |
+
for package, description in dependencies:
|
| 72 |
+
command = f"pip install {package}"
|
| 73 |
+
if run_command(command, description):
|
| 74 |
+
success_count += 1
|
| 75 |
+
|
| 76 |
+
print(f"\n" + "=" * 60)
|
| 77 |
+
print(f"π― Installation Summary:")
|
| 78 |
+
print(f"β
Successful: {success_count}/{len(dependencies)}")
|
| 79 |
+
print(f"β Failed: {len(dependencies) - success_count}/{len(dependencies)}")
|
| 80 |
+
|
| 81 |
+
if success_count == len(dependencies):
|
| 82 |
+
print("\nπ All dependencies installed successfully!")
|
| 83 |
+
print("π‘ You can now try the training again.")
|
| 84 |
+
else:
|
| 85 |
+
print("\nβ οΈ Some dependencies failed to install.")
|
| 86 |
+
print("π‘ Check the error messages above and try again.")
|
| 87 |
+
|
| 88 |
+
# Test critical imports
|
| 89 |
+
print(f"\nπ§ͺ Testing critical imports...")
|
| 90 |
+
test_imports = [
|
| 91 |
+
("sentencepiece", "SentencePiece (CRITICAL)"),
|
| 92 |
+
("transformers", "Transformers"),
|
| 93 |
+
("datasets", "Datasets"),
|
| 94 |
+
("torch", "PyTorch"),
|
| 95 |
+
("gradio", "Gradio"),
|
| 96 |
+
]
|
| 97 |
+
|
| 98 |
+
for module, name in test_imports:
|
| 99 |
+
try:
|
| 100 |
+
__import__(module)
|
| 101 |
+
print(f"β
{name} - Import successful")
|
| 102 |
+
except ImportError as e:
|
| 103 |
+
print(f"β {name} - Import failed: {e}")
|
| 104 |
+
|
| 105 |
+
print(f"\nπ§ Manual installation complete!")
|
| 106 |
+
print("π‘ If imports still fail, try restarting the Space.")
|
| 107 |
+
|
| 108 |
+
if __name__ == "__main__":
|
| 109 |
+
main()
|