-
Notifications
You must be signed in to change notification settings - Fork 418
Train from inline multimodal rollouts #3320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eligotts
wants to merge
16
commits into
main
Choose a base branch
from
feat/v1-inline-mm-vllm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cb20c6a
feat: train from inline multimodal rollouts
eligotts 27cb537
fix: split multimodal packing bins across workers
eligotts ef12808
fix: materialize trainer multimodal inputs lazily
eligotts 59bbc3d
refactor: simplify lazy multimodal materialization
eligotts 09f280f
Merge main into inline multimodal path
eligotts 538f732
Merge latest main into inline multimodal path
eligotts 6b5de34
Merge remote-tracking branch 'origin/main' into feat/v1-inline-mm-vllm
eligotts 4418fb1
chore: sync inline multimodal dependencies
eligotts 2f89b88
refactor: unify multimodal processing control
eligotts e96b231
chore: sync multimodal naming cleanup
eligotts c1b7a7d
chore: sync explicit renderer token state
eligotts 2e3a0c3
Merge remote-tracking branch 'origin/main' into feat/v1-inline-mm-vllm
eligotts d27af25
docs: clarify Qwen image token count
eligotts ab4ca01
Merge remote-tracking branch 'origin/main' into feat/v1-inline-mm-vllm
eligotts 2ad1838
chore: update verifiers inline multimodal pin
eligotts 577123e
chore: update inline multimodal dependency pins
eligotts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule renderers
updated
34 files
| +23 −15 | README.md | |
| +2 −7 | docs/renderer-config.md | |
| +21 −5 | pyproject.toml | |
| +11 −15 | renderers/__init__.py | |
| +85 −181 | renderers/base.py | |
| +91 −48 | renderers/client.py | |
| +2 −3 | renderers/deepseek_v3.py | |
| +2 −3 | renderers/default.py | |
| +5 −6 | renderers/gemma4.py | |
| +2 −3 | renderers/glm45.py | |
| +2 −3 | renderers/glm5.py | |
| +2 −3 | renderers/gpt_oss.py | |
| +2 −3 | renderers/hy3.py | |
| +5 −6 | renderers/inkling.py | |
| +2 −3 | renderers/kimi_k2.py | |
| +30 −14 | renderers/kimi_k25.py | |
| +2 −3 | renderers/laguna_s21.py | |
| +4 −5 | renderers/laguna_xs2.py | |
| +2 −3 | renderers/llama_3.py | |
| +2 −3 | renderers/minimax_m2.py | |
| +2 −3 | renderers/nemotron3.py | |
| +3 −4 | renderers/prime_qwen3.py | |
| +2 −3 | renderers/qwen3.py | |
| +50 −32 | renderers/qwen35.py | |
| +50 −32 | renderers/qwen3_vl.py | |
| +1 −0 | tests/conftest.py | |
| +1 −0 | tests/test_bridge.py | |
| +76 −2 | tests/test_client.py | |
| +4 −0 | tests/test_disabled_thinking_stability.py | |
| +18 −12 | tests/test_qwen38.py | |
| +0 −26 | tests/test_renderer_config.py | |
| +1 −0 | tests/test_renderer_config_parity.py | |
| +1 −0 | tests/test_roundtrip.py | |
| +14 −1 | uv.lock |
Submodule verifiers
updated
34 files
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from prime_rl.multimodal.base import ForwardPolicy, MaterializedMM, MultimodalAdapter | ||
| from prime_rl.multimodal.registry import get_multimodal_adapter | ||
|
|
||
| __all__ = [ | ||
| "ForwardPolicy", | ||
| "MaterializedMM", | ||
| "MultimodalAdapter", | ||
| "get_multimodal_adapter", | ||
| ] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Any, Protocol | ||
|
|
||
| import torch | ||
| from PIL.Image import Image | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class ForwardPolicy: | ||
| pass_position_ids: bool = True | ||
| requires_mm_token_type_ids: bool = False | ||
| defer_context_parallelism: bool = False | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class MaterializedMM: | ||
| kwargs: dict[str, torch.Tensor] | ||
| forward_policy: ForwardPolicy | ||
|
|
||
|
|
||
| class MultimodalAdapter(Protocol): | ||
| model_types: frozenset[str] | ||
| forward_policy: ForwardPolicy | ||
|
|
||
| def materialize( | ||
| self, | ||
| image_processor: Any, | ||
| images: list[Image], | ||
| placeholder_lengths: list[int], | ||
| ) -> MaterializedMM: ... | ||
|
|
||
|
|
||
| def required_tensors(values: Any, keys: tuple[str, ...]) -> dict[str, torch.Tensor]: | ||
| data = dict(values) | ||
| missing = [key for key in keys if key not in data] | ||
| if missing: | ||
| raise ValueError(f"Image processor did not return {', '.join(missing)}") | ||
| return {key: torch.as_tensor(data[key]).contiguous() for key in keys} |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from PIL.Image import Image | ||
|
|
||
| from prime_rl.multimodal.base import ForwardPolicy, MaterializedMM, required_tensors | ||
|
|
||
|
|
||
| class KimiK25Adapter: | ||
| model_types = frozenset({"kimi_k25"}) | ||
| forward_policy = ForwardPolicy() | ||
|
|
||
| def materialize( | ||
| self, | ||
| image_processor: Any, | ||
| images: list[Image], | ||
| placeholder_lengths: list[int], | ||
| ) -> MaterializedMM: | ||
| preprocess = getattr(image_processor, "preprocess", None) | ||
| if preprocess is None: | ||
| raise ValueError("Kimi image processor is missing preprocess") | ||
| media = [{"type": "image", "image": image} for image in images] | ||
| kwargs = required_tensors( | ||
| preprocess(media, return_tensors="pt"), | ||
| ("pixel_values", "grid_thws"), | ||
| ) | ||
| lengths = [1] * len(kwargs["grid_thws"].reshape(-1, 3)) | ||
| if lengths != placeholder_lengths: | ||
| raise ValueError( | ||
| f"Kimi image placeholder lengths differ from vLLM: expected {placeholder_lengths}, got {lengths}" | ||
| ) | ||
| return MaterializedMM(kwargs=kwargs, forward_policy=self.forward_policy) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from PIL.Image import Image | ||
|
|
||
| from prime_rl.multimodal.base import ForwardPolicy, MaterializedMM, required_tensors | ||
|
|
||
|
|
||
| class QwenVLAdapter: | ||
| model_types = frozenset({"qwen3_vl", "qwen3_vl_moe", "qwen3_5", "qwen3_5_moe"}) | ||
| forward_policy = ForwardPolicy( | ||
| pass_position_ids=False, | ||
| requires_mm_token_type_ids=True, | ||
| defer_context_parallelism=True, | ||
| ) | ||
|
|
||
| def materialize( | ||
| self, | ||
| image_processor: Any, | ||
| images: list[Image], | ||
| placeholder_lengths: list[int], | ||
| ) -> MaterializedMM: | ||
| kwargs = required_tensors( | ||
| image_processor(images=images, return_tensors="pt"), | ||
| ("pixel_values", "image_grid_thw"), | ||
| ) | ||
| merge_size = int(image_processor.merge_size) | ||
| # HF Qwen-VL / renderer pad count: T*H*W / merge_size^2. | ||
| lengths = [int(grid.prod()) // (merge_size * merge_size) for grid in kwargs["image_grid_thw"].reshape(-1, 3)] | ||
| if lengths != placeholder_lengths: | ||
| raise ValueError( | ||
| f"Qwen image placeholder lengths differ from vLLM: expected {placeholder_lengths}, got {lengths}" | ||
| ) | ||
| return MaterializedMM(kwargs=kwargs, forward_policy=self.forward_policy) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from prime_rl.multimodal.base import MultimodalAdapter | ||
| from prime_rl.multimodal.kimi_k25 import KimiK25Adapter | ||
| from prime_rl.multimodal.qwen_vl import QwenVLAdapter | ||
|
|
||
| _ADAPTERS = (QwenVLAdapter(), KimiK25Adapter()) | ||
| _BY_MODEL_TYPE: dict[str, MultimodalAdapter] = { | ||
| model_type: adapter for adapter in _ADAPTERS for model_type in adapter.model_types | ||
| } | ||
|
|
||
|
|
||
| def get_multimodal_adapter(model_type: str) -> MultimodalAdapter: | ||
| try: | ||
| return _BY_MODEL_TYPE[model_type] | ||
| except KeyError as exc: | ||
| raise NotImplementedError(f"Raw image training is not implemented for model type {model_type!r}") from exc | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing KL mismatch validation table for new models
Medium Severity
This PR introduces new custom multimodal adapters (
QwenVLAdapterforqwen3_vl/qwen3_vl_moe/qwen3_5/qwen3_5_moeandKimiK25Adapterforkimi_k25) with distinctForwardPolicyconfigurations that change howposition_ids,mm_token_type_ids, and context parallelism behave during the model forward pass. Per project rules, any PR introducing a new custom model must include a table showing mean KL mismatch across 20 steps on a math environment withbatch_size=64, with all entries below 0.015. No such table is present in the PR description.Additional Locations (2)
src/prime_rl/multimodal/qwen_vl.py#L9-L16src/prime_rl/multimodal/kimi_k25.py#L9-L12Triggered by project rule: BugBot Instructions
Reviewed by Cursor Bugbot for commit ab4ca01. Configure here.