Skip to content

feat(multimodal): Support multimodal Megatron generation. - #3834

Closed
cspades wants to merge 15 commits into
NVIDIA-NeMo:mainfrom
cspades:cye/rl_mllm_omni_multimodal
Closed

cspades wants to merge 15 commits into
NVIDIA-NeMo:mainfrom
cspades:cye/rl_mllm_omni_multimodal

Conversation

@cspades

@cspades cspades commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Depends on NVIDIA/Megatron-LM#6809 and NVIDIA-NeMo/Megatron-Bridge#5799

Screenshot 2026-08-25 at 1 26 50 PM Screenshot 2026-08-26 at 1 40 41 AM

Usage

Cause I keep forgetting where everything is...

Non-Gym RL Multimodal Data Pipeline

Dataset preprocessing:

vlm_hf_data_processor → resolve_to_image / load_video → Hugging Face Omni processor → produces token_ids, pixel_values, imgs_sizes, optionally num_frames → stores media as PackedTensor

Files:

nemo_rl/data/processors.py
nemo_rl/data/multimodal_utils.py

Rollout generation:

RolloutManager.generate_and_push → AsyncRolloutImpl._generate_response → batched_message_log_to_flat_message → MegatronGeneration.generate_async → MegatronWorker._prepare_data_for_generation → _sample_vision_tensors → _build_prompt_and_multimodal_data → MCore InferenceClient.add_request

Files:

nemo_rl/experience/rollout_manager.py
nemo_rl/data/llm_message_utils.py
nemo_rl/models/generation/megatron/megatron_worker.py

Megatron inference:

resolve_multimodal_data_for_engine → tensor payload passes through without decoding → DynamicInferenceEngine._build_vlm_request → NemotronOmniInferenceWrapper._forward_vision_encoder → NemotronOmniModel._encode_images

Here media_tokens_preexpanded=True, because NeMo-RL already expanded the image placeholders.

Gym RL Multimodal Data Pipeline

Dataset-side preprocessing for training/recompute:

nemo_gym_data_processor → nemo_gym_example_to_video_datum_spec → load_video_frames_with_metadata → process_nemotron_video_frames → _expand_nemotron_video_placeholders → produces PackedTensor(pixel_values, imgs_sizes, num_frames)

Files:

nemo_rl/data/processors.py
nemo_rl/environments/nemo_gym_multimodal.py
nemo_rl/environments/nemotron_utils.py

Gym rollout generation:

AsyncNemoGymRolloutImpl → NemoGym.run_rollouts → normalize_media_in_examples → Gym RolloutCollectionHelper.run_examples → Gym agent → SimpleResponsesAPIModel.responses_dispatch → Megatron OpenAI HTTP server

Files:

nemo_rl/experience/rollout_manager.py
nemo_rl/environments/nemo_gym.py
3rdparty/Gym-workspace/Gym/nemo_gym/rollout_collection.py
3rdparty/Gym-workspace/Gym/nemo_gym/base_responses_api_model.py

HTTP-side preprocessing for generation:

chat_completions → _extract_multimodal_from_messages → raw image/video bytes → resolve_multimodal_data_for_engine → preprocess_video_bytes_list → DynamicInferenceEngine._build_vlm_request → NemotronOmniInferenceWrapper.expand_image_tokens → _forward_vision_encoder → NemotronOmniModel._encode_images

Files:

Megatron-LM/.../endpoints/chat_completions.py
Megatron-LM/.../image_preprocessing.py
Megatron-LM/.../dynamic_engine.py
Megatron-LM/.../nemotron_omni_inference_wrapper.py

Here media_tokens_preexpanded=False; Megatron-LM expands placeholders itself.

After Gym returns:

NemoGym._postprocess_nemo_gym_to_nemo_rl_result → attach generated token IDs/logprobs → attach_static_multimodal_payload → restore the original NeMo-RL PackedTensors for policy recompute and training.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the unit tests and functional tests locally? Visit our Testing Guide for how to run tests
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

