Repository navigation
Add support for Nemotron Omni - #46509
Conversation
… related token fields explicitly in NemotronH_Nano_Omni_Reasoning_V3_Config
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
@ArthurZucker This PR is ready to be merged. Could we start the reviewing process? |
|
Yes sorry went off this week |
| pass | ||
|
|
||
|
|
||
| class EfficientVideoSampling: |
There was a problem hiding this comment.
this needs the model prefixing
There was a problem hiding this comment.
also if its just for a func not sure we need a clas?
There was a problem hiding this comment.
keep only func here
| parakeet_config = AutoConfig.for_model("parakeet_encoder", **config_dict) | ||
| self.config = parakeet_config | ||
| self.encoder = AutoModel.from_config(parakeet_config) |
There was a problem hiding this comment.
the config should just have a config saved. and at this point you create a wrapper around something that should just be used directly this is too many layers
There was a problem hiding this comment.
Directly use ParakeetEncoderConfig now
| return x | ||
|
|
||
| def extract_feature(self, pixel_values): | ||
| if isinstance(pixel_values, (list, tuple)): |
There was a problem hiding this comment.
the whole pixel shuffle exists in other models, it should be isolated as this shows it does not belong here. Isolated and done with the mlp1
There was a problem hiding this comment.
Isolate in NemotronH_Omni_Reasoning_V3VisionProjector now
| orig_projection = embeddings.patch_projection | ||
| embeddings.patch_projection = embeddings.video_patch_projection | ||
| try: | ||
| vit_embeds = self.vision_model(x).features |
There was a problem hiding this comment.
that is not super idea no? why do we have to do try catch it should be predictable
There was a problem hiding this comment.
video_patch_projection moved to inside Radio instead of replace patch_projection now.
| if image_vit_embeds is not None: | ||
| image_mask = input_ids_copy == self.img_context_token_id | ||
| assert image_mask.sum() != 0, "No image tokens found in input_ids" | ||
| inputs_embeds[image_mask] = image_vit_embeds.reshape(-1, C).to( | ||
| inputs_embeds.device, inputs_embeds.dtype | ||
| ) | ||
|
|
||
| if video_vit_embeds is not None: | ||
| if B > 1: | ||
| raise NotImplementedError("Video is not supported for batch size > 1") | ||
| video_mask = input_ids_copy == self.img_context_token_id | ||
| assert video_mask.sum() != 0, "No video tokens found in input_ids" | ||
| inputs_embeds[video_mask] = video_vit_embeds.reshape(-1, C).to( | ||
| inputs_embeds.device, inputs_embeds.dtype | ||
| ) | ||
|
|
||
| if sound_embeds is not None and self.sound_context_token_id is not None: | ||
| sound_mask = input_ids_copy == self.sound_context_token_id | ||
| assert sound_mask.sum() != 0, "No sound tokens found in input_ids" | ||
| if sound_embeds.dim() == 3 and sound_embeds.shape[0] > 1 and sound_attention_mask is not None: | ||
| natural_input_lengths = sound_attention_mask.sum(-1) + 1 | ||
| output_lengths = self.sound_encoder.encoder._get_subsampling_output_length(natural_input_lengths) | ||
| flat = torch.cat( | ||
| [sound_embeds[i, : int(n)] for i, n in enumerate(output_lengths.tolist())], | ||
| dim=0, | ||
| ) | ||
| else: | ||
| flat = sound_embeds.reshape(-1, C) | ||
| assert sound_mask.sum().item() == flat.shape[0], ( | ||
| f"sound token count ({sound_mask.sum().item()}) != encoder output count ({flat.shape[0]})" | ||
| ) | ||
| inputs_embeds[sound_mask] = flat.to(inputs_embeds.device, inputs_embeds.dtype) |
There was a problem hiding this comment.
you should take inspiration from other models on how we usally do this specific part! an example can be found in
There was a problem hiding this comment.
Follow Qwen3OmniMoe for generate path now
| def extract_sound_feature( | ||
| self, | ||
| input_features: torch.Tensor, | ||
| attention_mask: torch.Tensor | None = None, | ||
| ) -> torch.Tensor: | ||
| if self.sound_encoder is None: | ||
| raise RuntimeError("Sound encoder not initialized. Check if sound_config is provided.") | ||
| sound_embeds = self.sound_encoder(input_features, attention_mask) | ||
| sound_embeds = sound_embeds.to(dtype=torch.bfloat16) | ||
| sound_embeds = self.sound_projection(sound_embeds) | ||
| return sound_embeds | ||
|
|
There was a problem hiding this comment.
why not isolate this as audioProjector and have a single forward for it?
There was a problem hiding this comment.
Isolate as NemotronH_Omni_Reasoning_V3SoundProjector now
ArthurZucker
left a comment
There was a problem hiding this comment.
dropping the first review! as always we need to standardize cf the other omni models!
| from transformers import NemotronH_Omni_Reasoning_V3 | ||
|
|
||
|
|
||
| class NemotronHOmniModelTester: |
There was a problem hiding this comment.
you can probably inherit from causal LM tester?
There was a problem hiding this comment.
see other omni models and which class they inherit from!
There was a problem hiding this comment.
Inherit GenerationTesterMixin now
Added if-else in init now. |
|
@ArthurZucker The PR is ready. Could we merge this PR if there is no other concern? |
|
cc @VI-Arthur |
| # NemotronH Omni | ||
|
|
||
| NemotronH Omni is a multimodal reasoning model from NVIDIA that pairs the [NemotronH](./nemotron_h) hybrid | ||
| Mamba-Transformer language model with a [RADIO](./radio) vision encoder and an optional Parakeet-based sound encoder. |
There was a problem hiding this comment.
| Mamba-Transformer language model with a [RADIO](./radio) vision encoder and an optional Parakeet-based sound encoder. | |
| Mamba-Transformer language model with a [RADIO](./radio) vision encoder and an Parakeet-based sound encoder. |
nit but it sounds a bit off with the optional. I'd assume for omni == always all modalities no?
There was a problem hiding this comment.
We will reuse model class for the model without audio encoder
|
@vasqu The comments are resolved. Could you review them again? Thanks |
ArthurZucker
left a comment
There was a problem hiding this comment.
Let's go! Thanks for you efforts and bearing with us.
Omni models are very hard in general, the hardest to standardize. 🤗
|
[For maintainers] Suggested jobs to run (before merge) run-slow: auto, nemotron_h, nemotron_h_omni, radio |
|
run-slow: auto, nemotron_h, nemotron_h_omni, radio |
AMD CIThis comment contains models: ["models/auto", "models/nemotron_h", "models/nemotron_h_omni", "models/radio"] |
Nvidia CIThis comment contains models: ["models/auto", "models/nemotron_h", "models/nemotron_h_omni", "models/radio"] |
CI recapDashboard: View test results in Grafana |
CI Results (AMD)Commit Info
Model CI Report❌ 10 new failed tests from this PR 😭
|
CI Results (Nvidia)Commit Info
Model CI Report❌ 21 new failed tests from this PR 😭
|
|
I’ll check the failures and fixe but it’s ready to merge otherwise ! |
|
OK! |
What does this PR do?
Add NVIDIA Nemotron Omni support (This PR depends on radio PR #46425 )
Code Agent Policy
The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. We are currently bottlenecked by our ability to review and respond to them. As a result,
we ask that new users do not submit pure code agent PRs at this time.
You may use code agents in drafting or to help you diagnose issues. We'd also ask autonomous "OpenClaw"-like agents
not to open any PRs or issues for the moment.
PRs that appear to be fully agent-written will probably be closed without review, and we may block users who do this
repeatedly or maliciously.
This is a rapidly-evolving situation that's causing significant shockwaves in the open-source community. As a result,
this policy is likely to be updated regularly in the near future. For more information, please read
CONTRIBUTING.md.Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.