Skip to content

Add multimodal vision token utilities - #7249

Merged
tylerpoon merged 5 commits into
NVIDIA:mainfrom
tylerpoon:tpoon/github-vlm-sft-02-vision-token-utilities
Sep 14, 2026
Merged

tylerpoon merged 5 commits into
NVIDIA:mainfrom
tylerpoon:tpoon/github-vlm-sft-02-vision-token-utilities

Conversation

@tylerpoon

@tylerpoon tylerpoon commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do?

Add image patchify/unpatchify helpers and consistent vision-token accounting for temporal patches, attention pooling, class tokens, and tile tags. Include round-trip and video accounting tests.

This is part of a review-split multimodal SFT series. Production run scripts, data YAMLs, checkpoint conversion tooling, and separate CI compatibility fixes are outside this series.

Dependencies and review scope

Targets main.

Validation

  • Replayed onto public main at 46fb90ca942a2950c58c5654b3e56877e88a3e35, preserving atomic signed and signed-off commits.
  • The original combined feature stack had multi-node Super SFT validation before this migration; that is not an isolated-PR or rebased-head test result.
  • GitHub CI is pending. No GPU tests have been rerun locally for these rebased heads.
  • Local Black, isort, pylint, and Ruff checks passed for paths covered by the repository autoformat script (megatron/core and tests). Mypy is unavailable locally. Changed Python files pass syntax parsing; no CI configuration changes are included.

Kept as a draft pending CI and dependency integration.

Signed-off-by: Tyler Poon <tpoon@nvidia.com>
Signed-off-by: Tyler Poon <tpoon@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Sep 11, 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.

@tylerpoon

Copy link
Copy Markdown
Contributor Author

/ok to test c806aa7


def test_get_num_video_embeddings_applies_temporal_and_attention_pooling():
assert (
get_num_video_embeddings(

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.

could you add a test for the image case get_num_image_embeddings

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Sep 14, 2026
Signed-off-by: Tyler Poon <tpoon@nvidia.com>
@tylerpoon
tylerpoon requested a review from a team September 14, 2026 16:12
@tylerpoon
tylerpoon enabled auto-merge September 14, 2026 16:23
@tylerpoon
tylerpoon added this pull request to the merge queue Sep 14, 2026
@nemo-automation-bot

Copy link
Copy Markdown

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/34874783688

Merged via the queue into NVIDIA:main with commit c4997e3 Sep 14, 2026
4 checks passed
@tylerpoon
tylerpoon deleted the tpoon/github-vlm-sft-02-vision-token-utilities branch September 14, 2026 17:27
lauradang added a commit to tdene/Megatron-LM that referenced this pull request Sep 14, 2026
einops is only declared in the dev extra, so the unconditional
top-level import added in NVIDIA#7249 breaks the check-imports CI step for
plain pip installs of megatron.core. Wrap the import in a try/except
and assert availability inside patchify_image/unpatchify_image,
matching the pattern used by the Megatron FSDP adapter.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Laura Dang <laurad@nvidia.com>
@lauradang lauradang mentioned this pull request Sep 14, 2026
1 of 6 tasks
balasaajay added a commit to balasaajay/Megatron-LM that referenced this pull request Sep 15, 2026
This reverts commit c4997e3.

Signed-off-by: Ajay Balasa <abalasa@nvidia.com>
nemo-autobot-origin Bot pushed a commit to svcnemo-autobot/Megatron-LM that referenced this pull request Sep 15, 2026
The re-applied multimodal vision token utilities (NVIDIA#7249) import einops at
module scope. einops is an optional dependency that is absent from the
minimal environment used by the 'Pip - NGC PyTorch' import check, so
importing megatron.core.models.multimodal.utils raised ModuleNotFoundError.

Guard the import the same way the rest of megatron/core does (e.g.
transformer/attention.py): fall back to rearrange = None so the module
imports cleanly; the symbol is only exercised when the patchify helpers
actually run, where einops is installed.

Signed-off-by: svcnemo-autobot <svcnemo-autobot@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

complexity: medium Final Review PR is in the "final review" stage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants