George-API commited on
Commit
3edc673
·
verified ·
1 Parent(s): 71642d9

Upload folder using huggingface_hub

Browse files
requirements-base.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ torch>=2.0.0
2
+ accelerate>=0.27.0
3
+ bitsandbytes>=0.41.0
4
+ datasets>=2.15.0
5
+ gradio>=5.17.0
6
+ huggingface-hub>=0.19.0
7
+ tensorboard>=2.15.0
8
+ transformers>=4.36.0
requirements-flash.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ -r requirements-base.txt
2
+ flash-attn==2.5.2
requirements.txt CHANGED
@@ -22,4 +22,3 @@ tqdm>=4.65.0
22
  transformers>=4.36.0
23
  typing-extensions>=4.8.0
24
  unsloth>=2024.3
25
- flash-attn==2.5.2
 
22
  transformers>=4.36.0
23
  typing-extensions>=4.8.0
24
  unsloth>=2024.3
 
update_space.py CHANGED
@@ -97,10 +97,12 @@ def verify_configs():
97
  raise ValueError(f"Invalid JSON in {json_file}: {e}")
98
 
99
  def update_requirements():
100
- """Update requirements.txt with necessary packages."""
101
  current_dir = Path(__file__).parent
102
- req_path = current_dir / "requirements.txt"
 
103
 
 
104
  required_packages = {
105
  "torch>=2.0.0",
106
  "transformers>=4.36.0",
@@ -112,34 +114,34 @@ def update_requirements():
112
  "datasets>=2.15.0"
113
  }
114
 
115
- # Read existing requirements
116
  existing_requirements = set()
117
- if req_path.exists():
118
- with open(req_path) as f:
119
- existing_requirements = {line.strip() for line in f if line.strip()}
120
 
121
  # Add new requirements
122
  updated_requirements = existing_requirements.union(required_packages)
123
 
124
- # Write updated requirements with torch first and flash-attn last
125
- with open(req_path, 'w') as f:
126
  # Ensure torch is first
127
  torch_req = next((req for req in updated_requirements if req.startswith("torch")), "torch>=2.0.0")
128
  f.write(f"{torch_req}\n")
129
 
130
- # Extract flash-attn to add it last
131
- flash_attn_req = next((req for req in updated_requirements if req.startswith("flash-attn")), None)
132
-
133
- # Write all other requirements (excluding torch and flash-attn)
134
- for req in sorted(r for r in updated_requirements
135
- if not r.startswith("torch") and not r.startswith("flash-attn")):
136
  f.write(f"{req}\n")
137
-
138
- # Add flash-attn as the very last package
139
- if flash_attn_req:
140
- f.write(f"{flash_attn_req}\n")
141
 
142
- logger.info("Updated requirements.txt with torch listed first and flash-attn listed last")
 
 
 
 
 
 
 
 
143
 
144
  def create_space(username, space_name):
145
  """Create or get a Hugging Face Space."""
 
97
  raise ValueError(f"Invalid JSON in {json_file}: {e}")
98
 
99
  def update_requirements():
100
+ """Update requirements.txt with necessary packages using a two-stage installation process."""
101
  current_dir = Path(__file__).parent
102
+ base_req_path = current_dir / "requirements-base.txt"
103
+ flash_req_path = current_dir / "requirements-flash.txt"
104
 
105
+ # First ensure base requirements exist
106
  required_packages = {
107
  "torch>=2.0.0",
108
  "transformers>=4.36.0",
 
114
  "datasets>=2.15.0"
115
  }
116
 
117
+ # Read existing base requirements
118
  existing_requirements = set()
119
+ if base_req_path.exists():
120
+ with open(base_req_path) as f:
121
+ existing_requirements = {line.strip() for line in f if line.strip() and not line.startswith('-r')}
122
 
123
  # Add new requirements
124
  updated_requirements = existing_requirements.union(required_packages)
125
 
126
+ # Write updated base requirements
127
+ with open(base_req_path, 'w') as f:
128
  # Ensure torch is first
129
  torch_req = next((req for req in updated_requirements if req.startswith("torch")), "torch>=2.0.0")
130
  f.write(f"{torch_req}\n")
131
 
132
+ # Write all other requirements (excluding torch)
133
+ for req in sorted(r for r in updated_requirements if not r.startswith("torch")):
 
 
 
 
134
  f.write(f"{req}\n")
 
 
 
 
135
 
136
+ # Create or update flash-attn requirements
137
+ with open(flash_req_path, 'w') as f:
138
+ f.write("-r requirements-base.txt\n")
139
+ f.write("flash-attn==2.5.2\n")
140
+
141
+ logger.info("Updated requirements files for two-stage installation:")
142
+ logger.info(f"1. Base requirements in {base_req_path}")
143
+ logger.info(f"2. Flash-attention requirements in {flash_req_path}")
144
+ logger.info("This ensures torch is installed before flash-attn")
145
 
146
  def create_space(username, space_name):
147
  """Create or get a Hugging Face Space."""