Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- README.md +16 -10
- install_requirements.py +13 -27
- requirements.txt +17 -1
- update_space.py +43 -46
README.md
CHANGED
@@ -20,21 +20,27 @@ This Hugging Face Space automatically installs dependencies from requirements.tx
|
|
20 |
|
21 |
### Installation Process
|
22 |
|
23 |
-
|
24 |
|
25 |
-
1. **
|
26 |
-
-
|
27 |
-
- Install with: `pip install -r requirements-base.txt`
|
28 |
-
|
29 |
-
2. **Standard Dependencies (requirements.txt)**:
|
30 |
-
- References base requirements and adds additional packages
|
31 |
- Install with: `pip install -r requirements.txt`
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
|
34 |
- For faster attention computation
|
35 |
-
- Install with: `pip install -
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
|
38 |
|
39 |
### Essential Dependencies
|
40 |
|
|
|
20 |
|
21 |
### Installation Process
|
22 |
|
23 |
+
The project uses a single consolidated requirements file that maintains the proper installation order of dependencies:
|
24 |
|
25 |
+
1. **All Dependencies (requirements.txt)**:
|
26 |
+
- Contains all required packages in the correct installation order
|
|
|
|
|
|
|
|
|
27 |
- Install with: `pip install -r requirements.txt`
|
28 |
+
- The file is organized with clear sections:
|
29 |
+
- Base dependencies (installed first)
|
30 |
+
- Main dependencies
|
31 |
+
- Optional dependencies (commented out by default)
|
32 |
|
33 |
+
2. **Flash Attention** (Optional):
|
34 |
- For faster attention computation
|
35 |
+
- Install with: `pip install flash-attn==2.5.2 --no-build-isolation`
|
36 |
+
- Or uncomment the flash-attn line in requirements.txt
|
37 |
+
|
38 |
+
3. **Automated Installation**:
|
39 |
+
- For convenience, you can use the included script:
|
40 |
+
- Basic install: `python install_requirements.py`
|
41 |
+
- With flash-attn: `python install_requirements.py --flash`
|
42 |
|
43 |
+
This approach simplifies dependency management while still maintaining proper installation order.
|
44 |
|
45 |
### Essential Dependencies
|
46 |
|
install_requirements.py
CHANGED
@@ -22,43 +22,29 @@ logging.basicConfig(
|
|
22 |
logger = logging.getLogger(__name__)
|
23 |
|
24 |
def install_requirements(include_flash=False):
|
25 |
-
"""Install requirements
|
26 |
current_dir = Path(__file__).parent
|
27 |
-
|
28 |
-
main_req_path = current_dir / "requirements.txt"
|
29 |
-
flash_req_path = current_dir / "requirements-flash.txt"
|
30 |
|
31 |
-
if not
|
32 |
-
logger.error(f"
|
33 |
return False
|
34 |
|
35 |
-
|
36 |
-
logger.error(f"Main requirements file not found: {main_req_path}")
|
37 |
-
return False
|
38 |
-
|
39 |
-
logger.info("Installing dependencies in sequential order...")
|
40 |
|
41 |
try:
|
42 |
-
#
|
43 |
-
logger.info(f"
|
44 |
-
subprocess.run([sys.executable, "-m", "pip", "install", "-r", str(
|
45 |
-
check=True)
|
46 |
-
logger.info("Base requirements installed successfully")
|
47 |
-
|
48 |
-
# Step 2: Install main requirements
|
49 |
-
logger.info(f"Step 2: Installing additional requirements from {main_req_path}")
|
50 |
-
subprocess.run([sys.executable, "-m", "pip", "install", "-r", str(main_req_path)],
|
51 |
check=True)
|
52 |
-
logger.info("
|
53 |
|
54 |
-
#
|
55 |
-
if include_flash
|
56 |
-
logger.info(
|
57 |
-
subprocess.run([sys.executable, "-m", "pip", "install", "-
|
58 |
check=True)
|
59 |
logger.info("Flash-attention installed successfully")
|
60 |
-
elif include_flash:
|
61 |
-
logger.warning(f"Flash requirements file not found: {flash_req_path}")
|
62 |
|
63 |
logger.info("All required packages installed successfully!")
|
64 |
return True
|
|
|
22 |
logger = logging.getLogger(__name__)
|
23 |
|
24 |
def install_requirements(include_flash=False):
|
25 |
+
"""Install requirements from the consolidated requirements file."""
|
26 |
current_dir = Path(__file__).parent
|
27 |
+
req_path = current_dir / "requirements.txt"
|
|
|
|
|
28 |
|
29 |
+
if not req_path.exists():
|
30 |
+
logger.error(f"Requirements file not found: {req_path}")
|
31 |
return False
|
32 |
|
33 |
+
logger.info("Installing dependencies from consolidated requirements file...")
|
|
|
|
|
|
|
|
|
34 |
|
35 |
try:
|
36 |
+
# Install all requirements
|
37 |
+
logger.info(f"Installing requirements from {req_path}")
|
38 |
+
subprocess.run([sys.executable, "-m", "pip", "install", "-r", str(req_path)],
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
check=True)
|
40 |
+
logger.info("Main requirements installed successfully")
|
41 |
|
42 |
+
# Optionally install flash-attention
|
43 |
+
if include_flash:
|
44 |
+
logger.info("Installing flash-attention...")
|
45 |
+
subprocess.run([sys.executable, "-m", "pip", "install", "flash-attn==2.5.2", "--no-build-isolation"],
|
46 |
check=True)
|
47 |
logger.info("Flash-attention installed successfully")
|
|
|
|
|
48 |
|
49 |
logger.info("All required packages installed successfully!")
|
50 |
return True
|
requirements.txt
CHANGED
@@ -1,6 +1,18 @@
|
|
1 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
einops>=0.7.0
|
3 |
filelock>=3.13.1
|
|
|
4 |
matplotlib>=3.7.0
|
5 |
numpy>=1.24.0
|
6 |
packaging>=23.0
|
@@ -15,3 +27,7 @@ sentencepiece>=0.1.99
|
|
15 |
tqdm>=4.65.0
|
16 |
typing-extensions>=4.8.0
|
17 |
unsloth>=2024.3
|
|
|
|
|
|
|
|
|
|
1 |
+
# BASE REQUIREMENTS - Install these critical dependencies first
|
2 |
+
# ---------------------------------------------------------------------
|
3 |
+
torch>=2.0.0
|
4 |
+
accelerate>=0.27.0
|
5 |
+
bitsandbytes>=0.41.0
|
6 |
+
transformers>=4.36.0
|
7 |
+
datasets>=2.15.0
|
8 |
+
huggingface-hub>=0.19.0
|
9 |
+
tensorboard>=2.15.0
|
10 |
+
|
11 |
+
# MAIN REQUIREMENTS - Install these after base dependencies
|
12 |
+
# ---------------------------------------------------------------------
|
13 |
einops>=0.7.0
|
14 |
filelock>=3.13.1
|
15 |
+
gradio>=5.17.0
|
16 |
matplotlib>=3.7.0
|
17 |
numpy>=1.24.0
|
18 |
packaging>=23.0
|
|
|
27 |
tqdm>=4.65.0
|
28 |
typing-extensions>=4.8.0
|
29 |
unsloth>=2024.3
|
30 |
+
|
31 |
+
# OPTIONAL DEPENDENCIES - Install these last (if needed)
|
32 |
+
# ---------------------------------------------------------------------
|
33 |
+
# flash-attn==2.5.2
|
update_space.py
CHANGED
@@ -99,29 +99,26 @@ def verify_configs():
|
|
99 |
raise ValueError(f"Invalid JSON in {json_file}: {e}")
|
100 |
|
101 |
def update_requirements():
|
102 |
-
"""Update requirements.txt with necessary packages
|
103 |
-
logger.info("Setting up requirements
|
104 |
current_dir = Path(__file__).parent
|
105 |
-
|
106 |
-
main_req_path = current_dir / "requirements.txt"
|
107 |
-
flash_req_path = current_dir / "requirements-flash.txt"
|
108 |
|
109 |
-
#
|
110 |
-
|
|
|
111 |
"torch>=2.0.0",
|
112 |
-
"transformers>=4.36.0",
|
113 |
"accelerate>=0.27.0",
|
114 |
-
"bitsandbytes>=0.41.0",
|
115 |
-
"
|
116 |
-
"
|
117 |
"huggingface-hub>=0.19.0",
|
118 |
-
"
|
119 |
-
|
120 |
-
|
121 |
-
# Additional packages for main requirements
|
122 |
-
required_additional_packages = {
|
123 |
"einops>=0.7.0",
|
124 |
"filelock>=3.13.1",
|
|
|
125 |
"matplotlib>=3.7.0",
|
126 |
"numpy>=1.24.0",
|
127 |
"packaging>=23.0",
|
@@ -136,43 +133,43 @@ def update_requirements():
|
|
136 |
"tqdm>=4.65.0",
|
137 |
"typing-extensions>=4.8.0",
|
138 |
"unsloth>=2024.3"
|
139 |
-
|
140 |
-
|
141 |
-
# Read existing base requirements
|
142 |
-
existing_requirements = set()
|
143 |
-
if base_req_path.exists():
|
144 |
-
with open(base_req_path) as f:
|
145 |
-
existing_requirements = {line.strip() for line in f if line.strip() and not line.startswith('-r')}
|
146 |
|
147 |
-
#
|
148 |
-
|
|
|
|
|
149 |
|
150 |
-
#
|
151 |
-
with open(
|
152 |
-
#
|
153 |
-
|
154 |
-
f.write(f"{torch_req}\n")
|
155 |
|
156 |
-
# Write
|
157 |
-
for req in
|
|
|
|
|
|
|
158 |
f.write(f"{req}\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
-
|
161 |
-
|
162 |
-
f.write("-r requirements-base.txt\n")
|
163 |
-
for req in sorted(required_additional_packages):
|
164 |
-
f.write(f"{req}\n")
|
165 |
|
166 |
-
#
|
167 |
-
|
168 |
-
|
169 |
-
|
|
|
|
|
|
|
170 |
|
171 |
-
|
172 |
-
logger.info(f"1. Base requirements in {base_req_path}")
|
173 |
-
logger.info(f"2. Main requirements in {main_req_path}")
|
174 |
-
logger.info(f"3. Flash-attention requirements in {flash_req_path}")
|
175 |
-
logger.info("This ensures packages are installed in the correct order")
|
176 |
|
177 |
def create_space(username, space_name):
|
178 |
"""Create or get a Hugging Face Space."""
|
|
|
99 |
raise ValueError(f"Invalid JSON in {json_file}: {e}")
|
100 |
|
101 |
def update_requirements():
|
102 |
+
"""Update consolidated requirements.txt with all necessary packages in the correct order."""
|
103 |
+
logger.info("Setting up consolidated requirements file...")
|
104 |
current_dir = Path(__file__).parent
|
105 |
+
req_path = current_dir / "requirements.txt"
|
|
|
|
|
106 |
|
107 |
+
# All required packages in the correct installation order
|
108 |
+
required_packages = [
|
109 |
+
# Base requirements (install first)
|
110 |
"torch>=2.0.0",
|
|
|
111 |
"accelerate>=0.27.0",
|
112 |
+
"bitsandbytes>=0.41.0",
|
113 |
+
"transformers>=4.36.0",
|
114 |
+
"datasets>=2.15.0",
|
115 |
"huggingface-hub>=0.19.0",
|
116 |
+
"tensorboard>=2.15.0",
|
117 |
+
|
118 |
+
# Main requirements (install second)
|
|
|
|
|
119 |
"einops>=0.7.0",
|
120 |
"filelock>=3.13.1",
|
121 |
+
"gradio>=5.17.0",
|
122 |
"matplotlib>=3.7.0",
|
123 |
"numpy>=1.24.0",
|
124 |
"packaging>=23.0",
|
|
|
133 |
"tqdm>=4.65.0",
|
134 |
"typing-extensions>=4.8.0",
|
135 |
"unsloth>=2024.3"
|
136 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
+
# Optional packages (commented out by default)
|
139 |
+
optional_packages = [
|
140 |
+
"flash-attn==2.5.2"
|
141 |
+
]
|
142 |
|
143 |
+
# Create consolidated requirements file
|
144 |
+
with open(req_path, 'w') as f:
|
145 |
+
f.write("# BASE REQUIREMENTS - Install these critical dependencies first\n")
|
146 |
+
f.write("# ---------------------------------------------------------------------\n")
|
|
|
147 |
|
148 |
+
# Write base dependencies first
|
149 |
+
for i, req in enumerate(required_packages):
|
150 |
+
if i == 7: # After base requirements
|
151 |
+
f.write("\n# MAIN REQUIREMENTS - Install these after base dependencies\n")
|
152 |
+
f.write("# ---------------------------------------------------------------------\n")
|
153 |
f.write(f"{req}\n")
|
154 |
+
|
155 |
+
# Add optional dependencies section
|
156 |
+
f.write("\n# OPTIONAL DEPENDENCIES - Install these last (if needed)\n")
|
157 |
+
f.write("# ---------------------------------------------------------------------\n")
|
158 |
+
for opt_pkg in optional_packages:
|
159 |
+
f.write(f"# {opt_pkg}\n")
|
160 |
|
161 |
+
logger.info(f"Updated consolidated requirements file at {req_path}")
|
162 |
+
logger.info("Requirements are ordered for proper dependency installation")
|
|
|
|
|
|
|
163 |
|
164 |
+
# Remove old requirements files if they exist
|
165 |
+
old_files = ["requirements-base.txt", "requirements-flash.txt"]
|
166 |
+
for old_file in old_files:
|
167 |
+
old_path = current_dir / old_file
|
168 |
+
if old_path.exists():
|
169 |
+
old_path.unlink()
|
170 |
+
logger.info(f"Removed old requirements file: {old_file}")
|
171 |
|
172 |
+
return True
|
|
|
|
|
|
|
|
|
173 |
|
174 |
def create_space(username, space_name):
|
175 |
"""Create or get a Hugging Face Space."""
|