Sync modeling_paddleocr_vl.py with PaddleOCR-VL-1.6 (transformers v5 support)

#1
by Bvicii - opened
PaddlePaddle org

Replace modeling_paddleocr_vl.py with the latest version from PaddleOCR-VL-1.6. The architecture is identical; configuration_paddleocr_vl.py, processing/image_processing code and processor configs already match 1.6 byte-for-byte, so only this file changes.

Main changes (transformers v5 support, 4.x still works):

  • Import merge_with_config_defaults as check_model_inputs on transformers >= 5.2, fall back to the old name otherwise.
  • Wrap create_causal_mask to handle its signature changes (input_embeds -> inputs_embeds, cache_position removed) and pass 4D masks through.
  • Compute default RoPE locally (no longer in ROPE_INIT_FUNCTIONS in v5) and initialize non-persistent buffers (inv_freq, position_ids) in _init_weights.
  • Route weight init through transformers.initialization when available and skip tensors already loaded from the checkpoint.
  • _tied_weights_keys as a dict; _supports_flash_attn flag.
  • Vision attention: attend per image when cu_seqlens packs several images (non-flash path).
  • prepare_inputs_for_generation: read cache_position created by the v5 parent; drop pixel_values only once the KV cache holds tokens.

šŸ¤– Generated with Claude Code

Co-Authored-By: Claude Code noreply@anthropic.com

Bvicii changed pull request status to merged
Bvicii deleted the refs/pr/1 ref

Sign up or log in to comment