fix(nemotron-v3): support THD with input_embeds instead of input_ids#2185
Open
fix(nemotron-v3): support THD with input_embeds instead of input_ids#2185
input_embeds instead of input_ids#2185Conversation
`SALMAutomodel` and other multimodal callers feed the LLM through `inputs_embeds` (audio frames spliced into the token stream have no integer ID) and leave `input_ids=None`. Two bugs surfaced when running that path under `qkv_format="thd"`: 1. `squeeze_input_for_thd` did `input_ids.squeeze(0)` unconditionally and crashed with `AttributeError: 'NoneType' object has no attribute 'squeeze'`. Add the same `is-not-None` guard the helper already uses for `padding_mask`; document `None` as a valid value. 2. `NemotronHForCausalLM.forward` did `logits = logits.unsqueeze(0)` whenever `is_thd`, producing `[1, 1, T, V]` for the `inputs_embeds` path because `NemotronHModel.forward` already restores the batch dim (`squeezed_for_thd` branch). Restrict the outer unsqueeze to the case where the inner returned 2D logits; the standard `input_ids` path still satisfies that. Tests: - `TestSqueezeInputForThd` (5 cases) covers the helper-level contract: standard `input_ids` path, `input_ids=None` path, `padding_mask=None` composition, 3D `[1, T, H]` embedding-via-`input_ids` slot path, and `cu_seqlens_padded` filtering. - `TestNemotronHForCausalLM::test_causal_lm_thd_*` (2 cases) covers the outer logits-shape contract: `inputs_embeds`-only stays `[1, T, V]` (no double-unsqueeze), and `input_ids`-only still gets the batch dim re-added. The inner forward is stubbed via a tiny `nn.Module` because THD shapes only run end-to-end on TE/GPU. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Author
|
/ok to test 351806a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do ?
Support THD with
input_embedsinstead ofinput_ids.Previously, it errored out on THD because the utilities implicitly assumed input_ids cannot be
None.Changelog
input_embedsinstead ofinput_ids.Before your PR is "Ready for review"
Pre checks:
If you haven't finished some of the above items you can still open "Draft" PR.
Additional Information