DPO support for gpt-oss with DTensor and Megatron Backend
Similar to https://github.com/NVIDIA-NeMo/RL/issues/841, raising an issue for DPO support with gpt-oss.
if there are workarounds to achieving this, please share the steps.
Thanks
This should already be supported with #1470. Probably just missing a config.
Thanks for the prompt response @hemildesai.
Got it, I'm interested in performing gpt-oss20b and 120b with Megatron backend. Does pulling the main branch and creating an image out of it suffice?
Please let me know if I should make any other changes to get it working.
Hey @hemildesai,
I pulled the main branch changes and kicked off a job with following overrides in k8s cluseter(4 x p5.en.48xlarge worker nodes)
uv run examples/run_dpo.py \
--config examples/configs/dpo.yaml \
policy.model_name=openai/gpt-oss-20b \
policy.tokenizer.name=openai/gpt-oss-20b \
policy.train_global_batch_size=32 \
policy.train_micro_batch_size=1 \
policy.dtensor_cfg.enabled=false \
policy.megatron_cfg.enabled=true \
policy.megatron_cfg.tensor_model_parallel_size=2 \
policy.make_sequence_length_divisible_by=2 \
+policy.megatron_cfg.env_vars.NRL_MEGATRON_CHECKPOINT_DIR=/fsx/models/megatron/gpt-oss-20b/ \
policy.megatron_cfg.optimizer.use_distributed_optimizer=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/ws/dpo-k8s/checkpoints-megatron/gpt-oss-20b/ramasud-nemo-dpo-rayjob-16
and I see OOM error
nPolicyWorker pid=19398, ip=<ip>) successfully loaded checkpoint from /fsx/models/megatron/gpt-oss-20b//openai/gpt-oss-20b [ t 1/2, p 1/1 ] at iteration 0
(MegatronPolicyWorker pid=19528, ip=100.64.23.102) Reference model loaded
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 858, 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 22, 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 104, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo_rl_venv/lib/python3.12/site-packages/ray/_private/worker.py", line 2882, 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 970, in get_objects
raise value
ray.exceptions.ActorDiedError: The actor died because of an error raised in its creation task, ray::lm_policy-0-2:MegatronPolicyWorker.__init__() (pid=19528, ip=100.64.23.102, actor_id=a56b9a2ad54687c604825fa105000000, repr=MegatronPolicyWorker[rank=2])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/nemo_rl/models/policy/workers/megatron_policy_worker.py", line 945, in __init__
self.model = self.move_model(self.model, "cuda")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/ray_venvs/nemo_rl.models.policy.workers.megatron_policy_worker.MegatronPolicyWorker/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/nemo-rl/nemo_rl/models/policy/workers/megatron_policy_worker.py", line 2336, in move_model
buffers[buffer_idx].reload_from_cpu(
File "/opt/nemo-rl/3rdparty/Megatron-LM-workspace/Megatron-LM/megatron/core/distributed/param_and_grad_buffer.py", line 935, in reload_from_cpu
self.grad_data.storage().resize_(self.grad_data_size)
File "/opt/ray_venvs/nemo_rl.models.policy.workers.megatron_policy_worker.MegatronPolicyWorker/lib/python3.12/site-packages/torch/storage.py", line 1259, in resize_
self._resize_(size)
File "/opt/ray_venvs/nemo_rl.models.policy.workers.megatron_policy_worker.MegatronPolicyWorker/lib/python3.12/site-packages/torch/storage.py", line 1263, in _resize_
self._untyped_storage.resize_(size * self._element_size())
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 37.29 GiB. GPU 0 has a total capacity of 139.81 GiB of which 24.50 GiB is free. Including non-PyTorch memory, this process has 115.10 GiB memory in use. Of the allocated memory 111.86 GiB is allocated by PyTorch, and 6.00 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)
Following are some warnings that caught my eye
- I see the warning mentioned here when the hf checkpoint is being converted to megatron format I believe. Specifically,
WARNING: Dtype mismatch between HuggingFace weights and Megatron module. HF dtype: torch.bfloat16. Megatron dtype: torch.float32. Casting HF weights to Megatron dtype. THIS MAY RESULT IN A LOSS OF PRECISION. [repeated 2x across cluster]
- I also notice
(TP, PP) mismatch after resume ((2,1), vs (1,1) from checkpoint): RNG state will be ignored.message in the logs.
Could these contribute to the error I see?
If there is something else I'm missing, please let me know.
Thanks
Setting the recommended config mentioned here tp=1, pp=1 and ep=8 helped resolve the OOM.
QA RCCA Analysis
RCCA Status: Not Required RCCA Category: not_required Test Action: none
Fix PR: N/A Root Cause: This issue is not an actionable closed product-code defect for RCCA; it is enhancement/feature tracking, docs/cosmetic work, placeholder/test issue, or closed non-bug work. Trigger Config: N/A.
Coverage Assessment:
| Area | Result |
|---|---|
| Existing Test | N/A |
| Coverage Status | NOT_REQUIRED |
| Gap | N/A |
| Corrective Action | No RCCA regression test required. |
Conclusion: RCCA not required because this does not represent a QA coverage escape for a fixed NeMo-RL bug.