Skip to content

feat(data): add PackedTensor preprocessing modes - #4106

Merged
terrykong merged 4 commits into
mainfrom
rohit/packedtensor_padding
Sep 18, 2026
Merged

terrykong merged 4 commits into
mainfrom
rohit/packedtensor_padding

Conversation

@rohitrango

Copy link
Copy Markdown
Contributor

What does this PR do ?

Adds configurable PackedTensor preprocessing and patchifies Nemotron Omni pixels before materialization.

  • Replaces the top-level pad_to_max_shape boolean with preprocess_mode and preprocess_kwargs.
  • Adds native-resolution patchification into per-image (C_i, P²) blocks, packs them on dimension 0, and returns (1, total_C, P²).
  • Carries preprocessing settings through slicing, concatenation, wire transport, and materialization.
  • Enables patchification with patch size 16 for supported Nemotron Omni processors.
  • Adds NemotronH_Omni_Reasoning_V3Processor to the placeholder-style processor set.

Issues

None.

Usage

PackedTensor(
    pixel_values,
    dim_to_pack=0,
    preprocess_mode="patchify",
    preprocess_kwargs={"patch_dim": 16},
)

Before your PR is "Ready for review"

  • Read and followed the contributor guidelines.
  • Added or updated unit coverage for preprocessing and patchification.
  • Full pre-commit lint suite passed on Slurm job 18281365 (Ruff lint, import sorting, Ruff format, Pyrefly, and config checks).
  • Affected unit suite passed on Slurm job 18281365: 90 passed, 1 skipped (megatron.bridge unavailable).
  • GRPO and SFT GPU recipe validation passed on Slurm job 18281365.
  • Updated relevant inline documentation.

Additional Information

Scripts validated

uv run examples/run_vlm_grpo.py --config examples/configs/recipes/vlm/vlm_grpo-nemotron-omni-30ba3b-clevr-2n8g-megatron-tp8ep8.v1-tq_mooncake.yaml logger.wandb.name=grpo-nemotron-with-patches logger.wandb_enabled=true logger.wandb.project=sft-dev cluster.num_nodes=1

image
uv run examples/run_sft_v2.py --config examples/configs/recipes/vlm/vlm_sft-nemotron-omni-30ba3b-clevr-1n8g-megatron-tp8ep8-energon.v1.packing.yaml logger.wandb.name=sft-nemotron-with-patches logger.wandb_enabled=true logger.wandb.project=sft-dev sft.max_steps=50

(brown: baseline, green: with patches)
image

Previous PR and self-review

Previous PR: #4082. A self-review was performed on the previous PR, and the resulting feedback was addressed in this PR.

@copy-pr-bot

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

@rohitrango
rohitrango added this pull request to stack #4109 September 12, 2026 00:15
@rohitrango
rohitrango marked this pull request as ready for review September 12, 2026 00:15
@rohitrango
rohitrango requested review from a team as code owners September 12, 2026 00:15
@copy-pr-bot

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

@rohitrango
rohitrango force-pushed the rohit/packedtensor_padding branch from 977f0f3 to 3b6df1a Compare September 15, 2026 17:57
@rohitrango
rohitrango requested review from a team as code owners September 16, 2026 19:18

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This PR moves Nemotron Omni pixel_values from pad-to-max-shape to patchify, so each image is cut into vision patches at its native resolution and packed into one sequence instead of being padded up to the largest image in the batch. It adds preprocess_mode / preprocess_kwargs to PackedTensor, a _patchify_segments helper, and a get_preprocess policy function that picks the mode per processor and per field.

The patchify layout is not invented here — it's what Bridge's own Nemotron Omni SFT collate produces (collate_fn.py L342-L346), and the per-frame kernel does the same reshape/permute (nemotron_omni_utils.py L63-L67). Three lanes checked independently that _patchify_segments is bit-for-bit identical to Bridge's _patchify_dynamic_images on mixed-resolution input. _preprocess_spec is also a genuinely good call: it replaces what would otherwise be ten hand-written copies of the same keyword pair across every copy/slice/concat path, and an audit of all of them found none missed.

