Skip to content

feat(video): support video inputs in vLLM responses - #2324

Merged
ananthsub merged 2 commits into
NVIDIA-NeMo:mainfrom
ehosseiniasl:ehsan/video-rl-gym-async-grpo
Aug 19, 2026
Merged

ananthsub merged 2 commits into
NVIDIA-NeMo:mainfrom
ehosseiniasl:ehsan/video-rl-gym-async-grpo

Conversation

@ehosseiniasl

@ehosseiniasl ehosseiniasl commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add video-input support to the NeMo Gym Responses API and vLLM model backend for multimodal RL training.

  • Accept input_video and video_url content parts.
  • Convert Responses API video inputs into vLLM-compatible chat content.
  • Reject video parts that do not contain a valid URL.
  • Prefer prompt and generation token IDs returned by the generation request.
  • Preserve multimodal processor arguments when falling back to the tokenize endpoint.
  • Validate that generation token IDs and log probabilities have matching lengths.
  • Propagate token IDs, log probabilities, and optional training metadata through Gym responses.
  • Ensure component processes load their owning Gym checkout instead of a stale container installation.

Motivation

Video GRPO requires Gym to preserve video content and the exact prompt and generation tokenization used by vLLM.

Using token IDs produced by a separate or differently configured tokenization request can cause rollout and policy log probabilities to reference different token sequences, resulting in
incorrect training data and elevated TMPE.

Validation

  • Added coverage for input_video and video_url conversion.
  • Added coverage for missing video URLs.
  • Added coverage for native vLLM prompt and generation token IDs.
  • Added coverage for the tokenize fallback and multimodal processor arguments.
  • Added coverage for token-ID and log-probability propagation.
  • Added coverage ensuring component processes prefer the owning Gym checkout.
  • Exercised through downstream synchronous and asynchronous NeMo RL video GRPO training.

Dependencies

None.

Related integrations

@copy-pr-bot

copy-pr-bot Bot commented Aug 4, 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.

@ananthsub ananthsub left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for adding the video path and native vLLM token IDs. This branch predates several Responses fixes on main, so it needs to be rebased while preserving the current schema and token-metadata implementations.

The main schema concern is the second content-list union:

flowchart LR
    subgraph PR["Current PR"]
        INPUT1["Responses content"] --> LISTS{"Choose a complete list type"}
        LISTS --> SDK["SDK list - text · image · file"]
        LISTS --> CUSTOM["Custom model list - text · image · video"]
        CUSTOM --> COERCE["Existing dictionaries become Pydantic models"]
        SDK --> MIX["Cannot mix input_file with video"]
    end

    subgraph TARGET["Recommended"]
        INPUT2["Responses content"] --> ITEMS["One item-level union"]
        ITEMS --> TEXT["SDK input_text"]
        ITEMS --> IMAGE["SDK input_image"]
        ITEMS --> FILE["SDK input_file"]
        ITEMS --> VIDEO["Gym input_video"]
        VIDEO --> VALIDATE["Validate exactly one URL"]
        VALIDATE --> CHAT["Convert to canonical video_url"]
    end
Loading

Video should extend one SDK item-level union rather than add another list type. This preserves the existing dictionary representation and allows standard parts such as input_file to coexist with video.

Token handling has two separate validation layers:

flowchart TD
    REQUEST["Generation request"] --> VLLM["vLLM response"]
    VLLM --> SOURCE{"Native prompt and generation IDs present?"}

    SOURCE -->|Both| NATIVE["Use complete native bundle"]
    SOURCE -->|Neither| FALLBACK["Compatibility fallback"]
    SOURCE -->|Only one| PARTIAL["Reject or use an explicit partial-response policy"]

    FALLBACK --> EQUIV{"Can /tokenize reproduce every prompt-affecting field?"}
    EQUIV -->|No| FAIL["Require native prompt IDs"]
    EQUIV -->|Yes| TOKENIZE["Tokenize with all shared fields"]

    NATIVE --> ADAPTER["vLLM adapter validation source policy and lengths"]
    TOKENIZE --> ADAPTER

    ADAPTER --> MAIN["Existing main validation from #2488 required fields are atomic, types are valid, empty arrays remain valid"]
    MAIN --> TRAINING["Training message"]
    TRAINING --> RESET["Clear metadata after the turn"]
