lemms commited on
Commit
e70ffa3
Β·
verified Β·
1 Parent(s): 87b9630

Add dependency test script to diagnose import issues

Browse files
Files changed (1) hide show
  1. test_dependencies.py +103 -0
test_dependencies.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Test script to verify all dependencies are properly installed for OpenLLM training.
4
+
5
+ This script checks if all required libraries are available and can be imported
6
+ without errors. It's useful for debugging dependency issues in Hugging Face Spaces.
7
+
8
+ Author: Louis Chua Bean Chong
9
+ License: GPL-3.0
10
+ """
11
+
12
+ import sys
13
+ import importlib
14
+
15
+ def test_import(module_name, package_name=None):
16
+ """
17
+ Test if a module can be imported successfully.
18
+
19
+ Args:
20
+ module_name: Name of the module to import
21
+ package_name: Optional package name for pip installation reference
22
+
23
+ Returns:
24
+ bool: True if import successful, False otherwise
25
+ """
26
+ try:
27
+ importlib.import_module(module_name)
28
+ print(f"βœ… {module_name} - Import successful")
29
+ return True
30
+ except ImportError as e:
31
+ print(f"❌ {module_name} - Import failed: {e}")
32
+ if package_name:
33
+ print(f" πŸ’‘ Try installing with: pip install {package_name}")
34
+ return False
35
+
36
+ def main():
37
+ """Test all required dependencies for OpenLLM training."""
38
+ print("πŸ” Testing OpenLLM Training Dependencies")
39
+ print("=" * 50)
40
+
41
+ # Core ML Framework
42
+ print("\nπŸ“Š Core Machine Learning Framework:")
43
+ test_import("torch", "torch")
44
+ test_import("torchvision", "torchvision")
45
+ test_import("torchaudio", "torchaudio")
46
+
47
+ # Hugging Face Ecosystem
48
+ print("\nπŸ€— Hugging Face Ecosystem:")
49
+ test_import("transformers", "transformers")
50
+ test_import("datasets", "datasets")
51
+ test_import("tokenizers", "tokenizers")
52
+ test_import("sentencepiece", "sentencepiece") # CRITICAL for OpenLLM
53
+ test_import("huggingface_hub", "huggingface_hub")
54
+ test_import("accelerate", "accelerate")
55
+
56
+ # UI Framework
57
+ print("\n🎨 User Interface Framework:")
58
+ test_import("gradio", "gradio")
59
+
60
+ # Data Processing
61
+ print("\nπŸ“ˆ Data Processing and Scientific Computing:")
62
+ test_import("numpy", "numpy")
63
+ test_import("pandas", "pandas")
64
+ test_import("scipy", "scipy")
65
+
66
+ # Progress and Monitoring
67
+ print("\nπŸ“Š Progress and Monitoring:")
68
+ test_import("tqdm", "tqdm")
69
+ test_import("psutil", "psutil")
70
+
71
+ # Memory and Performance Optimization
72
+ print("\n⚑ Memory and Performance Optimization:")
73
+ test_import("bitsandbytes", "bitsandbytes")
74
+ test_import("peft", "peft")
75
+
76
+ # Logging and Debugging
77
+ print("\nπŸ“ Logging and Debugging:")
78
+ test_import("wandb", "wandb")
79
+ test_import("tensorboard", "tensorboard")
80
+
81
+ # Additional Utilities
82
+ print("\nπŸ”§ Additional Utilities:")
83
+ test_import("requests", "requests")
84
+ test_import("PIL", "pillow")
85
+ test_import("matplotlib", "matplotlib")
86
+ test_import("seaborn", "seaborn")
87
+
88
+ # Development and Testing
89
+ print("\nπŸ§ͺ Development and Testing:")
90
+ test_import("pytest", "pytest")
91
+ test_import("black", "black")
92
+ test_import("flake8", "flake8")
93
+
94
+ print("\n" + "=" * 50)
95
+ print("🎯 Dependency Test Complete!")
96
+ print("\nπŸ’‘ If any dependencies failed to import:")
97
+ print(" 1. Check the error messages above")
98
+ print(" 2. Install missing packages with pip")
99
+ print(" 3. Restart the Hugging Face Space")
100
+ print(" 4. Run this test again to verify")
101
+
102
+ if __name__ == "__main__":
103
+ main()