The one blocking problem is that get_preprocess decides patchify from the processor alone, with no idea which backend will read the result. Megatron takes pre-patchified input by design; the AutoModel/DTensor forward takes 4-D only, so two nightly VLM lanes now hit an unpack error raised inside HuggingFace code — details in the inline comment on get_preprocess.

One note on the description: it says a self-review on the previous PR (#4082) "was addressed in this PR", but the change this PR contributes is identical to #4082's — every added and removed line matches across all 10 files, with only hunk offsets moved by the rebase — so no code changed as a result. If that review happened somewhere off GitHub, could you link it? A pending review would be invisible to us, so I can't tell from here whether one exists.

FYI, for a later PR and not this one: the next PR up the stack calls PackedTensor(..., pad_to_max_shape=True) in nemo_rl/data/energon/multimodal/task_encoders/nemotron_multimodal.py while carrying this PR's __init__, which takes no such keyword and no **kwargs — that'll raise TypeError once this lands.

Reviewed by a team of agents.

Generated by Claude Code

Comment thread nemo_rl/data/multimodal_utils.py
Comment thread nemo_rl/data/multimodal_utils.py Outdated
Comment thread nemo_rl/data/multimodal_utils.py
Comment thread nemo_rl/data/multimodal_utils.py
Comment thread nemo_rl/data/processors.py Outdated
Comment thread nemo_rl/data/multimodal_utils.py Outdated
Comment thread nemo_rl/data/multimodal_utils.py Outdated
Comment thread tests/unit/data/test_multimodal_dict.py
Comment thread nemo_rl/data/multimodal_utils.py Outdated
Comment thread nemo_rl/data/multimodal_utils.py Outdated
@rohitrango
rohitrango force-pushed the rohit/packedtensor_padding branch from 3b6df1a to 5fbf187 Compare September 17, 2026 03:15
@rohitrango
rohitrango force-pushed the rohit/packedtensor_padding branch from 5fbf187 to 2fc6596 Compare September 17, 2026 19:28
@rohitrango
rohitrango requested review from a team as code owners September 17, 2026 19:28
@rohitrango

Copy link
Copy Markdown
Contributor Author

Validated end to end:

uv run examples/run_vlm_grpo.py --config examples/configs/recipes/vlm/vlm_grpo-nemotron-omni-30ba3b-clevr-1n8g-megatron-tp8ep8.v1.yaml
uv run examples/run_vlm_grpo.py --config examples/configs/recipes/vlm/vlm_grpo-nemotron-omni-30ba3b-clevr-1n8g-automodel-ep8.v2.yaml

@rohitrango

Copy link
Copy Markdown
Contributor Author

/ok to test 2fc6596

Base automatically changed from rohit/sft_v2_stage2 to main September 18, 2026 00:39
@terrykong
terrykong force-pushed the rohit/packedtensor_padding branch from 2fc6596 to 972e9f4 Compare September 18, 2026 00:39
@copy-pr-bot

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

@rohitrango rohitrango added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Sep 18, 2026
@terrykong

Copy link
Copy Markdown
Collaborator

/ok to test 972e9f4

terrykong
terrykong previously approved these changes Sep 18, 2026
@rohitrango
rohitrango force-pushed the rohit/packedtensor_padding branch from 972e9f4 to 1cba512 Compare September 18, 2026 18:53
@rohitrango

Copy link
Copy Markdown
Contributor Author

/ok to test 1cba512

Signed-off-by: rohitrango <rohit.rango@gmail.com>
Signed-off-by: rohitrango <rohit.rango@gmail.com>
Signed-off-by: rohitrango <rohit.rango@gmail.com>
Signed-off-by: rohitrango <rohit.rango@gmail.com>
@rohitrango

Copy link
Copy Markdown
Contributor Author

/ok to test 30821cc

@terrykong
terrykong merged commit a684560 into main Sep 18, 2026
95 checks passed
@terrykong
terrykong deleted the rohit/packedtensor_padding branch September 18, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants