6161except (ImportError , ModuleNotFoundError ):
6262 from .perf_plugins import NsysPlugin , PreemptionPlugin , PyTorchProfilerPlugin
6363
64+ try :
65+ from utils .nvcre_bridge import (
66+ BRIDGE_POD_ROOT ,
67+ WORKSPACE_MOUNT ,
68+ WORKSPACE_VOLUME ,
69+ LocalBridge ,
70+ bridge_init_container ,
71+ local_bridge_source ,
72+ )
73+ except (ImportError , ModuleNotFoundError ):
74+ from .utils .nvcre_bridge import (
75+ BRIDGE_POD_ROOT ,
76+ WORKSPACE_MOUNT ,
77+ WORKSPACE_VOLUME ,
78+ LocalBridge ,
79+ bridge_init_container ,
80+ local_bridge_source ,
81+ )
82+
6483SCRIPT_DIR = Path (__file__ ).parent .resolve ()
6584REPO_ROOT = SCRIPT_DIR .parents [1 ]
6685BRIDGE_SOURCE_DIR = REPO_ROOT / "src" / "megatron" / "bridge"
@@ -95,7 +114,7 @@ def _filter_run_script_args(argv: List[str]) -> List[str]:
95114 Value-taking flags are passed as ``--flag value`` or ``--flag=value``.
96115 Boolean flags (no following value) are listed in ``_LAUNCHER_ONLY_BOOL``.
97116 """
98- _LAUNCHER_ONLY_BOOL = {"--offline" , "--dryrun" , "-d" }
117+ _LAUNCHER_ONLY_BOOL = {"--offline" , "--dryrun" , "-d" , "--nvcre_use_mbridge_commit" }
99118
100119 def _is_launcher_only (flag : str ) -> bool :
101120 return (
@@ -158,6 +177,17 @@ def _bridge_source_mount(in_container_script_dir: str) -> str:
158177 return f"{ BRIDGE_SOURCE_DIR } :{ target } "
159178
160179
180+ def _resolve_local_bridge (nvcre_use_mbridge_commit : bool , nvcre_namespace : Optional [str ]) -> Optional [LocalBridge ]:
181+ """The checkout the pods should run for ``--nvcre_use_mbridge_commit``, or None when the flag is off."""
182+ if not nvcre_use_mbridge_commit :
183+ return None
184+ if nvcre_namespace is None :
185+ raise ValueError ("--nvcre_use_mbridge_commit requires --nvcre_namespace." )
186+ local_bridge = local_bridge_source (REPO_ROOT )
187+ logger .info ("Pods will run Megatron-Bridge %s@%s from the init container" , local_bridge .url , local_bridge .commit )
188+ return local_bridge
189+
190+
161191def _build_nemorun_script (
162192 * ,
163193 script_path : str ,
@@ -168,10 +198,11 @@ def _build_nemorun_script(
168198) -> run .Script :
169199 """Build the rank-local task and apply optional Kubeflow NUMA binding."""
170200 in_container_repo_root = Path (script_dir ).parents [1 ]
201+ python_path = [script_dir , str (in_container_repo_root / "src" )]
171202 task = run .Script (
172203 path = script_path ,
173204 entrypoint = "python" ,
174- env = {"PYTHONPATH" : f" { script_dir } : { in_container_repo_root / 'src' } : $PYTHONPATH" },
205+ env = {"PYTHONPATH" : ":" . join ([ * python_path , " $PYTHONPATH"]) },
175206 args = args ,
176207 )
177208 if kubeflow_namespace and _kubeflow_numa_binding_enabled (custom_env_vars ):
@@ -578,7 +609,8 @@ def main(
578609 nvcre_node_selector_json : Optional [str ] = None ,
579610 nvcre_volumes_json : Optional [str ] = None ,
580611 nvcre_volume_mounts_json : Optional [str ] = None ,
581- nvcre_timeout_per_job : str = "24h" ,
612+ nvcre_use_mbridge_commit : bool = False ,
613+ nvcre_timeout_per_job : str = "12h" ,
582614 nvcre_kubeconfig : Optional [str ] = None ,
583615 nvcre_kube_context : Optional [str ] = None ,
584616 nvcre_gang_scheduler_name : Optional [str ] = None ,
@@ -656,8 +688,11 @@ def main(
656688 # Kubeflow the trainer pod runs the image — which ships Megatron-Bridge at
657689 # /opt/Megatron-Bridge — and custom_mounts do not apply, so the launcher's
658690 # /tmp path does not exist in the pod; use the image's script path instead.
691+ # On NVCRE, --nvcre_use_mbridge_commit has an init container clone this checkout's commits into the pod.
692+ local_bridge = _resolve_local_bridge (nvcre_use_mbridge_commit , nvcre_namespace )
659693 if kubeflow_namespace or nvcre_namespace :
660- in_container_script_dir = "/opt/Megatron-Bridge/scripts/performance"
694+ bridge_root = BRIDGE_POD_ROOT if local_bridge else "/opt/Megatron-Bridge"
695+ in_container_script_dir = f"{ bridge_root } /scripts/performance"
661696 in_container_script_path = f"{ in_container_script_dir } /{ script_name } "
662697 else :
663698 in_container_script_dir = str (SCRIPT_DIR )
@@ -720,6 +755,9 @@ def main(
720755 from utils .executors import nvcre_executor
721756 except ImportError :
722757 from .utils .executors import nvcre_executor
758+ init_containers = [bridge_init_container (local_bridge , container_image )] if local_bridge else None
759+ extra_volumes = [dict (WORKSPACE_VOLUME )] if local_bridge else []
760+ extra_mounts = [dict (WORKSPACE_MOUNT )] if local_bridge else []
723761 executor = nvcre_executor (
724762 namespace = nvcre_namespace ,
725763 container_image = container_image ,
@@ -730,8 +768,9 @@ def main(
730768 workdir_pvc_path = nvcre_workdir_pvc_path ,
731769 workdir_local_path = nvcre_workdir_local_path ,
732770 node_selector = json .loads (nvcre_node_selector_json ) if nvcre_node_selector_json else None ,
733- volumes = json .loads (nvcre_volumes_json ) if nvcre_volumes_json else None ,
734- volume_mounts = json .loads (nvcre_volume_mounts_json ) if nvcre_volume_mounts_json else None ,
771+ volumes = (json .loads (nvcre_volumes_json ) if nvcre_volumes_json else []) + extra_volumes ,
772+ volume_mounts = (json .loads (nvcre_volume_mounts_json ) if nvcre_volume_mounts_json else []) + extra_mounts ,
773+ init_containers = init_containers ,
735774 timeout_per_job = nvcre_timeout_per_job ,
736775 kubeconfig = nvcre_kubeconfig ,
737776 kube_context = nvcre_kube_context ,
@@ -1062,7 +1101,7 @@ def main(
10621101 task = args .task ,
10631102 compute_dtype = args .compute_dtype ,
10641103 gpu = args .gpu ,
1065- hf_token = args .hf_token or os . environ . get ( "HF_TOKEN" ) ,
1104+ hf_token = args .hf_token ,
10661105 offline = args .offline ,
10671106 # Force detach for Nvcre — llmb-run polls for completion via nvcrectl
10681107 detach = True if args .nvcre_namespace else args .detach ,
@@ -1150,6 +1189,7 @@ def main(
11501189 nvcre_node_selector_json = args .nvcre_node_selector_json ,
11511190 nvcre_volumes_json = args .nvcre_volumes_json ,
11521191 nvcre_volume_mounts_json = args .nvcre_volume_mounts_json ,
1192+ nvcre_use_mbridge_commit = args .nvcre_use_mbridge_commit ,
11531193 nvcre_timeout_per_job = args .nvcre_timeout_per_job ,
11541194 nvcre_kubeconfig = args .nvcre_kubeconfig ,
11551195 nvcre_kube_context = args .nvcre_kube_context ,
0 commit comments