Loading

#2488 now provides bundle validation and per-turn state clearing. The generic token-metadata propagation logic in this PR should be dropped during the rebase.

The generation ID and log-probability length check added here is provider-level validation and should remain with the vLLM token change. The remaining adapter cases are:

  • partial native prompt/generation ID responses;
  • prompt-affecting fields omitted from /tokenize;
  • invalid token-source configuration.

It would be helpful to split the remaining work into separate PRs:

  • Responses and Chat video schemas together with video conversion.
  • vLLM native token IDs, fallback tokenization, and provider-level validation.
  • CLI PYTHONPATH precedence.

Comment thread nemo_gym/openai_utils.py Resolved
Comment thread nemo_gym/openai_utils.py Resolved
Comment thread nemo_gym/openai_utils.py Resolved
Comment thread nemo_gym/openai_utils.py Resolved
Comment thread nemo_gym/responses_converter.py Resolved
Comment thread responses_api_models/vllm_model/app.py Resolved
Comment thread responses_api_models/vllm_model/app.py Resolved
Comment thread responses_api_models/vllm_model/app.py Resolved
Comment thread nemo_gym/cli/env.py Resolved
@ehosseiniasl
ehosseiniasl force-pushed the ehsan/video-rl-gym-async-grpo branch from e9fd77c to d31df71 Compare August 14, 2026 16:19
@ananthsub ananthsub removed the sla:review-overdue Review response is over the one-business-day SLA label Aug 14, 2026
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Aug 14, 2026
@ehosseiniasl

ehosseiniasl commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor Author

@ananthsub Thanks for the detailed review. I addressed all your comments in 5b8f04b:

  • Added video support to the Responses API item-level SDK union.
  • Enforced exactly one non-empty video source.
  • Normalized video conversion to canonical video_url content.
  • Made native prompt/generation token handling atomic and validated token lengths.
  • Completed the /tokenize fallback and made unsupported fields fail clearly.
  • Removed unrelated generic propagation changes.
  • Reverted the RunHelper project_root/import-precedence change and its test. nemo_gym/cli/env.py is no longer changed by this PR.
  • Added regression coverage for the reviewed cases.

All 15 Gym CI checks are green. Could you please take another look?

ananthsub added a commit that referenced this pull request Aug 18, 2026
#1558)

## Summary

- Consume a complete token bundle from `choice.message` without making a
second `/tokenize` request.
- Support opt-in vLLM response token IDs for endpoints that return
top-level `prompt_token_ids` and choice-level `token_ids`.
- Retain `/tokenize` for integrations that return neither inline
representation.
- Reject partial or conflicting sources. Token capture supports one
completion choice per request (`n` omitted or set to `1`).

## Why

Gym needs the prompt token IDs, generated token IDs, and selected-token
log probabilities used during generation. The previous adapter
reconstructed prompt IDs through a second awaited `/tokenize` request.
That request adds inter-turn latency and can reproduce a different
prompt when prompt-affecting inputs are omitted.

NeMo RL [#3390](NVIDIA-NeMo/RL#3390) attaches
the token bundle to the assistant message. Gym reads that bundle
directly and does not request duplicate response-level IDs by default.

Gym cannot require that message shape from every training integration.
Other integrations, including Verl, can request vLLM's response token
IDs or continue using the compatibility fallback.

## Source precedence

1. A complete token bundle on `choice.message`.
2. Top-level `prompt_token_ids`, choice-level `token_ids`, and
`choice.logprobs` from the vLLM response.
3. Generation metadata from `choice.logprobs` and prompt IDs from
`/tokenize`.

`request_prompt_and_generation_token_ids: true` enables the second
source by sending `return_token_ids=true` to compatible vLLM endpoints.
The option defaults to `false`. If both inline sources are present,
their token IDs must agree. The selected training message is validated
once to avoid repeated list scans and copies at long sequence lengths.

The fallback forwards `model`, `messages`, `tools`,
`chat_template_kwargs`, `mm_processor_kwargs`, and
`required_prefix_token_ids`. This keeps fallback tokenization aligned
with the generation prompt.

`prompt_logprobs` is not requested. vLLM returns prompt IDs
independently when `return_token_ids` is enabled, and Gym does not
consume prompt-token log probabilities.

## Related work

- Gym [#700](#700) is superseded
by this change.
- Gym [#2576](#2576) is
superseded by this change.
- NeMo RL [#3390](NVIDIA-NeMo/RL#3390) produces
the message-level token bundle consumed by the first source.
- NeMo RL [#3581](NVIDIA-NeMo/RL#3581) reuses
replayed token metadata across turns.
- Gym [#1784](#1784) can add the
Dynamo `nvext.engine_data` source independently.
- Gym [#2324](#2324) can retain
its video-specific schema, conversion, and adapter behavior
independently.

---------

Signed-off-by: Ananth Subramaniam <[email protected]>
Comment thread responses_api_models/vllm_model/app.py Resolved
@ehosseiniasl
ehosseiniasl force-pushed the ehsan/video-rl-gym-async-grpo branch from 5b8f04b to dc23f91 Compare August 18, 2026 23:48
@ehosseiniasl

ehosseiniasl commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor Author

@ananthsub Rebased this PR onto the latest upstream main after #1558 merged. I removed the duplicated inline token-metadata and /tokenize fallback changes, so this PR is now limited to video schema support, canonical video conversion, and focused regression tests.

Local validation passed: 216 focused unit tests plus Ruff checks. All CI checks passed on dc23f911. Could you please take another look?

@ananthsub
ananthsub force-pushed the ehsan/video-rl-gym-async-grpo branch from dc23f91 to 890b30a Compare August 19, 2026 00:16
@ananthsub
ananthsub enabled auto-merge (squash) August 19, 2026 00:17
@ananthsub
ananthsub merged commit c3bac96 into NVIDIA-NeMo:main Aug 19, 2026
14 checks passed
ehosseiniasl added a commit to NVIDIA-NeMo/RL that referenced this pull request Aug 19, 2026
Address all actionable review comments for PR #3648.

- centralize image, video, and audio content aliases across preprocessing
- validate cached frames as one video source and normalize local image aliases
- align Nemotron Omni tubelet placeholders and timestamps with vLLM metadata
- materialize one strict frame-sampling contract for rollout and policy paths
- reattach deduplicated media to sync and async Gym message logs consistently
- remove obsolete optional-epoch handling from SingleController step clamping
- document video runtime, cache, epoch, and raw-TMPE contracts
- add focused config, media, vLLM, and executable 2n/16n regression coverage
- pin Gym to merged video Responses API integration NVIDIA-NeMo/Gym#2324

Signed-off-by: Ehsan Hosseini Asl <[email protected]>
ehosseiniasl added a commit to NVIDIA-NeMo/RL that referenced this pull request Aug 19, 2026
Address all actionable review comments for PR #3648.

- centralize image, video, and audio content aliases across preprocessing
- validate cached frames as one video source and normalize local image aliases
- align Nemotron Omni tubelet placeholders and timestamps with vLLM metadata
- materialize one strict frame-sampling contract for rollout and policy paths
- keep cached-frame policy timestamps identical to the vLLM synthetic timeline
- reattach deduplicated media to sync and async Gym message logs consistently
- remove obsolete optional-epoch handling from SingleController step clamping
- document video runtime, cache, epoch, and raw-TMPE contracts
- add focused config, media, vLLM, and executable 2n/16n regression coverage
- pin Gym to merged video Responses API integration NVIDIA-NeMo/Gym#2324

Signed-off-by: Ehsan Hosseini Asl <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants