Skip to content

feat(models): port PaddleOCR-VL (NaViT vision + ERNIE-4.5 MRoPE text) - #595

Merged
inureyes merged 3 commits into
mainfrom
feature/issue-526-paddleocr-vl
Jul 1, 2026
Merged

inureyes merged 3 commits into
mainfrom
feature/issue-526-paddleocr-vl

Conversation

@inureyes

@inureyes inureyes commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

Ports PaddleOCR-VL, a document-OCR vision-language model that pairs a NaViT dynamic-resolution vision encoder with a lightweight ERNIE-4.5 text decoder using MRoPE. The port follows the mlx-vlm paddleocr_vl reference and reuses the ERNIE-4.5 text architecture plus the Qwen-family MRoPE machinery.

What changed

New model components:

  • src/vision/encoders/paddleocr_vl.rs: NaViT SigLIP-style ViT. Conv2d-as-Linear patch embedding, bilinearly interpolated learned position embeddings, 2D vision RoPE in raw row-major order (no spatial-merge reordering), cu_seqlens-packed per-segment attention, post_layernorm.
  • src/vision/connectors/paddleocr_vl.rs: spatial-merge projector (pre_norm plus a two-layer MLP) that folds each spatial_merge_size squared block into one text-width token.
  • src/vision/processors/paddleocr_vl.rs: OCR image processor with the reference smart_resize (patch times merge factor, min/max pixel clamps), SigLIP normalization, and temporal_patch_size=1 patchification.
  • src/models/paddleocr_vl.rs: ERNIE-4.5 dense decoder (RMSNorm, SwiGLU, GQA, optional head_dim override and projection bias) driven by sectioned half-split MRoPE, reusing MRopeState.
  • src/vision/paddleocr_vl.rs: VLM wrapper. LLaVA-style image-feature merge and 3D [T, H, W] MRoPE position ids at prefill.
  • src/loading/vlm_paddleocr.rs: loader with reference-faithful weight remap (visual namespace, fused qkv, projector rename).

Registration and wiring:

  • ModelType::PaddleOcrVL, detection.rs arm for model_type paddleocr_vl, model_metadata.rs entry, and a docs/supported-models.md row.
  • LoadedModel::PaddleOcrVL plus a dedicated VlmRuntimeRef::PaddleOcr runtime so the OCR processor and vision encoder run in the live embedding path.
  • fallback_architecture maps PaddleOcrVL to the ERNIE-4.5 text arch string.

Scope note: PaddleOCR-VL vision fast paths (perf) are a separate follow-up. Real-checkpoint generation validation is deferred; this PR validates via reference-parity and unit tests.

Test plan

  • cargo test --test paddleocr_vl_parity (6 passed: reference-derived smart_resize/grid parity plus construct-and-run shape checks for the encoder, projector, and text decoder)
  • cargo check --lib --tests
  • cargo clippy --lib --tests -- -D warnings
  • cargo fmt --check

Closes #526

Add PaddleOCR-VL, a document-OCR vision-language model that pairs a NaViT dynamic-resolution vision encoder with a lightweight ERNIE-4.5 text decoder using MRoPE.

New model components:

- Vision encoder (src/vision/encoders/paddleocr_vl.rs): SigLIP-style ViT with a Conv2d-as-Linear patch embedding, bilinearly interpolated learned position embeddings, 2D vision RoPE in raw row-major order (no spatial-merge reordering), cu_seqlens-packed per-segment attention, and post_layernorm.
- Spatial-merge projector (src/vision/connectors/paddleocr_vl.rs): pre_norm plus a two-layer MLP that folds each spatial_merge_size squared block of vision tokens into one text-width token.
- OCR image processor (src/vision/processors/paddleocr_vl.rs): the reference smart_resize (patch times merge factor with min/max pixel clamps), SigLIP normalization, and temporal_patch_size=1 patchification.
- Text decoder (src/models/paddleocr_vl.rs): the ERNIE-4.5 dense stack (RMSNorm, SwiGLU, GQA, optional head_dim override and projection bias) driven by sectioned half-split MRoPE, reusing MRopeState for per-sequence position tracking.
- VLM wrapper (src/vision/paddleocr_vl.rs): composes the pieces, merges image features LLaVA-style, and computes 3D [T, H, W] MRoPE position ids at prefill.

Registration and wiring:

- ModelType::PaddleOcrVL, a detection arm for model_type "paddleocr_vl", a metadata table entry, and a docs/supported-models.md row.
- Loader (src/loading/vlm_paddleocr.rs) with a reference-faithful weight remap (visual namespace, fused qkv, projector rename).
- LoadedModel::PaddleOcrVL and a dedicated VlmRuntimeRef::PaddleOcr runtime so the OCR processor and vision encoder run in the live embedding path.

Vision fast paths (perf) are a separate follow-up. Adds tests/paddleocr_vl_parity.rs: reference-derived smart_resize and grid checks plus construct-and-run shape checks for the encoder, projector, and text decoder.
@inureyes inureyes added type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:models Model architectures, weights, loading, metadata status:review Under review status:done Completed and removed status:review Under review labels Jul 1, 2026
inureyes added 2 commits July 2, 2026 02:29
…dleocr-vl

# Conflicts:
#	docs/supported-models.md
#	src/loaded_model.rs
#	src/loading/mod.rs
#	src/model_metadata.rs
#	src/models/detection.rs
#	src/models/mod.rs
@inureyes
inureyes merged commit 1a3a386 into main Jul 1, 2026
4 checks passed
@inureyes
inureyes deleted the feature/issue-526-paddleocr-vl branch July 2, 2026 13:49
@inureyes inureyes self-assigned this Aug 31, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…lablup#595)

Add PaddleOCR-VL, a document-OCR vision-language model that pairs a NaViT dynamic-resolution vision encoder with a lightweight ERNIE-4.5 text decoder using MRoPE.

New model components:

- Vision encoder (src/vision/encoders/paddleocr_vl.rs): SigLIP-style ViT with a Conv2d-as-Linear patch embedding, bilinearly interpolated learned position embeddings, 2D vision RoPE in raw row-major order (no spatial-merge reordering), cu_seqlens-packed per-segment attention, and post_layernorm.
- Spatial-merge projector (src/vision/connectors/paddleocr_vl.rs): pre_norm plus a two-layer MLP that folds each spatial_merge_size squared block of vision tokens into one text-width token.
- OCR image processor (src/vision/processors/paddleocr_vl.rs): the reference smart_resize (patch times merge factor with min/max pixel clamps), SigLIP normalization, and temporal_patch_size=1 patchification.
- Text decoder (src/models/paddleocr_vl.rs): the ERNIE-4.5 dense stack (RMSNorm, SwiGLU, GQA, optional head_dim override and projection bias) driven by sectioned half-split MRoPE, reusing MRopeState for per-sequence position tracking.
- VLM wrapper (src/vision/paddleocr_vl.rs): composes the pieces, merges image features LLaVA-style, and computes 3D [T, H, W] MRoPE position ids at prefill.

Registration and wiring:

- ModelType::PaddleOcrVL, a detection arm for model_type "paddleocr_vl", a metadata table entry, and a docs/supported-models.md row.
- Loader (src/loading/vlm_paddleocr.rs) with a reference-faithful weight remap (visual namespace, fused qkv, projector rename).
- LoadedModel::PaddleOcrVL and a dedicated VlmRuntimeRef::PaddleOcr runtime so the OCR processor and vision encoder run in the live embedding path.

Vision fast paths (perf) are a separate follow-up. Adds tests/paddleocr_vl_parity.rs: reference-derived smart_resize and grid checks plus construct-and-run shape checks for the encoder, projector, and text decoder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:models Model architectures, weights, loading, metadata priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(models): port PaddleOCR-VL (NaViT dynamic-resolution vision + ERNIE-4.5 text)

1 participant