Skip to content

[Train] Support FSDP2 checkpoint resume#1149

Merged
Caozhou1995 merged 28 commits into
flagos-ai:mainfrom
legitnull:qwen_gr00t_fix_lerobot_adapt
Mar 25, 2026
Merged

[Train] Support FSDP2 checkpoint resume#1149
Caozhou1995 merged 28 commits into
flagos-ai:mainfrom
legitnull:qwen_gr00t_fix_lerobot_adapt

Conversation

@legitnull

@legitnull legitnull commented Mar 13, 2026

Copy link
Copy Markdown
Collaborator

PR Category

Train

PR Types

Improvements

PR Description

  • Refactor to use standard from_pretrained, save_pretrained api
  • Reorganize qwen_gr00t into proper subpackage (qwen_gr00t/, vlm/qwenvl_backbone)
  • Add FSDP2 checkpoint resume support (model, optimizer, scheduler, RNG state)
  • vla serving script now supports arbitrary observation key names

@legitnull legitnull force-pushed the qwen_gr00t_fix_lerobot_adapt branch from 8e092a4 to 7504c21 Compare March 13, 2026 08:43
@legitnull legitnull changed the title Qwen gr00t fix lerobot adapt [Train] Support FSDP2 checkpoint resume Mar 17, 2026
@legitnull legitnull marked this pull request as ready for review March 17, 2026 09:49
heavyrain-lzy
heavyrain-lzy previously approved these changes Mar 19, 2026

@heavyrain-lzy heavyrain-lzy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aoyulong aoyulong requested a review from Copilot March 19, 2026 04:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates FlagScale’s VLA training/serving stack to use a Hugging Face–style checkpoint layout (save_pretrained / from_pretrained), adds FSDP2 resume support (including optimizer/scheduler/RNG), and introduces serve-time preprocessing + observation key remapping for QwenGr00t.

Changes:

  • Refactor checkpoint save/load to a standard config.json + model.safetensors layout, plus training_state/ for resuming.
  • Add FSDP2 full-state checkpoint resume utilities and CUDA tests for model/optimizer/training-state round-trips.
  • Improve QwenGr00t packaging/config dispatch and serving behavior (rename-map + optional serve preprocessor like image resize).

Reviewed changes

