Skip to content

fix(train): serialize GaLore projector state in checkpoints - #10161

Open
MrCapricornLiu wants to merge 1 commit into
modelscope:mainfrom
MrCapricornLiu:lch/fix-galore-checkpoint-serialization
Open

MrCapricornLiu wants to merge 1 commit into
modelscope:mainfrom
MrCapricornLiu:lch/fix-galore-checkpoint-serialization

Conversation

@MrCapricornLiu

Copy link
Copy Markdown
Contributor

GaLore stores a GaLoreProjector instance in optimizer state. Consequently, a normal optimizer checkpoint cannot be restored by Trainer's torch.load(..., weights_only=True): it fails with an unsupported-global error before training resumes.

Serialize the projector as a dictionary of configuration values and tensors, then reconstruct it when loading optimizer state. The live optimizer keeps its projector object. Move cached projection bases to the gradient's device/dtype before reuse, so CPU-mapped checkpoints can resume on CUDA without waiting for the next SVD refresh. This applies to the bundled AdamW, Adafactor and AdamW8bit implementations.

Validation:

  • Four regression methods pass on CUDA, including five projection modes on CPU, CPU-mapped restoration on CUDA, bitsandbytes 8-bit state, ordinary parameter groups and legacy in-memory projector states.
  • A tiny GPT-2 with the real Transformers Trainer fails to resume on main. With the patch, resuming at step 3 produces exactly the same parameters as uninterrupted training through step 6.
  • Changed-file pre-commit hooks and git diff --check pass. Base-revision whole-repository lint has an unrelated formatting failure in tests/megatron/test_infonce_ddp_e2e.py.

This makes newly written checkpoints compatible with safe loading. It does not change safe-loading policy for older pickled-object checkpoints, or address the separate per-parameter optimizer wrapper's checkpoint handling. Validation used FP32 parameters; distributed/sharded checkpoints and q-galore were not tested.

@tastelikefeet

Copy link
Copy Markdown
Collaborator

lint the code by:

pre-commit run --all-files

please

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants