Skip to content

Commit e951de3

Browse files
committed
fix init?
1 parent 1dafd28 commit e951de3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

app/serverless.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,35 @@
1010

1111
from pypdf import PdfReader, PdfWriter
1212

13+
# # Ensure MinerU custom HF classes are available and optionally pre-initialize sglang engine
14+
# try:
15+
# # Importing registers custom model types and/or enables custom code for AutoConfig
16+
# from mineru.backend.vlm.hf_predictor import HuggingfacePredictor # noqa: F401
17+
# except Exception:
18+
# pass
19+
# try:
20+
# from mineru.backend.vlm.predictor import get_predictor # noqa: F401
21+
# except Exception:
22+
# pass
23+
24+
def _maybe_init_sglang_engine_in_main() -> None:
25+
"""Initialize sglang engine in the main process if requested via env.
26+
27+
Per MinerU guidance, sglang-engine must be initialized in the main process.
28+
This avoids scheduler failures when workers spawn without prior initialization.
29+
"""
30+
backend_env = os.getenv("MINERU_BACKEND", "pipeline").lower()
31+
if backend_env == "vlm-sglang-engine":
32+
try:
33+
from mineru.backend.vlm.vlm_analyze import ModelSingleton
34+
# Initialize once; ModelSingleton handles idempotency
35+
ModelSingleton().get_model("sglang-engine", None, None)
36+
except Exception:
37+
# Defer detailed errors to runtime path to avoid import-time crashes
38+
pass
39+
40+
_maybe_init_sglang_engine_in_main()
41+
1342
class TimeoutError(Exception):
1443
pass
1544

0 commit comments

Comments
 (0)