Skip to content

feat(mtp): enable MTP to accept pre-fused input embeddings for multimodal models - #2510

Merged
adil-a merged 3 commits into
NVIDIA-NeMo:mainfrom
Slyne:slyne/salm_mtp
Jun 16, 2026
Merged

adil-a merged 3 commits into
NVIDIA-NeMo:mainfrom
Slyne:slyne/salm_mtp

Conversation

@Slyne

@Slyne Slyne commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

What does this PR do ?

In multimodal LLM training (e.g., SALM), audio/vision positions in the input sequence carry continuous features from a perception encoder that cannot be recovered by re-embedding an integer token id. The existing MTP path assumes all positions have a corresponding token id and uses embed_fn(rolled_input_ids) to produce the future-token signal — this yields embed_fn(padding_id) at every audio position, which is wrong.

This PR adds a second input mode to the MTP forward path: when pre-fused input embeddings are available (e.g., the fused audio+text tensor in SALM), the caller pre-rolls them per depth and passes them as embed_inputs, bypassing embed_fn entirely. Audio positions then carry the correct audio embedding as their future-token signal. The existing input_ids + embed_fn path is unchanged for pure-text models.

Changelog

  • nemo_automodel/components/models/common/mtp/mtp.py: Updated embed_inputs docstring to document the multimodal use case alongside the existing PP use case.
  • nemo_automodel/components/models/nemotron_v3/model.py: In NemotronHForCausalLM.forward(), when inputs_embeds is provided and no PP embeddings are present, pre-roll inputs_embeds per MTP depth and pass as embed_inputs, bypassing embed_fn for audio/vision positions.
  • tests/unit_tests/models/nemotron_v3/test_nemotron_v3_mtp.py: Added TestMTPInputEmbeds with three tests — embed_inputs path delivers the correct tensor to the fusion sublayer, embed_fn path is unchanged when embed_inputs is absent, and end-to-end model forward produces different mtp_per_depth_h when inputs_embeds differs from embed_tokens(input_ids).

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 add or update any necessary documentation?

Additional Information

This fix is required for SALM (Speech and Language Model) training in NeMo, where the input sequence interleaves text tokens and audio frame embeddings. The NeMo-side change (pre-rolling inputs_embeds before calling the LLM) will be submitted in a separate NeMo PR that depends on this one.

Signed-off-by: SlyneD <slyned@nvidia.com>
@Slyne
Slyne requested a review from a team as a code owner June 10, 2026 18:57
@copy-pr-bot

copy-pr-bot Bot commented Jun 10, 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.

@Slyne Slyne changed the title enable nemotron mtp to accept embedding input feat(mtp): enable MTP to accept pre-fused input embeddings for multimodal models Jun 10, 2026
@akoumpa

akoumpa commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

/ok to test d78fb9a

Signed-off-by: SlyneD <slyned@nvidia.com>
@akoumpa

akoumpa commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

/ok to test fff5d7e

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-customer Waiting on the original author to respond waiting-on-maintainers Waiting on maintainers to respond labels Jun 12, 2026
@akoumpa

akoumpa commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Thank you for the contribution @Slyne ! ,

@adil-a can you review?

Thank you

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Jun 16, 2026
Comment thread nemo_automodel/components/models/nemotron_v3/model.py
@adil-a

adil-a commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

/claude review

@claude claude Bot 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.

LGTM

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-customer Waiting on the original author to respond label Jun 16, 2026
@adil-a
adil-a merged commit cb1b378 into NVIDIA-NeMo:main Jun 16, 2026
67 checks passed
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Jun 16, 2026

This branch was previously deployed

3 inactive deployments
public — fff5d7e0 Deployed Jun 12, 2026 by copy-pr-bot[bot] via release / finalize / notify #1218
test — fff5d7e0 Deployed Jun 12, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #7459
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants