Skip to content

fix: add PIL image and processor serialization for VLM RPC#1070

Open
Adiactive wants to merge 1 commit intoinclusionAI:mainfrom
Adiactive:fix/vlm-rpc-serialization
Open

fix: add PIL image and processor serialization for VLM RPC#1070
Adiactive wants to merge 1 commit intoinclusionAI:mainfrom
Adiactive:fix/vlm-rpc-serialization

Conversation

@Adiactive
Copy link

@Adiactive Adiactive commented Mar 21, 2026

Summary

This PR fixes VLM RPC serialization failures for multimodal training workloads by adding serialization support for:

  • PIL image payloads in rollout submission
  • Hugging Face processors (ProcessorMixin) in checkpoint save metadata

Root cause

Two RPC payload types were not JSON-serializable in areal/infra/rpc/serialization.py:

  1. PIL images (JpegImageFile) in rollout submit path
  2. Qwen2.5-VL processor (Qwen2_5_VLProcessor) in SaveLoadMeta during save/checkpoint

Changes

  • Add SerializedPILImage (PNG bytes -> base64 -> round-trip to PIL image)
  • Add SerializedProcessor (archive via save_pretrained -> zip/base64 -> AutoProcessor.from_pretrained)
  • Wire both into serialize_value() and deserialize_value()
  • Add tests:
    • test_pil_image_roundtrip
    • test_processor

Validation

  • pytest tests/test_serialization.py -v on GPU host: 10 passed
  • Lint/format checks passed (ruff check, ruff format --check)

Training results after fix

Environment

  • Platform: Linux
  • Distributed actor workers: 4
  • Scheduler: LocalScheduler
  • Model: Qwen2.5-VL-3B-Instruct
  • Dataset/workload: geometry3k GRPO multimodal training

Following 1.0.2-vllm docker image

docker pull ghcr.io/inclusionai/areal-runtime:v1.0.2-vllm
docker run -it --name areal-node1 \
   --privileged --gpus all --network host \
   --shm-size 700g -v /path/to/mount:/path/to/mount \
   ghcr.io/inclusionai/areal-runtime:v1.0.2-vllm\
   /bin/bash
git clone https://github.com/inclusionAI/AReaL /path/to/mount/AReaL
cd /path/to/mount/AReaL
uv pip install -e . --no-deps

Script

python3 examples/vlm/geometry3k_grpo.py \
    --config examples/vlm/geometry3k_grpo.yaml

Eval-Rollout/Reward

image

Related issue

Fixes #1069

VLM training (e.g. geometry3k with Qwen2.5-VL) fails during RPC
communication because PIL images and HuggingFace processors
(ProcessorMixin) are not JSON-serializable.

- Add SerializedPILImage: encodes PIL images as base64 PNG for
  rollout submit calls
- Add SerializedProcessor: archives processors via save_pretrained
  into a zip, mirroring the existing SerializedTokenizer pattern
- Wire both into serialize_value() and deserialize_value()
- Add round-trip tests for both types

Fixes: "Object of type JpegImageFile is not JSON serializable"
Fixes: "Object of type Qwen2_5_VLProcessor is not JSON serializable"
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves critical RPC serialization failures encountered in multimodal training workloads. By introducing robust serialization mechanisms for PIL images and Hugging Face processors, it ensures that these complex data types can be correctly transmitted and stored within the system, thereby stabilizing VLM-related operations.

Highlights

  • PIL Image Serialization: Added support for serializing and deserializing PIL image payloads, crucial for VLM (Vision-Language Model) RPC rollout submissions.
  • Hugging Face Processor Serialization: Implemented serialization and deserialization for Hugging Face processors (e.g., ProcessorMixin), enabling their inclusion in checkpoint save metadata.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively adds serialization support for PIL images and Hugging Face processors, which is crucial for VLM RPC workloads. The implementation for SerializedPILImage is clean and robust. The addition of SerializedProcessor correctly handles archiving and compression, and the integration into the main serialize_value and deserialize_value functions is well-executed. The accompanying tests are thorough and validate the new functionality well.

My main feedback is regarding significant code duplication between the new SerializedProcessor and the existing SerializedTokenizer classes. Refactoring this shared logic would greatly improve the maintainability of the code. I've left a specific comment with a suggestion on how to address this. I also have a minor suggestion to rename some constants for better clarity.

raise ValueError(msg)


class SerializedProcessor(BaseModel):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There is significant code duplication between the new SerializedProcessor class and the existing SerializedTokenizer class. The methods for archiving (_archive_processor), compression (_maybe_compress), and decompression (_maybe_decompress) are nearly identical.

This duplication makes the code harder to maintain, as any bug fix or improvement in this logic would need to be applied in two places.

To improve maintainability, I recommend refactoring this common logic. For example, you could extract the shared logic into standalone utility functions that both SerializedTokenizer and SerializedProcessor can use.

)
compression = (
zipfile.ZIP_STORED
if total_size < TOKENIZER_ARCHIVE_INLINE_THRESHOLD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since TOKENIZER_ARCHIVE_INLINE_THRESHOLD and TOKENIZER_ZSTD_THRESHOLD (used on line 512) are now also used for serializing processors, consider renaming them to be more generic, for example ARCHIVE_INLINE_THRESHOLD and ZSTD_COMPRESSION_THRESHOLD. This would improve code clarity.

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.

[BUG] VLM RPC serialization fails for PIL images and Qwen2_5_VLProcessor

1 participant