Spaces:
Running on Zero
Running on Zero
Commit ·
a9cd66b
1
Parent(s): cb89a63
Remove incompatible attention extensions
Browse files- app.py +11 -6
- requirements.txt +0 -2
app.py
CHANGED
|
@@ -7,12 +7,16 @@ from diffusers import DiffusionPipeline
|
|
| 7 |
import random
|
| 8 |
import numpy as np
|
| 9 |
import os
|
| 10 |
-
import
|
|
|
|
| 11 |
from huggingface_hub import hf_hub_download
|
| 12 |
from llm_inference import LLMInferenceNode
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Initialize models
|
| 18 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
@@ -23,9 +27,10 @@ huggingface_token = os.getenv("HUGGINGFACE_TOKEN")
|
|
| 23 |
# SD3.5 model
|
| 24 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-3.5-large", torch_dtype=dtype, use_safetensors=True, variant="fp16", token=huggingface_token).to(device)
|
| 25 |
|
| 26 |
-
# Initialize Florence model
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
# Prompt Enhancer
|
| 31 |
enhancer_long = pipeline("summarization", model="gokaygokay/Lamini-Prompt-Enchance-Long", device=device)
|
|
|
|
| 7 |
import random
|
| 8 |
import numpy as np
|
| 9 |
import os
|
| 10 |
+
from unittest.mock import patch
|
| 11 |
+
from transformers.dynamic_module_utils import get_imports
|
| 12 |
from huggingface_hub import hf_hub_download
|
| 13 |
from llm_inference import LLMInferenceNode
|
| 14 |
|
| 15 |
+
def fixed_get_imports(filename):
|
| 16 |
+
imports = get_imports(filename)
|
| 17 |
+
if str(filename).replace("\\", "/").endswith("/modeling_florence2.py"):
|
| 18 |
+
imports = [name for name in imports if name != "flash_attn"]
|
| 19 |
+
return imports
|
| 20 |
|
| 21 |
# Initialize models
|
| 22 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 27 |
# SD3.5 model
|
| 28 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-3.5-large", torch_dtype=dtype, use_safetensors=True, variant="fp16", token=huggingface_token).to(device)
|
| 29 |
|
| 30 |
+
# Initialize Florence model without requiring its optional FlashAttention path.
|
| 31 |
+
with patch("transformers.dynamic_module_utils.get_imports", fixed_get_imports):
|
| 32 |
+
florence_model = AutoModelForCausalLM.from_pretrained('microsoft/Florence-2-base', trust_remote_code=True).to(device).eval()
|
| 33 |
+
florence_processor = AutoProcessor.from_pretrained('microsoft/Florence-2-base', trust_remote_code=True)
|
| 34 |
|
| 35 |
# Prompt Enhancer
|
| 36 |
enhancer_long = pipeline("summarization", model="gokaygokay/Lamini-Prompt-Enchance-Long", device=device)
|
requirements.txt
CHANGED
|
@@ -4,8 +4,6 @@ torch
|
|
| 4 |
transformers==4.46.3
|
| 5 |
sentencepiece
|
| 6 |
spaces
|
| 7 |
-
xformers
|
| 8 |
-
sentencepiece
|
| 9 |
timm
|
| 10 |
einops
|
| 11 |
openai
|
|
|
|
| 4 |
transformers==4.46.3
|
| 5 |
sentencepiece
|
| 6 |
spaces
|
|
|
|
|
|
|
| 7 |
timm
|
| 8 |
einops
|
| 9 |
openai
|