[Train] Support FSDP2 checkpoint resume#1149
Merged
Caozhou1995 merged 28 commits intoMar 25, 2026
Merged
Conversation
8e092a4 to
7504c21
Compare
Contributor
There was a problem hiding this comment.
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.safetensorslayout, plustraining_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 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) |
Collaborator
Author
There was a problem hiding this comment.
todo: will support dataloader resume in the nex PR
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>
…to qwen_gr00t_fix_lerobot_adapt
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Category
Train
PR Types
Improvements
PR Description
from_pretrained,save_pretrainedapi