[Model] Add DeepSeek-OCR-2 PaddlePaddle implementation with full SFT and LoRA support#4324
Open
forBlank wants to merge 9 commits intoPaddlePaddle:developfrom
Open
[Model] Add DeepSeek-OCR-2 PaddlePaddle implementation with full SFT and LoRA support#4324forBlank wants to merge 9 commits intoPaddlePaddle:developfrom
forBlank wants to merge 9 commits intoPaddlePaddle:developfrom
Conversation
|
Thanks for your contribution! |
Codecov Report❌ Patch coverage is ❌ Your patch status has failed because the patch coverage (56.26%) is below the target coverage (75.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #4324 +/- ##
==========================================
Coverage ? 39.45%
==========================================
Files ? 478
Lines ? 90740
Branches ? 0
==========================================
Hits ? 35803
Misses ? 54937
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
lugimzzz
reviewed
Apr 21, 2026
| per_device_eval_batch_size: 8 | ||
| per_device_train_batch_size: 8 | ||
| num_train_epochs: 2 | ||
| max_steps: -1 |
Collaborator
There was a problem hiding this comment.
新增一个文档简单介绍一下,并提供数据集./ocr_vl_sft-train_Bengali.jsonl下载方式
| "sam_model.*mlp.lin1.*", | ||
| "sam_model.*mlp.lin2.*", | ||
| # Qwen2 Encoder-as-Decoder | ||
| "qwen2_model.*self_attn.qkv_proj.*", |
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.
Before submitting
testsfolder. If there are codecov issues, please add tests cases first.PR types
New features
PR changes
Models
Description
This PR migrates DeepSeek-OCR-2 from PyTorch to PaddlePaddle, including the full model definition, data pipeline, training configuration, and unit tests.
Model Architecture
DeepSeek-OCR-2 is a multi-modal OCR model with a three-stage vision-language architecture:
Changes
Model (
paddleformers/transformers/deepseek_ocr2/)configuration.py:DeepseekOCR2Configwith SAM / Qwen2 encoder / LLM sub-configsmodeling.py: Full model implementation —DeepseekOCR2Model,DeepseekOCR2ForCausalLM,DeepseekOCR2ForConditionalGeneration; includes AOA weight mapping for checkpoint loadingconversation.py: Conversation format and prompt builder__init__.py: Module exportsRegistration (
paddleformers/transformers/)DeepseekOCR2Config/ model classes to auto mapping andtransformers/__init__.pydeepseek_vl_v2as alias inSPECIAL_MODEL_TYPE_TO_MODULE_NAMEData Pipeline
mm_plugin.py:DeepseekOCR2Plugin— dynamic crop (up to 6 tiles), global/local view preprocessing, image token expansion based on spatial crop ratiotemplate.py: Registerdeepseek_ocr2conversation templatecollate.py:mm_collate_fn_ds_ocr2— handles images_crop / images_spatial_crop / images_seq_mask batchingworkflow.py: Dispatch tomm_collate_fn_ds_ocr2whenmodel_type == "deepseek_ocr2"LoRA (
cli/utils/llm_utils.py)Training Configs (
examples/best_practices/DeepSeek-OCR-2/)deepseek_ocr2_full_8k_config.yaml: Full fine-tuning, 8K seq len, sharding stage1, bf16deepseek_ocr2_lora_8k_config.yaml: LoRA fine-tuning, rank=8, alpha=32Tests (
tests/transformers/deepseek_ocr2/)test_modeling.py: Unit tests covering model construction, forward pass, and generation with tiny config