Additional Information

  • ...

@copy-pr-bot

copy-pr-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cspades cspades self-assigned this Aug 25, 2026
@cspades cspades changed the title feat(multimodal-mllm): Support multimodal (image and video) Megatron Inference in NeMo-RL. feat(multimodal): Support multimodal Megatron generation. Aug 26, 2026
@cspades
cspades force-pushed the cye/rl_mllm_omni_multimodal branch from 4d076b5 to 63f916f Compare August 26, 2026 00:27
@cspades

cspades commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 63f916f

@cspades cspades added CI:L1 Run doctests, unit tests, and functional tests enhancement New feature or request inference Inference Related labels Aug 26, 2026
@cspades
cspades requested a review from a team as a code owner August 26, 2026 21:04
@cspades
cspades force-pushed the cye/rl_mllm_omni_multimodal branch 3 times, most recently from 4857079 to 63c67a0 Compare August 26, 2026 23:01
@cspades

cspades commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

Lockfile test is not gonna be fixed until we bump MBridge and MCore. 😩

@copy-pr-bot

copy-pr-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cspades
cspades requested a review from a team as a code owner August 30, 2026 20:49
@copy-pr-bot

copy-pr-bot Bot commented Aug 30, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Aug 30, 2026
@github-actions

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: 1f8c19a (PR #3834 from cye/rl_mllm_omni_multimodal)

✅ Submodules that are properly updated:

Megatron-Bridge: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

@cspades
cspades force-pushed the cye/rl_mllm_omni_multimodal branch from 1f8c19a to 2c45b7b Compare August 30, 2026 21:04
@github-actions

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: 2c45b7b (PR #3834 from cye/rl_mllm_omni_multimodal)

✅ Submodules that are properly updated:

Megatron-Bridge: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

kajalj22 and others added 13 commits August 30, 2026 14:07
Bumps the Megatron-Bridge submodule (nesting Megatron-LM at 7c9c3a027,
which pins [email protected]) and RL's own constraint-dependencies
pin to match, per <NVIDIA/Megatron-LM#6701>.

The automated mbridge-bump pipeline (nemo-ci) could not do this on its
own: it bumps only the submodule, not RL's root pin, so uv lock failed
with a conflicting-URL error until both moved together in one commit.

Signed-off-by: Kajal Jain <[email protected]>
Keep main's deduplicated, atomic media encoding behavior in the multimodal module where the branch moved Gym normalization.

Signed-off-by: Cory Ye <[email protected]>
Use the full media model for the inference context while retaining the nested language model for hybrid state and lifecycle operations.

Signed-off-by: Cory Ye <[email protected]>
Signed-off-by: Cory Ye <[email protected]>
…reate a new wrapper for a new config.

Signed-off-by: Cory Ye <[email protected]>
Signed-off-by: Cory Ye <[email protected]>
@cspades
cspades force-pushed the cye/rl_mllm_omni_multimodal branch from 2c45b7b to 9f47b0a Compare August 30, 2026 21:07
@github-actions

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: 9f47b0a (PR #3834 from cye/rl_mllm_omni_multimodal)

✅ Submodules that are properly updated:

Megatron-Bridge: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

@github-actions

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: 7ef4ec3 (PR #3834 from cye/rl_mllm_omni_multimodal)

✅ Submodules that are properly updated:

Megatron-Bridge: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

@cspades

cspades commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 7ef4ec3

@cspades

cspades commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Migrating to NRL local branches.

@cspades cspades closed this Aug 31, 2026
@github-actions

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: 1092610 (PR #3834 from cye/rl_mllm_omni_multimodal)

✅ Submodules that are properly updated:

Megatron-Bridge: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

@cspades

cspades commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Moved to: #3920

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L1 Run doctests, unit tests, and functional tests Documentation Improvements or additions to documentation enhancement New feature or request inference Inference Related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants