Skip to content

Commit 8c61e94

Browse files
committed
Fix save_megatron_model deadlock with vLLM inference workers
Pass fully_parallel_save=False to bridge.save_megatron_model() during HF-to-Megatron conversion. FullyParallelSaveStrategyWrapper calls all_gather_object on DP sub-groups that include vLLM ranks which never enter save, causing a permanent deadlock. Uses inspect.signature for backward compat with Megatron-Bridge versions that do not yet expose the parameter (see NVIDIA-NeMo/Megatron-Bridge PR).
1 parent 0baabd5 commit 8c61e94

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

nemo_rl/models/megatron/community_import.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import inspect
1516
import os
1617
from typing import Any, Optional
1718

@@ -107,7 +108,14 @@ def import_model_from_hf_name(
107108
config.num_layers_in_last_pipeline_stage = orig_num_layers_in_last_pipeline_stage
108109
config.pipeline_dtype = orig_pipeline_dtype
109110

110-
bridge.save_megatron_model(megatron_model, output_path)
111+
# fully_parallel_save=False avoids deadlock when world includes non-training ranks
112+
# (e.g., non-colocated vLLM). FullyParallelSaveStrategyWrapper would call
113+
# all_gather_object on DP sub-groups that include ranks that never enter save.
114+
# Conditional for backward compat with older Megatron-Bridge versions.
115+
save_kwargs = {}
116+
if "fully_parallel_save" in inspect.signature(bridge.save_megatron_model).parameters:
117+
save_kwargs["fully_parallel_save"] = False
118+
bridge.save_megatron_model(megatron_model, output_path, **save_kwargs)
111119

112120
# resetting mcore state
113121
import megatron.core.rerun_state_machine

0 commit comments

Comments
 (0)