Copilot reviewed 30 out of 31 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/unit_tests/train/utils/test_train_utils.py Adds unit tests for new checkpoint/training-state helpers, including FSDP2 round-trips.
tests/unit_tests/serve/processor/test_image_resize_processor.py Adds tests for the new serve-time image resize processor step.
tests/unit_tests/models/vla/vlm/test_qwenvl_backbone.py Updates imports to the renamed QwenVL backbone module.
tests/unit_tests/models/vla/test_qwen_gr00t_config.py Adds extensive tests for PreTrainedConfig dispatch + QwenGr00tConfig serialization/validation.
flagscale/train/utils/train_utils.py Reworks checkpoint saving into save_checkpoint + adds FSDP2 load helpers + optimizer/scheduler/rng persistence.
flagscale/train/utils/random_utils.py Adds safetensors-based RNG state save/load for random/numpy/torch.
flagscale/train/utils/io_utils.py Adds strict JSON→object deserialization helper (used for scheduler state).
flagscale/train/train_qwen_gr00t.py Integrates PreTrainedConfig, TrainablePolicy, FSDP2 optimizer state capture, and resume logic.
flagscale/train/train_config.py Adds resume_from, introduces train_config.json save/load helpers, and improves extra-field accessors.
flagscale/train/processor/pipeline.py Uses resolve_pretrained_dir when loading pipeline configs from a directory.
flagscale/serve/run_serve_qwen_gr00t.py Switches to TrainablePolicy.from_pretrained, adds validation, rename-map support, and serve-time processor pipeline.
flagscale/serve/processor/image_resize_processor.py Introduces an observation image resize processor for serving.
flagscale/serve/processor/init.py Registers/exports serve processor steps.
flagscale/models/vla/vlm/qwenvl_backbone.py Refactors VLM config to a dataclass (QwenVLConfig) and removes TrainConfig coupling.
flagscale/models/vla/vlm/init.py Updates exports for renamed backbone module.
flagscale/models/vla/registry.py Simplifies build_action_model API to **kwargs.
flagscale/models/vla/qwen_gr00t/task_encoder_qwen_gr00t.py Adds WDS task encoder under the reorganized qwen_gr00t subpackage.
flagscale/models/vla/qwen_gr00t/modeling_qwen_gr00t.py Migrates QwenGr00t to TrainablePolicy + PreTrainedConfig, adds self-contained VLM artifact saving/loading.
flagscale/models/vla/qwen_gr00t/configuration_qwen_gr00t.py Adds QwenGr00tConfig implementing polymorphic config + delta index logic.
flagscale/models/vla/qwen_gr00t/init.py Exposes QwenGr00t model + config from the new subpackage.
flagscale/models/vla/pretrained_config.py Introduces polymorphic config base (PreTrainedConfig) with registry + serialization.
flagscale/models/vla/base_policy.py Introduces TrainablePolicy base with registry + save_pretrained/from_pretrained.
flagscale/models/vla/action_model/gr00t_action_header.py Adds GR00TActionHeadConfig + registers GR00TActionHead; refactors Flowmatching head init to config-driven.
flagscale/models/vla/action_model/flow_matching.py Removes old FlowMatchingHead wrapper (replaced by GR00TActionHead).
flagscale/models/vla/action_model/init.py Updates exports to GR00TActionHead.
flagscale/models/vla/init.py Exports TrainablePolicy and removes FlowMatchingHead from public API.
flagscale/models/utils/constants.py Adds SAFETENSORS_FILE constant + resolve_pretrained_dir helper.
flagscale/inference/inference_qwen_gr00t.py Switches inference loading to TrainablePolicy.from_pretrained + pipeline loading.
examples/qwen_gr00t/conf/train/qwen_gr00t.yaml Updates config layout (action head type, prompt_template, normalization_mapping, resume_from comment).
examples/qwen_gr00t/conf/serve/qwen_gr00t.yaml Adds rename-map and serve-time preprocessor (image resize) example.
.github/workflows/unit_tests_common.yml Installs added deps for unit tests (incl. datasets).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread flagscale/train/utils/train_utils.py
Comment thread flagscale/models/vla/registry.py
Comment on lines +534 to +543
# Advance the dataloader iterator to the correct position. The data
# ordering is deterministic from the DistributedSampler's own seed
# (not the global RNG), so calling next() `step` times moves the
# cursor to the right batch. We save/restore the global RNG around
# this so the fast-forward's incidental RNG consumption is discarded
# and training resumes with the exact RNG state from the checkpoint.
saved_rng = serialize_rng_state()
# TODO: (yupu) Maybe save/restore the dataloader state?
for _ in range(step):
next(dl_iter)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: will support dataloader resume in the nex PR

Comment thread flagscale/train/train_qwen_gr00t.py Outdated
Comment thread flagscale/serve/run_serve_qwen_gr00t.py
legitnull and others added 6 commits March 19, 2026 20:30
Unstaged debug additions and config changes for 0% eval investigation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove `torch.device("meta")` context in VLM model loading and the
corresponding `to_empty` materialization in `from_pretrained`. Meta
device init leaves non-persistent buffers (inv_freq in rotary
embeddings) as zeros since they are not saved in safetensors, causing
garbage VLM outputs and 0% eval success.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Caozhou1995 Caozhou1995 merged commit cbc199b into flagos-ai:main Mar 25, 2026
4 checks passed
LiJunscs pushed a commit to LiJunscs/FlagScale that referenced this pull request Apr 13, 2026
### PR Category
<!-- One of [ Train | Inference | Compress | Serve | RL | Core |
Hardware | CICD | Tools | Others ] -->
Train
### PR Types
<!-- One of [ User Experience | New Features | Bug Fixes | Improvements
| Performance | Breaking Change| Deprecations | Test Case | Docs |
Others ] -->
Improvements
### PR Description
<!-- Describe what you’ve done -->
  - Refactor to use standard `from_pretrained`, `save_pretrained` api
- Reorganize qwen_gr00t into proper subpackage (qwen_gr00t/,
vlm/qwenvl_backbone)
- Add FSDP2 checkpoint resume support (model, optimizer, scheduler, RNG
state)
  - vla serving script now supports arbitrary observation key names

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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.

4 participants