# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from huggingface_hub.dataclasses import strict from transformers.configuration_utils import PreTrainedConfig from transformers.models.nemotron_h import NemotronHConfig from transformers.models.parakeet.configuration_parakeet import ParakeetEncoderConfig from transformers.utils import auto_docstring, logging from .configuration_radio import RadioConfig from .configuration_nemotron_h_puzzle import NemotronHPuzzleConfig # Imported by name even though NemotronHPuzzleConfig re-exports what we need: # for a local checkpoint directory Transformers stages only the direct relative # imports of this one file into HF_MODULES_CACHE, while the loader then walks # imports recursively. Without this line the nested # configuration_nemotron_h_puzzle -> configuration_nemotron_h import is never # copied and AutoConfig.from_pretrained fails with FileNotFoundError. from .configuration_nemotron_h import NemotronHConfig as _NemotronHConfig # noqa: F401 __all__ = ["NemotronH_Omni_Reasoning_V3_Config"] logger = logging.get_logger(__name__) def _nemotron_h_compatible_config(config: dict) -> dict: """Translate current Nemotron-H layer names for Transformers versions using legacy names.""" config = dict(config) legacy_names = {"linear_attention": "mamba", "full_attention": "attention"} for field in ("layers_block_type", "mtp_layers_block_type"): if field in config and config[field] is not None: config[field] = [legacy_names.get(layer_type, layer_type) for layer_type in config[field]] return config @auto_docstring(checkpoint="nvidia/Nemotron-3-Nano-Omni-30B-A3B-Reasoning-BF16") @strict class NemotronH_Omni_Reasoning_V3_Config(PreTrainedConfig): r""" vision_config (`dict` or `RadioConfig`, *optional*): Configuration for the RADIO vision encoder. Defaults to a default [`RadioConfig`]. llm_config (`dict` or `NemotronHConfig`, *optional*): Configuration for the NemotronH language model. Defaults to a default [`NemotronHConfig`]. sound_config (`dict` or `ParakeetEncoderConfig`, *optional*): Configuration for the optional Parakeet sound encoder. `None` disables the audio branch. force_image_size (`int`, *optional*): Fixed input image resolution (in pixels) the vision tower expects. downsample_ratio (`float`, *optional*, defaults to 0.5): Pixel-shuffle spatial downsample ratio applied to the vision features. template (`str`, *optional*): Conversation template name (legacy; the chat template is carried by the processor). ps_version (`str`, *optional*, defaults to `"v1"`): Pixel-shuffle implementation version (`"v2"` swaps height/width back; `"v1"` is the legacy transposed variant). image_tag_type (`str`, *optional*, defaults to `"internvl"`): Image-tag convention used when expanding image placeholders. projector_hidden_size (`int`, *optional*, defaults to 4096): Hidden size of the vision-to-LLM MLP projector. vit_hidden_size (`int`, *optional*, defaults to 1280): Hidden size of the RADIO vision features. video_pruning_rate (`float`, *optional*, defaults to 0.0): Efficient-Video-Sampling token pruning rate; `0.0` disables pruning. video_temporal_patch_size (`int`, *optional*, defaults to 2): Number of frames collapsed into a single temporal patch by the video embedder. patch_size (`int`, *optional*, defaults to 16): Vision patch size in pixels. img_context_token_id (`int`, *optional*): Token id used as the image-context placeholder in `input_ids`. img_context_token (`str`, *optional*, defaults to `""`): Textual image-context placeholder token. video_context_token_id (`int`, *optional*): Token id used as the video-context placeholder in `input_ids`. video_context_token (`str`, *optional*, defaults to `"