DPO, megatron backend, run_config.yaml FileNotFound error issue with HF -> mcore conversion
Describe the bug
FileNotFoundError: Pretrained run config not found at /root/.cache/huggingface/nemo_rl/model__fsx_models_qwen3-4b/iter_0000000/run_config.yaml on rank=8. This usually means that the one-time HF->mcore conversion on rank=0 saved to a directory not being mounted on this node. Please check
Steps/Code to reproduce bug
- Pull v0.4.0 image and execute following command.
uv run examples/run_dpo.py \
--config examples/configs/dpo.yaml \
policy.model_name=/fsx/models/qwen3-4b \
policy.tokenizer.name=/fsx/models/qwen3-4b \
policy.train_global_batch_size=32 \
policy.train_micro_batch_size=1 \
policy.dtensor_cfg.enabled=false \
policy.megatron_cfg.enabled=true \
dpo.sft_loss_weight=0.1 \
dpo.preference_average_log_probs=true \
cluster.gpus_per_node=8 \
cluster.num_nodes=2 \
checkpointing.checkpoint_dir=/fsx/mydir/
I'm running the job in a k8s cluster and I see the model checkpoints are split between the workers pods. Logging into the pods, I see one of the pod has run_config.yaml file, but not the other.
How do I go about fixing this issue?
Expected behavior
I expected to see training epoch metrics.
Additional context
Head and worker nodes have /root folder mounted.
volumeMounts:
- name: fsx-storage
mountPath: /fsx
- name: ray-logs
mountPath: /tmp/ray
- name: hf-cache
mountPath: /root/.cache/huggingface/
volumes:
- name: ray-logs
emptyDir: {}
- name: hf-cache
emptyDir: {}
- name: fsx-storage
persistentVolumeClaim:
claimName: fsx
Following is the complete stack trace.
nPolicyWorker pid=1081, <ip>) ramasud-nemo-rl-cluster-group-worker-88xkq:1081:3938 [0] NCCL INFO Channel 11/0 : 3[3] -> 11[3] [receive] via NET/Libfabric/3/GDRDMA [repeated 16x across cluster]
(MegatronPolicyWorker pid=1078, <ip>) ramasud-nemo-rl-cluster-group-worker-88xkq:1078:3933 [0] NCCL INFO Connected all trees [repeated 4x across cluster]
(MegatronPolicyWorker pid=1017, <ip>) successfully saved checkpoint from iteration 0 to /root/.cache/huggingface/nemo_rl/model__fsx_models_qwen3-4b [ t 1/2, p 1/1 ]
(MegatronPolicyWorker pid=1017, <ip>) Reinitializing model parallel after loading model state.
Traceback (most recent call last):
File "/opt/nemo-rl/examples/run_dpo.py", line 294, in <module>
main()
File "/opt/nemo-rl/examples/run_dpo.py", line 278, in main
) = setup(config, tokenizer, train_dataset, val_dataset)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/nemo_rl/algorithms/dpo.py", line 252, in setup
policy.print_node_ip_and_gpu_id()
File "/opt/nemo-rl/nemo_rl/models/policy/lm_policy.py", line 784, in print_node_ip_and_gpu_id
results = ray.get(
^^^^^^^^
File "/opt/nemo_rl_venv/lib/python3.12/site-packages/ray/_private/auto_init_hook.py", line 21, in auto_init_wrapper
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/opt/nemo_rl_venv/lib/python3.12/site-packages/ray/_private/client_mode_hook.py", line 103, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo_rl_venv/lib/python3.12/site-packages/ray/_private/worker.py", line 2822, in get
values, debugger_breakpoint = worker.get_objects(object_refs, timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo_rl_venv/lib/python3.12/site-packages/ray/_private/worker.py", line 932, in get_objects
raise value
ray.exceptions.ActorDiedError: The actor died because of an error raised in its creation task, ray::lm_policy-1-0:MegatronPolicyWorker.__init__() (pid=1080, <ip>, actor_id=684403e39bab76693f74d4e002000000, repr=MegatronPolicyWorker[rank=8])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/nemo_rl/models/policy/megatron_policy_worker.py", line 530, in __init__
raise FileNotFoundError(
FileNotFoundError: Pretrained run config not found at /root/.cache/huggingface/nemo_rl/model__fsx_models_qwen3-4b/iter_0000000/run_config.yaml on rank=8. This usually means that the one-time HF->mcore conversion on rank=0 saved to a directory not being mounted on this node. Please check
(MegatronPolicyWorker pid=1017, <ip>) torch distributed is already initialized, skipping initialization ...
(MegatronPolicyWorker pid=1017, <ip>) INFO:megatron.core.num_microbatches_calculator:setting number of microbatches to constant 4
(MegatronPolicyWorker pid=1017, <ip>) WARNING:megatron.core.rerun_state_machine:RerunStateMachine initialized in mode RerunMode.DISABLED
(MegatronPolicyWorker pid=1080, <ip>) /opt/ray_venvs/nemo_rl.models.policy.megatron_policy_worker.MegatronPolicyWorker/lib/python3.12/site-packages/torch/distributed/distributed_c10d.py:4631: UserWarning: No device id is provided via `init_process_group` or `barrier `. Using the current device set by the user. [repeated 5x across cluster]
(MegatronPolicyWorker pid=1080, <ip>) warnings.warn( # warn only once [repeated 5x across cluster]
(MegatronPolicyWorker pid=1078, <ip>) Exception raised in creation task: The actor died because of an error raised in its creation task, ray::lm_policy-1-1:MegatronPolicyWorker.__init__() (pid=1078, <ip>, actor_id=b83f847dd61b7360e5352d1702000000, repr=MegatronPolicyWorker[rank=9])
(MegatronPolicyWorker pid=1078, <ip>) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(MegatronPolicyWorker pid=1078, <ip>) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(MegatronPolicyWorker pid=1078, <ip>) File "/opt/nemo-rl/nemo_rl/models/policy/megatron_policy_worker.py", line 530, in __init__
(MegatronPolicyWorker pid=1078, <ip>) raise FileNotFoundError(
(MegatronPolicyWorker pid=1078, <ip>) FileNotFoundError: Pretrained run config not found at /root/.cache/huggingface/nemo_rl/model__fsx_models_qwen3-4b/iter_0000000/run_config.yaml on rank=9. This usually means that the one-time HF->mcore conversion on rank=0 saved to a directory not being mounted on this node. Please check
(MegatronPolicyWorker pid=1016, <ip>) ramasud-nemo-rl-cluster-group-worker-44pfr:1016:3884 [0] NCCL INFO Connected all trees [repeated 11x across cluster]
(MegatronPolicyWorker pid=1080, <ip>) Reinitializing model parallel after loading model state. [repeated 15x across cluster]
(MegatronPolicyWorker pid=1080, <ip>) Exception raised in creation task: The actor died because of an error raised in its creation task, ray::lm_policy-1-0:MegatronPolicyWorker.__init__() (pid=1080, <ip>, actor_id=684403e39bab76693f74d4e002000000, repr=MegatronPolicyWorker[rank=8]) [repeated 7x across cluster]
(MegatronPolicyWorker pid=1080, <ip>) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [repeated 7x across cluster]
(MegatronPolicyWorker pid=1080, <ip>) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [repeated 7x across cluster]
(MegatronPolicyWorker pid=1080, <ip>) File "/opt/nemo-rl/nemo_rl/models/policy/megatron_policy_worker.py", line 530, in __init__ [repeated 7x across cluster]
(MegatronPolicyWorker pid=1080, <ip>) raise FileNotFoundError( [repeated 7x across cluster]
(MegatronPolicyWorker pid=1080, <ip>) FileNotFoundError: Pretrained run config not found at /root/.cache/huggingface/nemo_rl/model__fsx_models_qwen3-4b/iter_0000000/run_config.yaml on rank=8. This usually means that the one-time HF->mcore conversion on rank=0 saved to a directory not being mounted on this node. Please check [repeated 7x across cluster]
Error removing placement group PlacementGroupID(b3496425739a07596abffb867c0e02000000): sys.meta_path is None, Python is likely shutting down
Error removing placement group PlacementGroupID(77e32508b1496d95de263f08d3bd02000000): sys.meta_path is None, Python is likely shutting down
hi @dhineshkumar-r . what did you set HF_HOME to?
here's our doc for the NRL_MEGATRON_CHECKPOINT_DIR https://github.com/NVIDIA-NeMo/RL/blob/e95efb912a6909b5da91ffeb197debe91fd480d8/docs/design-docs/training-backends.md#megatron-configuration
So usually we set HF_HOME to a NFS so all processes can access the HF checkpoint, but we also re-use that to write the initial checkpoint for the megatron backend. The writing of the initial megatron checkpoint is distributed (to make it fast), so all ranks need to be able to see that path.
Hey @terrykong,
Thanks for the pointer. I did not explicitly set the HF_HOME environment variable when executing the job.
When I set the NRL_MEGATRON_CHECKPOINT_DIR env. variable pointing to a shared folder within /fsx, it works thanks.
However, I face the following issue. Do you have any thoughts on why this could happen? I'm using the default HelpSteer3 dataset.
/opt/nemo-rl/examples/run_dpo.py:140: UserWarning: Sequence length 2258 exceeds max_seq_length 1024. Ignoring example.
warnings.warn(
/opt/nemo-rl/examples/run_dpo.py:140: UserWarning: Sequence length 3422 exceeds max_seq_length 1024. Ignoring example.
warnings.warn(
Traceback (most recent call last):
File "/opt/nemo-rl/examples/run_dpo.py", line 294, in <module>
main()
File "/opt/nemo-rl/examples/run_dpo.py", line 280, in main
dpo_train(
File "/opt/nemo-rl/nemo_rl/algorithms/dpo.py", line 532, in dpo_train
validation_result = validate(
^^^^^^^^^
File "/opt/nemo-rl/nemo_rl/algorithms/dpo.py", line 327, in validate
k_val_metrics, k_validation_timings = validate_one_dataset(
^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/nemo_rl/algorithms/dpo.py", line 387, in validate_one_dataset
for batch_idx, val_batch in enumerate(
^^^^^^^^^^
File "/opt/nemo-rl/nemo_rl/algorithms/dpo.py", line 296, in add_ref_logprobs_to_data
logprobs = policy.get_reference_policy_logprobs(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/nemo_rl/models/policy/lm_policy.py", line 388, in get_reference_policy_logprobs
self.worker_group.get_all_worker_results(futures)
File "/opt/nemo-rl/nemo_rl/distributed/worker_groups.py", line 926, in get_all_worker_results
return future_bundle.get_results(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/nemo_rl/distributed/worker_groups.py", line 102, in get_results
all_results = ray.get(object_refs)
^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo_rl_venv/lib/python3.12/site-packages/ray/_private/auto_init_hook.py", line 21, in auto_init_wrapper
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/opt/nemo_rl_venv/lib/python3.12/site-packages/ray/_private/client_mode_hook.py", line 103, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo_rl_venv/lib/python3.12/site-packages/ray/_private/worker.py", line 2822, in get
values, debugger_breakpoint = worker.get_objects(object_refs, timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo_rl_venv/lib/python3.12/site-packages/ray/_private/worker.py", line 930, in get_objects
raise value.as_instanceof_cause()
ray.exceptions.RayTaskError(AssertionError): ray::MegatronPolicyWorker.get_reference_policy_logprobs() (pid=994, ip=100.64.109.129, actor_id=02e8a240e26cf653463437f602000000, repr=MegatronPolicyWorker[rank=2])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/nemo_rl/utils/nsys.py", line 88, in wrapper
ret = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/nemo_rl/models/policy/megatron_policy_worker.py", line 1429, in get_reference_policy_logprobs
reference_logprobs = self.get_logprobs(
^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/nemo_rl/utils/nsys.py", line 88, in wrapper
ret = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/nemo_rl/models/policy/megatron_policy_worker.py", line 1330, in get_logprobs
list_of_logprobs = forward_backward_func(
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/3rdparty/Megatron-LM-workspace/Megatron-LM/megatron/core/pipeline_parallel/schedules.py", line 631, in forward_backward_no_pipelining
output_tensor, num_tokens = forward_step(
^^^^^^^^^^^^^
File "/opt/nemo-rl/3rdparty/Megatron-LM-workspace/Megatron-LM/megatron/core/pipeline_parallel/schedules.py", line 408, in forward_step
output_tensor, loss_func = forward_step_func(data_iterator, model)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/nemo_rl/models/policy/megatron_policy_worker.py", line 1262, in forward_step_fn
output_tensor = model(
^^^^^^
File "/opt/ray_venvs/nemo_rl.models.policy.megatron_policy_worker.MegatronPolicyWorker/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/ray_venvs/nemo_rl.models.policy.megatron_policy_worker.MegatronPolicyWorker/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/3rdparty/Megatron-LM-workspace/Megatron-LM/megatron/core/distributed/data_parallel_base.py", line 22, in forward
return self.module(*inputs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/ray_venvs/nemo_rl.models.policy.megatron_policy_worker.MegatronPolicyWorker/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/ray_venvs/nemo_rl.models.policy.megatron_policy_worker.MegatronPolicyWorker/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/3rdparty/Megatron-LM-workspace/Megatron-LM/megatron/core/transformer/module.py", line 259, in forward
outputs = self.module(*inputs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/ray_venvs/nemo_rl.models.policy.megatron_policy_worker.MegatronPolicyWorker/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/ray_venvs/nemo_rl.models.policy.megatron_policy_worker.MegatronPolicyWorker/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/3rdparty/Megatron-LM-workspace/Megatron-LM/megatron/core/models/gpt/gpt_model.py", line 373, in forward
self._preprocess(
File "/opt/nemo-rl/3rdparty/Megatron-LM-workspace/Megatron-LM/megatron/core/models/gpt/gpt_model.py", line 279, in _preprocess
decoder_input = self.embedding(input_ids=input_ids, position_ids=position_ids)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/ray_venvs/nemo_rl.models.policy.megatron_policy_worker.MegatronPolicyWorker/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/ray_venvs/nemo_rl.models.policy.megatron_policy_worker.MegatronPolicyWorker/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/3rdparty/Megatron-LM-workspace/Megatron-LM/megatron/core/models/common/embeddings/language_model_embedding.py", line 111, in forward
word_embeddings = self.word_embeddings(input_ids)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/ray_venvs/nemo_rl.models.policy.megatron_policy_worker.MegatronPolicyWorker/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/ray_venvs/nemo_rl.models.policy.megatron_policy_worker.MegatronPolicyWorker/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/3rdparty/Megatron-LM-workspace/Megatron-LM/megatron/core/tensor_parallel/layers.py", line 289, in forward
output = reduce_scatter_to_sequence_parallel_region(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/3rdparty/Megatron-LM-workspace/Megatron-LM/megatron/core/tensor_parallel/mappings.py", line 518, in reduce_scatter_to_sequence_parallel_region
return _ReduceScatterToSequenceParallelRegion.apply(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/ray_venvs/nemo_rl.models.policy.megatron_policy_worker.MegatronPolicyWorker/lib/python3.12/site-packages/torch/autograd/function.py", line 575, in apply
return super().apply(*args, **kwargs) # type: ignore[misc]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/3rdparty/Megatron-LM-workspace/Megatron-LM/megatron/core/tensor_parallel/mappings.py", line 365, in forward
return _reduce_scatter_along_first_dim(input_, group, input_split_sizes, use_global_buffer)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/3rdparty/Megatron-LM-workspace/Megatron-LM/megatron/core/tensor_parallel/mappings.py", line 173, in _reduce_scatter_along_first_dim
dim_size[0] % world_size == 0
AssertionError: First dimension of the tensor should be divisible by tensor parallel size
(MegatronPolicyWorker[rank=14] pid=1113, ip=100.64.250.80) ramasud-nemo-rl-cluster-group-worker-nfhqj:1113:5353 [0] NCCL INFO Connected all rings, use ring PXN 0 GDR 1 [repeated 3x across cluster]
(MegatronPolicyWorker[rank=6] pid=996, ip=100.64.109.129) /opt/nemo-rl/3rdparty/Megatron-LM-workspace/Megatron-LM/megatron/core/tensor_parallel/layers.py:715: UserWarning: When using sequence parallelism it is recommended to set the environment variable CUDA_DEVICE_MAX_CONNECTIONS to 1 for maximum speedup [repeated 3x across cluster]
(MegatronPolicyWorker[rank=6] pid=996, ip=100.64.109.129) warnings.warn( [repeated 3x across cluster]
@ashors1 for the most recent error
Hi, the sequence length should be divisible by tensor parallel size. If you're using the Megatron backend, you'll need to change this line to
make_sequence_length_divisible_by: ${policy.megatron_cfg.tensor_model_parallel_size}
That worked. Thanks both!
QA RCCA Analysis
RCCA Status: Not Required RCCA Category: not_required Test Action: none
Fix PR: N/A Root Cause: closed with no confirmed merged product-code fix PR. Trigger Config: DPO, megatron backend, run_config.yaml FileNotFound error issue with HF -> mcore conversion
Coverage Assessment:
| Area | Result |
|---|---|
| Existing Test | N/A |
| Coverage Status | NOT_REQUIRED |
| Gap | N/A |
| Corrective Action | No RCCA regression test required. |
Conclusion: RCCA classification completed for this closed NeMo-RL GitHub issue.