Skip to content

CPU offload issue causing optimizer to work on randomly initialized model weights #2371

Open

Description

@pengdurice

Describe the bug

When using megatron backend + optimizer CPU offload + fp32 optimizer update + distributed optimizer + reading from a hf checkpoints combined together, the model weights that the optimizer states operate on (call step() on) are still randomly initiated values invalidating the training.

Steps/Code to reproduce bug

In this PR which is aimed to fix the issue has steps to reproduce and fix the issue.

run:
NRL_DISABLE_FP32_SYNC_FIX=1 bash tests/test_suites/llm/sft-qwen2.5-0.5b-1n2g-megatron-cpuoffload.sh
loss values ~10 which is logprobs of random prediction of ~100K vocab

Image

When calling with
NRL_DISABLE_FP32_SYNC_FIX=0 bash tests/test_suites/llm/sft-qwen2.5-0.5b-1n2g-megatron-cpuoffload.sh

Image

Root Cause
The root cause is after when the above mentioned knobs are combined, some more copies on CPU of the model weights are created, however, they are not correctly replaced by the pretrained hf model weights when doing fine-tuning, causing the optimizer to operate on randomly initialized model weights invalidating the whole training.
Expected behavior

A clear and concise description of what you expected to happen.

Additional context

The issue was first discovered during a mutli-node large model fine tuning where the fine-tuned model only produced gibberish outputs, further investigation revealed that the model weights were nearly randomly initialized, then this final root cause was discovered. The cpu offload + distributed optimizer + bf16 are all combined for efficiency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    accuracybugcommunity-requestwaiting-on-maintainers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions