Repository navigation
feat(models): port PaddleOCR-VL (NaViT vision + ERNIE-4.5 MRoPE text) - #595
Merged
Merged
Conversation
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.
…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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_vlreference 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_normplus a two-layer MLP) that folds eachspatial_merge_sizesquared block into one text-width token.src/vision/processors/paddleocr_vl.rs: OCR image processor with the referencesmart_resize(patch times merge factor, min/max pixel clamps), SigLIP normalization, andtemporal_patch_size=1patchification.src/models/paddleocr_vl.rs: ERNIE-4.5 dense decoder (RMSNorm, SwiGLU, GQA, optionalhead_dimoverride and projection bias) driven by sectioned half-split MRoPE, reusingMRopeState.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, fusedqkv, projector rename).Registration and wiring:
ModelType::PaddleOcrVL,detection.rsarm formodel_typepaddleocr_vl,model_metadata.rsentry, and adocs/supported-models.mdrow.LoadedModel::PaddleOcrVLplus a dedicatedVlmRuntimeRef::PaddleOcrruntime so the OCR processor and vision encoder run in the live embedding path.fallback_architecturemapsPaddleOcrVLto 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-derivedsmart_resize/grid parity plus construct-and-run shape checks for the encoder, projector, and text decoder)cargo check --lib --testscargo clippy --lib --tests -- -D warningscargo fmt --checkCloses #526