Skip to content

Fix RecursionError in MediaWithBytes unpickling#31191

Merged
DarkLight1337 merged 3 commits intovllm-project:mainfrom
nrghosh:nrghosh/multimodal-pickling-fix
Jan 6, 2026
Merged

Fix RecursionError in MediaWithBytes unpickling#31191
DarkLight1337 merged 3 commits intovllm-project:mainfrom
nrghosh:nrghosh/multimodal-pickling-fix

Conversation

@nrghosh
Copy link
Copy Markdown
Contributor

@nrghosh nrghosh commented Dec 22, 2025

Guard __getattr__ against recursion when media attribute is not yet set during pickle deserialization. Adds regression test.

Fixes: #30818

Purpose

Fix RecursionError when unpickling MediaWithBytes dataclass, which breaks vLLM usage with Ray. The __getattr__ method recursively calls itself when self.media is not yet set during pickle deserialization.

Test Plan

pytest tests/multimodal/test_image.py::test_media_with_bytes_pickle_roundtrip -v

Test Result

Test verifies pickle roundtrip succeeds and attribute delegation works before and after unpickling. Without the fix, unpickling causes RecursionError: maximum recursion depth exceeded.


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Guard __getattr__ against recursion when media attribute is not yet set
during pickle deserialization. Adds regression test.

Fixes: vllm-project#30818

Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com>
@mergify mergify bot added the multi-modality Related to multi-modality (#4194) label Dec 22, 2025
Copy link
Copy Markdown
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 addresses a RecursionError that occurs when unpickling MediaWithBytes objects. The root cause is the __getattr__ method recursively calling itself when the media attribute is not yet set during deserialization. The proposed fix introduces a guard to check for the presence of media in the instance's __dict__, which is a correct and idiomatic way to prevent such recursion. A comprehensive regression test is also added, which validates the fix by performing a pickle roundtrip and asserting attribute delegation works correctly before and after. The changes are well-implemented and effectively resolve the issue.

@mergify
Copy link
Copy Markdown

mergify bot commented Dec 22, 2025

Hi @nrghosh, the pre-commit checks have failed. Please run:

uv pip install pre-commit
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy or markdownlint failing?
mypy and markdownlint are run differently in CI. If the failure is related to either of these checks, please use the following commands to run them locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10
# For markdownlint
pre-commit run --hook-stage manual markdownlint

@nrghosh nrghosh requested a review from hmellor as a code owner January 6, 2026 17:39
- and fix ordering

Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com>
@nrghosh nrghosh force-pushed the nrghosh/multimodal-pickling-fix branch from 75f5925 to 34a4067 Compare January 6, 2026 18:04
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) January 6, 2026 18:09
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Jan 6, 2026
@DarkLight1337 DarkLight1337 merged commit ada6f91 into vllm-project:main Jan 6, 2026
47 checks passed
yugong333 pushed a commit to yugong333/vllm that referenced this pull request Jan 9, 2026
Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com>
akh64bit pushed a commit to akh64bit/vllm that referenced this pull request Jan 16, 2026
Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com>
dsuhinin pushed a commit to dsuhinin/vllm that referenced this pull request Jan 21, 2026
Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com>
Signed-off-by: dsuhinin <suhinin.dmitriy@gmail.com>
ItzDEXX pushed a commit to ItzDEXX/vllm that referenced this pull request Feb 19, 2026
Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

multi-modality Related to multi-modality (#4194) ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Unpickling MediaWithBytes dataclass leads to RecursionError

3 participants