Spaces:
Sleeping
Sleeping
Install flash-attn at runtime for HF Spaces
Browse files- Remove flash-attn from requirements.txt to avoid build issues
- Install flash-attn at startup only when on HF Spaces (SPACE_ID env var)
- Use --no-build-isolation flag to use pre-built wheels
- Made optional: continues without flash-attn if installation fails
- Installs after torch is available, avoiding build dependency issues
- app.py +12 -0
- requirements.txt +0 -1
app.py
CHANGED
|
@@ -21,6 +21,18 @@ from mosaic.gradio_app import download_and_process_models
|
|
| 21 |
from mosaic.ui import launch_gradio
|
| 22 |
|
| 23 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
# Install Paladin from GitHub
|
| 25 |
GIT_TOKEN = os.environ.get("GH_TOKEN")
|
| 26 |
if GIT_TOKEN:
|
|
|
|
| 21 |
from mosaic.ui import launch_gradio
|
| 22 |
|
| 23 |
if __name__ == "__main__":
|
| 24 |
+
# Install flash-attn for H100 acceleration (if on Spaces)
|
| 25 |
+
if os.environ.get("SPACE_ID"):
|
| 26 |
+
try:
|
| 27 |
+
subprocess.run(
|
| 28 |
+
"pip install flash-attn --no-build-isolation",
|
| 29 |
+
shell=True,
|
| 30 |
+
check=False,
|
| 31 |
+
capture_output=True,
|
| 32 |
+
)
|
| 33 |
+
except Exception:
|
| 34 |
+
pass # Flash-attn is optional, continue without it
|
| 35 |
+
|
| 36 |
# Install Paladin from GitHub
|
| 37 |
GIT_TOKEN = os.environ.get("GH_TOKEN")
|
| 38 |
if GIT_TOKEN:
|
requirements.txt
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
--extra-index-url https://download.pytorch.org/whl/cu121
|
| 2 |
torch>=2.0.0,<2.6
|
| 3 |
torchvision>=0.15.0
|
| 4 |
-
flash-attn>=2.5.0
|
| 5 |
open-clip-torch
|
| 6 |
gradio>=5.49.0
|
| 7 |
loguru>=0.7.3
|
|
|
|
| 1 |
--extra-index-url https://download.pytorch.org/whl/cu121
|
| 2 |
torch>=2.0.0,<2.6
|
| 3 |
torchvision>=0.15.0
|
|
|
|
| 4 |
open-clip-torch
|
| 5 |
gradio>=5.49.0
|
| 6 |
loguru>=0.7.3
|