-
Notifications
You must be signed in to change notification settings - Fork 62
Initialize weights before parallelization #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
puigde
wants to merge
3
commits into
fla-org:main
Choose a base branch
from
puigde:fix/init-before-parallelize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "model_type": "rwkv7", | ||
| "hidden_size": 1024, | ||
| "num_hidden_layers": 24, | ||
| "head_dim": 64, | ||
| "hidden_ratio": 4, | ||
| "hidden_act": "sqrelu", | ||
| "vocab_size": 32000, | ||
| "decay_low_rank_dim": 64, | ||
| "gate_low_rank_dim": 128, | ||
| "a_low_rank_dim": 64, | ||
| "v_low_rank_dim": 16, | ||
| "tie_word_embeddings": false, | ||
| "fuse_cross_entropy": true, | ||
| "fuse_norm": true, | ||
| "use_l2warp": false, | ||
| "attn_mode": "chunk", | ||
| "bos_token_id": 1, | ||
| "eos_token_id": 2 | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving
to_empty()andpost_init()beforeparallelize_fn()introduces a significant memory risk for large models. In the non-pipeline-parallel path, this causes the entire model to be materialized on theinit_device(typically GPU) for every rank before FSDP or Tensor Parallelism can shard the parameters.\n\nFor models that are larger than a single GPU's memory (e.g., 70B+ models on 80GB GPUs), this will lead to an immediate Out-Of-Memory (OOM) error during initialization. The previous order was more memory-efficient as it allowed FSDP to create sharded meta-tensors that were materialized only as shards.\n\nWhile this change fixes the.data=assignment issue for specific models like RWKV-7, it regresses the scalability of the training script. If this behavior is necessary for specific models, consider making it optional or ensuringinit_deviceis set to'cpu'when training very large models.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The largest config in the repo is 7B (28 GB in fp32 at init, since FSDP's bf16 casting applies after parallelization). For FSDP-only setups the threshold where init OOMs is >10B params on 40GB GPUs or >20B on 80GB GPUs, below current flame model range. For larger scales, init_device="cpu" (already supported in train.py) is a straightforward fallback with minimal overhead (measured 5s at 7B vs. hours of training, see updated comment in code).