File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1010
1111from 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+
1342class TimeoutError (Exception ):
1443 pass
1544
You can’t perform that action at this time.
0 commit comments