Skip to content

Lazy-load table recognition models to speed up startup and fix oneDNN crash - #270

Open
Jammy123-prog wants to merge 1 commit into
PFCCLab:mainfrom
Jammy123-prog:perf/lazy-load-table-models
Open

Jammy123-prog wants to merge 1 commit into
PFCCLab:mainfrom
Jammy123-prog:perf/lazy-load-table-models

Conversation

@Jammy123-prog

Copy link
Copy Markdown

Problem

  1. Slow startup: MainWindow.__init__ builds the full PPStructureV3 pipeline unconditionally. That loads ~14 bundled models (~1.1 GB: PP-DocLayout-L, SLANeXt/SLANet, RT-DETR-L cell detectors, etc.) before the main window appears — on a machine without a warm model cache this adds several minutes to launch, even for users who only annotate plain text and never use table recognition. The eager warm-up call table_ocr.predict("./data/paddle.png") has the same cost.
  2. Startup crash with PaddleX >= 3.7: the HPI auto-tuner may pick the oneDNN backend for the table models, which aborts with:
NotImplementedError: (Unimplemented) ConvertPirAttribute2RuntimeAttribute not support
[pir::ArrayAttribute<pir::DoubleAttribute>]
(at ..\paddle\fluid\framework\new_executor\instruction\onednn\onednn_instruction.cc:118)

Observed with paddlepaddle-gpu 3.3.1 + paddlex 3.7.2 on Windows 11 (RTX 1000 Ada, CUDA 12.6).

Fix

  • Initialize self.table_ocr = None and construct the pipeline lazily in a new _get_table_ocr() helper, called from TableRecognition(). Table features work exactly as before — models simply load on first use.
  • Drop the eager table warm-up call (the text-OCR warm-up is kept).
  • Pass enable_mkldnn=False, enable_hpi=False when constructing PPStructureV3 so a stable, working backend is used (mirrors what PPOCRLabel already does for its PaddleOCR instance).
  • The language-switch path now just resets self.table_ocr = None; the pipeline is rebuilt on demand with the new language.

Result

Startup now only loads det/rec models (Creating model lines drop from 16 to 2 in a typical session); resident GPU memory drops accordingly, which also helps low-VRAM laptops. Table recognition remains fully functional, loading its models on first use (~1 min one-time cost, then cached).

Verified: offscreen launch test with custom --det_model_dir/--rec_model_dir models loads only 2 models and runs clean; table recognition path works after lazy init.

中文说明

问题:① 启动时无条件构建 PPStructureV3 全套表格识别管线(约 14 个模型、1.1GB),纯文本标注场景也要多等数分钟;② PaddleX ≥ 3.7 的 HPI 自动调优可能为表格模型选中 oneDNN 后端,启动即抛 NotImplementedError 崩溃。

修复:表格管线改为首次使用时懒加载(新增 _get_table_ocr());删除启动阶段的表格推理预热;构造时显式 enable_mkldnn=False, enable_hpi=False(与 PPOCRLabel 对 PaddleOCR 的处理一致);切换语言处仅置空 table_ocr,按需重建。启动只加载检测/识别两个模型,表格标注功能不受影响。已在 Windows 11 + paddlepaddle-gpu 3.3.1 环境验证。

Startup currently builds the full PP-StructureV3 pipeline unconditionally.
That loads ~14 bundled models (~1.1 GB) before the main window appears,
adding several minutes to launch on machines without a warm model cache,
even for users who only annotate plain text and never touch the
table-recognition feature. The startup warm-up run of
table_ocr.predict() has the same cost.

With PaddleX >= 3.7 there is a second problem: the HPI auto-tuner may
select the oneDNN backend for the table models, which aborts with
"NotImplementedError: ConvertPirAttribute2RuntimeAttribute not support
[pir::ArrayAttribute<pir::DoubleAttribute>]" on Paddle 3.3.1.

Changes:
- Initialize self.table_ocr = None and build the pipeline lazily in a
  new _get_table_ocr() helper, used by TableRecognition().
- Drop the eager table warm-up call on startup (the text OCR warm-up is
  kept).
- Pass enable_mkldnn=False and enable_hpi=False when constructing
  PPStructureV3 to keep a stable, working backend.
- The language-switch rebuild path now just resets self.table_ocr so the
  pipeline is rebuilt on demand with the new language.

Result: startup only loads the det/rec models; table recognition still
works, loading its models on first use.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant