Model

ankit/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-NVFP4

Blame for configuration_nemotron_h_omni.py at 951ba44

Line blame for configuration_nemotron_h_omni.py
LineCommitAuthorDateCode
1Add files using upload-large-folder toolbf6c919ankit# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14from huggingface_hub.dataclasses import strict
15from transformers.configuration_utils import PreTrainedConfig
16from transformers.models.nemotron_h import NemotronHConfig
17from transformers.models.parakeet.configuration_parakeet import ParakeetEncoderConfig
18from transformers.utils import auto_docstring, logging
19
20from .configuration_radio import RadioConfig
21
22
23__all__ = ["NemotronH_Omni_Reasoning_V3_Config"]
24
25logger = logging.get_logger(__name__)
26
27
28def _nemotron_h_compatible_config(config: dict) -> dict:
29 """Translate current Nemotron-H layer names for Transformers versions using legacy names."""
30 config = dict(config)
31 legacy_names = {"linear_attention": "mamba", "full_attention": "attention"}
32 for field in ("layers_block_type", "mtp_layers_block_type"):
33 if field in config and config[field] is not None:
34 config[field] = [legacy_names.get(layer_type, layer_type) for layer_type in config[field]]
35 return config
36
37
38@auto_docstring(checkpoint="nvidia/Nemotron-3-Nano-Omni-30B-A3B-Reasoning-BF16")
39@strict
40class NemotronH_Omni_Reasoning_V3_Config(PreTrainedConfig):
41 r"""
42 vision_config (`dict` or `RadioConfig`, *optional*):
43 Configuration for the RADIO vision encoder. Defaults to a default [`RadioConfig`].
44 llm_config (`dict` or `NemotronHConfig`, *optional*):
45 Configuration for the NemotronH language model. Defaults to a default [`NemotronHConfig`].
46 sound_config (`dict` or `ParakeetEncoderConfig`, *optional*):
47 Configuration for the optional Parakeet sound encoder. `None` disables the audio branch.
48 force_image_size (`int`, *optional*):
49 Fixed input image resolution (in pixels) the vision tower expects.
50 downsample_ratio (`float`, *optional*, defaults to 0.5):
51 Pixel-shuffle spatial downsample ratio applied to the vision features.
52 template (`str`, *optional*):
53 Conversation template name (legacy; the chat template is carried by the processor).
54 ps_version (`str`, *optional*, defaults to `"v1"`):
55 Pixel-shuffle implementation version (`"v2"` swaps height/width back; `"v1"` is the legacy
56 transposed variant).
57 image_tag_type (`str`, *optional*, defaults to `"internvl"`):
58 Image-tag convention used when expanding image placeholders.
59 projector_hidden_size (`int`, *optional*, defaults to 4096):
60 Hidden size of the vision-to-LLM MLP projector.
61 vit_hidden_size (`int`, *optional*, defaults to 1280):
62 Hidden size of the RADIO vision features.
63 video_pruning_rate (`float`, *optional*, defaults to 0.0):
64 Efficient-Video-Sampling token pruning rate; `0.0` disables pruning.
65 video_temporal_patch_size (`int`, *optional*, defaults to 2):
66 Number of frames collapsed into a single temporal patch by the video embedder.
67 patch_size (`int`, *optional*, defaults to 16):
68 Vision patch size in pixels.
69 img_context_token_id (`int`, *optional*):
70 Token id used as the image-context placeholder in `input_ids`.
71 img_context_token (`str`, *optional*, defaults to `"<image>"`):
72 Textual image-context placeholder token.
73 video_context_token_id (`int`, *optional*):
74 Token id used as the video-context placeholder in `input_ids`.
75 video_context_token (`str`, *optional*, defaults to `"<video>"`):
76 Textual video-context placeholder token.
77 sound_context_token_id (`int`, *optional*):
78 Token id used as the audio-context placeholder in `input_ids`.
79 sound_context_token (`str`, *optional*, defaults to `"<audio>"`):
80 Textual audio-context placeholder token.
81 """
82
83 model_type = "nemotron_h_omni"
84 is_composition = True
85
86 vision_config: dict | RadioConfig | None = None
87 llm_config: dict | NemotronHConfig | None = None
88 sound_config: dict | ParakeetEncoderConfig | None = None
89 force_image_size: int | None = None
90 downsample_ratio: float = 0.5
91 template: str | None = None # TODO move out of here and into the tokenizer
92 ps_version: str = "v1" # Pixel shuffle version
93 image_tag_type: str = "internvl" # TODO: into the tokenizer too?
94 projector_hidden_size: int = 4096
95 vit_hidden_size: int = 1280
96 video_pruning_rate: float = 0.0
97 video_temporal_patch_size: int = 2
98 # Vision token settings
99 patch_size: int = 16
100 img_context_token_id: int | None = None
101 img_context_token: str = "<image>"
102 video_context_token_id: int | None = None
103 video_context_token: str = "<video>"
104 # Sound/audio token settings
105 sound_context_token_id: int | None = None
106 sound_context_token: str = "<audio>"
107
108 def __post_init__(self, **kwargs):
109 if isinstance(self.vision_config, dict):
110 self.vision_config = RadioConfig(**self.vision_config)
111 elif self.vision_config is None:
112 self.vision_config = RadioConfig()
113 # The vision tower needs the temporal patch size to build its video patch projection.
114 self.vision_config.video_temporal_patch_size = self.video_temporal_patch_size
115
116 # Handle both cases: when loading from JSON (llm_config is dict) and when called
117 # internally by transformers (llm_config is None).
118 if isinstance(self.llm_config, dict):
119 self.llm_config = NemotronHConfig(**_nemotron_h_compatible_config(self.llm_config))
120 elif self.llm_config is None:
121 self.llm_config = NemotronHConfig()
122
123 # This checkpoint's sound_config omits `attention_bias`/`scale_input`, which are `False` for
124 # its Parakeet variant, so supply them before building the encoder config.
125 if isinstance(self.sound_config, dict):
126 sound_config = {"attention_bias": False, "scale_input": False, **self.sound_config}
127 sound_config.pop("model_type", None)
128 self.sound_config = ParakeetEncoderConfig(**sound_config)
129
130 super().__post_init__(**kwargs)
131
132 # `attn_implementation` flows in through `**kwargs` (the base `PreTrainedConfig` stores it as
133 # `self._attn_implementation`, as for every other model); propagate it to the language model.
134 self.llm_config._attn_implementation = self._attn_implementation
135
136 # vLLM's `NemotronH_Nano_VL_V2` implementation reads the language-model sub-config as
137 # `config.text_config`. Our HF config stores it as `config.llm_config`; expose an alias so the
138 # same config object loads under both loaders without having to duplicate the dict on disk.
139 @property
140 def text_config(self):
141 return self.llm_config