[EXPERIMENT][WIP][OpenVINO] Add support for NemotronH#1724
Closed
mlukasze wants to merge 9 commits into
Closed
Conversation
- Add NemotronHOpenVINOConfig class extending TextDecoderOnnxConfig - Register nemotron_h model type for text-generation and text-generation-with-past tasks - Configure DUMMY_INPUT_GENERATOR_CLASSES and NORMALIZED_CONFIG_CLASS for proper export support This enables exporting NVIDIA Nemotron H models to OpenVINO IR format.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16 for the nemotron_h test entry on the feature branch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
NemotronH is NVIDIA's hybrid Mamba-2 + MoE architecture used in nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16. Architecture pattern: - 23 Mamba-2 SSM layers (M) - 6 standard attention layers (E) - 23 MoE layers (*) - hybrid_override_pattern: 'MEMEM*EMEMEM*...' Changes: - model_configs.py: NemotronHNormalizedTextConfig mapping layers_block_type->layer_types NemotronHOpenVINOConfig extending GraniteMoeHybridOpenVINOConfig - model_patcher.py: NemotronHModelPatcher with: * _parse_nemotron_h_pattern() for hybrid_override_pattern parsing * Robust MoE forward with fallbacks * Fixed closure scoping for TorchScript tracing * backbone.layers access pattern Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Features added: - Comprehensive documentation for NemotronH (NVIDIA Nemotron Hybrid Mamba-2 + MoE) * Architecture overview and characteristics * Configuration parameters (Mamba SSM, MoE, hybrid layers) * Export and inference examples with code samples * Performance characteristics and optimization tips * Troubleshooting guide for common issues * Implementation details and internal architecture - Complete test suite for NemotronH support (13 tests): * Model type registration in TasksManager * Config inheritance validation (GraniteMoeHybridOpenVINOConfig, OnnxConfig) * NemotronHOpenVINOConfig initialization * NemotronHNormalizedTextConfig attribute mapping * Layer type mapping for hybrid architecture (Mamba, Attention, MoE) * MoE and SSM parameter handling * Hybrid architecture validation (alternating layers, override patterns) * Task support (text-generation, text-generation-with-past) - Integration with existing test suites: * Added nemotron_h to test_exporters_cli.py SUPPORTED_ARCHITECTURES (TF >= 5.0) * Added nemotron_h to _NUM_EXPECTED_TOKENIZERS with value 2 * Added nemotron_h to test_decoder.py with decoder count 1 All tests pass (13/13 in test_nemotron_h.py): - Registration tests: 3/3 passed - Config tests: 1/1 passed - Normalized config tests: 4/4 passed - Hybrid architecture tests: 2/2 passed - Task support tests: 3/3 passed Changes are ready for model export, inference optimization, and production deployment. Co-authored-by: Copilot <copilot@users.noreply.github.com>
NemotronHBlock.forward() unconditionally calls torch.cuda.stream() which fails on systems without NVIDIA GPU driver. Added _patch_cuda_stream_for_cpu() in NemotronHModelPatcher to make the CUDA stream call a no-op when running on CPU. This allows exporting the model to OpenVINO IR on CPU-only Intel systems (no NVIDIA driver required). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
NemotronH uses different attribute names than standard Mamba config: - mamba_expand -> expand - mamba_d_conv -> conv_kernel - mamba_d_state -> ssm_state_size - mamba_ngroups -> n_groups - mamba_headdim -> head_dim - mamba_nheads -> mamba_num_heads - mamba_d_ssm -> (computed from expand*hidden_size/nheads) - mamba_dt_rank -> (computed from hidden_size/16) Added comprehensive property-based mapping in NemotronHNormalizedTextConfig to support GraniteMoeHybrid dummy input generator for Mamba-2 blocks. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use torch.narrow for the padded prefill crop so the export path no longer creates a tensor-valued Python slice at the NemotronH mamba output trim. This removes the model_patcher.py:8186 tracerwarning seen during export. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- declare NemotronH normalized config supports past - add temporary .model alias for NemotronH patching - point NemotronH test registry to tiny random model Validated with: PYTHONPATH=$PWD pytest -q tests/openvino/test_nemotron_h.py -q Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Collaborator
|
We need other representation for mamba block. The current one is not correct. This arch review matters. |
Contributor
Author
|
current PR: #1789 |
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?
Adds OpenVINO export support for NemotronH (
model_type = "nemotron_h") — NVIDIA's hybrid Mamba-2 + MoE architecture used innvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16.Architecture:
hybrid_override_pattern(e.g."MEMEM*EMEMEM*...")M= Mamba-2 SSM layer (23 layers)E= standard attention layer (6 layers)*= Mixture-of-Experts layer (23 layers, 128 routed + 1 shared expert)Changes:
model_configs.py:NemotronHNormalizedTextConfig— maps NemotronH'slayers_block_typeattribute to thelayer_typesinterface expected byGraniteMoeHybridOpenVINOConfigmodel_configs.py:NemotronHOpenVINOConfig— extendsGraniteMoeHybridOpenVINOConfigto reuse hybrid cache handling (Mamba-2 SSM states + KV cache)model_patcher.py:NemotronHModelPatcher— parses thehybrid_override_patternstring; fixes TorchScript tracing closure scoping; robust MoE forward with API fallbacksInstallation instructions
pip install optimum-intel[openvino] \ --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly \ openvino openvino-tokenizersExporting the model
optimum-cli export openvino \ --model nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16 \ --task text-generation-with-past \ --weight-format int4 \ --trust-remote-code \ ./nemotron-h-int4/Inference script
Before submitting