Spaces:
Sleeping
Sleeping
Create download_file.py
Browse files- download_file.py +19 -0
download_file.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# download_model.py
|
2 |
+
import os
|
3 |
+
from unittest.mock import patch
|
4 |
+
from transformers import AutoModelForCausalLM, AutoProcessor
|
5 |
+
from transformers.dynamic_module_utils import get_imports
|
6 |
+
|
7 |
+
def fixed_get_imports(filename: os.PathLike) -> list[str]:
|
8 |
+
if not str(filename).endswith("/modeling_florence2.py"):
|
9 |
+
return get_imports(filename)
|
10 |
+
imports = get_imports(filename)
|
11 |
+
if "flash_attn" in imports:
|
12 |
+
imports.remove("flash_attn")
|
13 |
+
return imports
|
14 |
+
|
15 |
+
with patch("transformers.dynamic_module_utils.get_imports", fixed_get_imports):
|
16 |
+
model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-base-ft", trust_remote_code=True)
|
17 |
+
processor = AutoProcessor.from_pretrained("microsoft/Florence-2-base-ft", trust_remote_code=True)
|
18 |
+
model.save_pretrained("/code/florence_model")
|
19 |
+
processor.save_pretrained("/code/florence_processor")
|