|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# |
| 16 | +# Nemotron Omni / Super 3.5 HF <-> MegatronMIMO conversion. |
| 17 | +# Run from the repository root with a local HF checkpoint or HF repository ID: |
| 18 | +# HF_MODEL=/path/to/hf-checkpoint WORKSPACE=/workspace \ |
| 19 | +# bash examples/megatron_mimo/nemotron_omni/conversion.sh |
| 20 | +# Pass "import" or "export" to run only that phase; default is both. |
| 21 | +# Defaults match the four-GPU Super 3.5 layout: image DP2, language TP2/EP2. |
| 22 | +# The images component contains RADIO and its projector. Audio is not supported. |
| 23 | + |
| 24 | +set -euo pipefail |
| 25 | + |
| 26 | +: "${HF_MODEL:?Set HF_MODEL to the source HF checkpoint path or repository ID}" |
| 27 | +PHASE=${1:-all} |
| 28 | +case "${PHASE}" in |
| 29 | + import|export|all) ;; |
| 30 | + *) echo "Usage: $0 [import|export|all]" >&2; exit 1 ;; |
| 31 | +esac |
| 32 | + |
| 33 | +WORKSPACE=${WORKSPACE:-/workspace} |
| 34 | +MEGATRON_PATH=${MEGATRON_PATH:-"${WORKSPACE}/nemotron-omni-mimo"} |
| 35 | +HF_PATH=${HF_PATH:-"${WORKSPACE}/nemotron-omni-mimo-export-hf"} |
| 36 | +TORCH_DTYPE=${TORCH_DTYPE:-bfloat16} |
| 37 | + |
| 38 | +LANGUAGE_TP=${LANGUAGE_TP:-2} |
| 39 | +LANGUAGE_DP=${LANGUAGE_DP:-1} |
| 40 | +LANGUAGE_EP=${LANGUAGE_EP:-2} |
| 41 | +LANGUAGE_ETP=${LANGUAGE_ETP:-1} |
| 42 | +VISION_TP=${VISION_TP:-1} |
| 43 | +VISION_DP=${VISION_DP:-2} |
| 44 | +LANGUAGE_RANKS=$((LANGUAGE_TP * LANGUAGE_DP)) |
| 45 | +VISION_RANKS=$((VISION_TP * VISION_DP)) |
| 46 | +NPROC_PER_NODE=${NPROC_PER_NODE:-$((LANGUAGE_RANKS + VISION_RANKS))} |
| 47 | + |
| 48 | +# Import uses the verified layout: images first, then language. |
| 49 | +if [[ "${PHASE}" == import || "${PHASE}" == all ]]; then |
| 50 | + uv run python -m torch.distributed.run --nproc_per_node="${NPROC_PER_NODE}" \ |
| 51 | + examples/conversion/convert_megatron_mimo.py import \ |
| 52 | + --hf-model "${HF_MODEL}" \ |
| 53 | + --megatron-path "${MEGATRON_PATH}" \ |
| 54 | + --component "images=tp=${VISION_TP},dp=${VISION_DP},rank_offset=0" \ |
| 55 | + --component "language=tp=${LANGUAGE_TP},dp=${LANGUAGE_DP},ep=${LANGUAGE_EP},etp=${LANGUAGE_ETP},rank_offset=${VISION_RANKS}" \ |
| 56 | + --torch-dtype "${TORCH_DTYPE}" \ |
| 57 | + --trust-remote-code |
| 58 | +fi |
| 59 | + |
| 60 | +# Export places language on rank zero so its weights stream directly to the |
| 61 | +# HF writer, avoiding a whole-language-component gather from another rank. |
| 62 | +if [[ "${PHASE}" == export || "${PHASE}" == all ]]; then |
| 63 | + uv run python -m torch.distributed.run --nproc_per_node="${NPROC_PER_NODE}" \ |
| 64 | + examples/conversion/convert_megatron_mimo.py export \ |
| 65 | + --hf-model "${HF_MODEL}" \ |
| 66 | + --megatron-path "${MEGATRON_PATH}" \ |
| 67 | + --hf-path "${HF_PATH}" \ |
| 68 | + --component "language=tp=${LANGUAGE_TP},dp=${LANGUAGE_DP},ep=${LANGUAGE_EP},etp=${LANGUAGE_ETP},rank_offset=0" \ |
| 69 | + --component "images=tp=${VISION_TP},dp=${VISION_DP},rank_offset=${LANGUAGE_RANKS}" \ |
| 70 | + --torch-dtype "${TORCH_DTYPE}" \ |
| 71 | + --trust-remote-code |
| 72 | +fi |
0 commit comments