Files
Model-Optimizer/modelopt/torch/utils/import_utils.py
T
Keval Morabia 01c708e792 Add HybridModel MBridge support for nemo:26.08 (#2005)
### Description

MBridge main (nemo:26.08) will initialize Nemotron-H as HybridModel
instead of MambaModel (subclassed of HybridModel). Also make minimum
nemo container 26.04

### Testing 

Tested Nemotron-3-Nano PTQ with MBridge main (fails otherwise)

Tested locally `tests/gpu_megatron` and `tests/examples/megatron_bridge`
with `nemo:26.06.01` + Mount latest MBridge/Mcore

GH CICD tests will be added with nemo:26.08 release

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added TE HybridModel stack-spec support and enabled Megatron-Bridge
hybrid providers/models for export/import and runtime handling.
* **Updates**
* Dataset packing now oversamples raw text at **16x** and improves the
packed-mode underflow warning.
* Quantization: `--quant_cfg` now defaults to `None` unless explicitly
set (or via `--recipe`).
* Distillation example: validation settings are provided via a dedicated
top-level validation configuration.
* Improved plugin import warnings to report the originating call
location; model stats now support HybridModel.
* **Deprecations**
* Megatron-Bridge / Megatron-LM optimization features now require NeMo
container `nemo:26.04` or newer (`nemo:26.06` recommended).
  * The Mamba stack specification helper is deprecated.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com>
2026-07-23 18:26:15 +05:30

45 lines
1.9 KiB
Python

# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# 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.
"""Handles suppressing import errors for third-party modules that may or may not be available."""
import sys
from contextlib import contextmanager
from .logging import warn_rank_0
@contextmanager
def import_plugin(plugin_name, msg_if_missing=None, verbose=True, success_msg=None):
"""Context manager to import a plugin and suppress ModuleNotFoundError."""
try:
yield
if verbose and success_msg is not None:
warn_rank_0(success_msg)
except ModuleNotFoundError:
if verbose and msg_if_missing is not None:
warn_rank_0(msg_if_missing)
except Exception as e:
if verbose:
# Capture the ``with import_plugin(...)`` call site so warnings point at the plugin
# that actually failed rather than at this helper. When ``__enter__`` runs the
# generator body, the stack is [0]=here, [1]=contextlib.__enter__, [2]=the caller.
caller = sys._getframe(2)
warn_rank_0(
f"Failed to import modelopt {plugin_name} plugin "
f"(from {caller.f_code.co_filename}:{caller.f_lineno}) due to: {e!r}. "
"You may ignore this warning if you do not need this plugin."
)