Spaces:
Running
Running
Commit
·
47bf6ec
1
Parent(s):
bf6c79b
chage torch_dtype
Browse files
app.py
CHANGED
@@ -13,9 +13,17 @@ from transformers import AutoProcessor, AutoModelForVision2Seq
|
|
13 |
from transformers.image_utils import load_image
|
14 |
from pathlib import Path
|
15 |
import time
|
|
|
16 |
|
17 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
pipeline_options = PdfPipelineOptions(enable_remote_services=True)
|
20 |
converter = DocumentConverter(
|
21 |
format_options={
|
@@ -28,7 +36,7 @@ pipeline = PPStructureV3()
|
|
28 |
processor = AutoProcessor.from_pretrained("ds4sd/SmolDocling-256M-preview")
|
29 |
model = AutoModelForVision2Seq.from_pretrained(
|
30 |
"ds4sd/SmolDocling-256M-preview",
|
31 |
-
torch_dtype=
|
32 |
_attn_implementation="flash_attention_2" if DEVICE == "cuda" else "eager",
|
33 |
).to(DEVICE)
|
34 |
|
|
|
13 |
from transformers.image_utils import load_image
|
14 |
from pathlib import Path
|
15 |
import time
|
16 |
+
import os
|
17 |
|
18 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
19 |
|
20 |
+
# Optimize for CPU: set float32 and use all CPU threads
|
21 |
+
if DEVICE == "cpu":
|
22 |
+
torch.set_num_threads(os.cpu_count() or 1)
|
23 |
+
smoldocling_dtype = torch.float32
|
24 |
+
else:
|
25 |
+
smoldocling_dtype = torch.bfloat16
|
26 |
+
|
27 |
pipeline_options = PdfPipelineOptions(enable_remote_services=True)
|
28 |
converter = DocumentConverter(
|
29 |
format_options={
|
|
|
36 |
processor = AutoProcessor.from_pretrained("ds4sd/SmolDocling-256M-preview")
|
37 |
model = AutoModelForVision2Seq.from_pretrained(
|
38 |
"ds4sd/SmolDocling-256M-preview",
|
39 |
+
torch_dtype=smoldocling_dtype,
|
40 |
_attn_implementation="flash_attention_2" if DEVICE == "cuda" else "eager",
|
41 |
).to(DEVICE)
|
42 |
|