Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -8,19 +8,31 @@ import gradio as gr
|
|
8 |
# Load the model and tokenizer
|
9 |
model_path = "ByteDance/Sa2VA-4B"
|
10 |
|
11 |
-
|
12 |
-
model_path,
|
13 |
-
torch_dtype = torch.bfloat16,
|
14 |
-
low_cpu_mem_usage = True,
|
15 |
-
use_flash_attn = True,
|
16 |
-
#trust_remote_code = True
|
17 |
-
).eval().cuda()
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
def image_vision(image_input_path, prompt):
|
26 |
image_path = image_input_path
|
|
|
8 |
# Load the model and tokenizer
|
9 |
model_path = "ByteDance/Sa2VA-4B"
|
10 |
|
11 |
+
from transformers.dynamic_module_utils import get_imports
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
def fixed_get_imports(filename: str | os.PathLike) -> list[str]:
|
14 |
+
if not str(filename).endswith("/modeling_phi3.py"):
|
15 |
+
return get_imports(filename)
|
16 |
+
imports = get_imports(filename)
|
17 |
+
imports.remove("flash_attn")
|
18 |
+
return imports
|
19 |
+
|
20 |
+
|
21 |
+
with patch("transformers.dynamic_module_utils.get_imports", fixed_get_imports):
|
22 |
+
|
23 |
+
model = AutoModel.from_pretrained(
|
24 |
+
model_path,
|
25 |
+
torch_dtype = torch.bfloat16,
|
26 |
+
low_cpu_mem_usage = True,
|
27 |
+
use_flash_attn = True,
|
28 |
+
trust_remote_code = True
|
29 |
+
).eval().cuda()
|
30 |
+
|
31 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
32 |
+
model_path,
|
33 |
+
trust_remote_code = True,
|
34 |
+
use_fast = False
|
35 |
+
)
|
36 |
|
37 |
def image_vision(image_input_path, prompt):
|
38 |
image_path = image_input_path
|