-
Notifications
You must be signed in to change notification settings - Fork 24
Delete DCP saved checkpoints used for weight sync #210
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a51dc22
start dcp delete
allenwang28 23f3f50
Merge branch 'main' into dcp_delete
allenwang28 cb55ef4
delete old DCP ckpts
allenwang28 f84db49
does this fix tyro for ci?
allenwang28 a3f3ee4
add titan to unit test installs
allenwang28 62cbe78
torchtitan head?
allenwang28 33d1d22
?
allenwang28 26bf167
a
allenwang28 64828a7
a
allenwang28 5b1f6db
b
allenwang28 df7124c
c
allenwang28 ba347ad
d
allenwang28 12bd2f7
n-1 and current
allenwang28 b844e0b
merge
allenwang28 6d4ca2a
comment
allenwang28 c945e9c
remove ref actor test for now
allenwang28 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 |
---|---|---|
|
@@ -32,6 +32,10 @@ jobs: | |
eval "$(ssh-agent -s)" | ||
ssh-add - <<< '${{ secrets.FORGE_GITHUB_CI_FOR_TORCHSTORE }}' | ||
python -m pip install git+ssh://[email protected]/meta-pytorch/torchstore.git | ||
- name: Install torchtitan | ||
run: | | ||
pip install --pre torchtitan==0.1.0.dev20250826+cpu --extra-index-url https://download.pytorch.org/whl/nightly/cpu | ||
pip install tyro | ||
- name: Install dependencies | ||
run: python -m pip install --no-build-isolation -e ".[dev]" | ||
- name: Run unit tests with coverage | ||
|
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 |
---|---|---|
|
@@ -193,3 +193,6 @@ cover/ | |
wandb/ | ||
|
||
assets/wheels/vllm*.whl | ||
|
||
# DCP artifacts | ||
model_state_dict/ |
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
This file was deleted.
Oops, something went wrong.
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,102 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
import os | ||
import shutil | ||
import tempfile | ||
import unittest | ||
|
||
from forge.actors.trainer import cleanup_old_weight_versions | ||
|
||
|
||
class TestTrainerUtilities(unittest.TestCase): | ||
def setUp(self): | ||
"""Set up test environment with temporary directory.""" | ||
self.test_dir = tempfile.mkdtemp() | ||
self.addCleanup(shutil.rmtree, self.test_dir) | ||
|
||
def test_cleanup_old_weight_versions_basic(self): | ||
"""Test basic cleanup functionality - keeps current and N-1 versions.""" | ||
# Create test directory structure | ||
state_dict_key = os.path.join(self.test_dir, "model") | ||
delim = "__" | ||
|
||
# Create some mock weight directories | ||
old_version_1 = f"{state_dict_key}{delim}1" | ||
previous_version = f"{state_dict_key}{delim}2" # N-1 version | ||
current_version = f"{state_dict_key}{delim}3" # Current version | ||
unrelated_dir = os.path.join(self.test_dir, "other_model__1") | ||
|
||
for dir_path in [ | ||
old_version_1, | ||
previous_version, | ||
current_version, | ||
unrelated_dir, | ||
]: | ||
os.makedirs(dir_path) | ||
|
||
# Run cleanup for version 3 | ||
cleanup_old_weight_versions( | ||
state_dict_key=state_dict_key, | ||
delim=delim, | ||
current_policy_version=3, | ||
) | ||
|
||
# Check that only very old versions were deleted (version 1) | ||
self.assertFalse(os.path.exists(old_version_1)) | ||
|
||
# Check that current and previous versions still exist | ||
self.assertTrue(os.path.exists(previous_version)) # N-1 version should remain | ||
self.assertTrue( | ||
os.path.exists(current_version) | ||
) # Current version should remain | ||
self.assertTrue(os.path.exists(unrelated_dir)) # Unrelated dirs should remain | ||
|
||
def test_cleanup_old_weight_versions_no_cleanup_version_1(self): | ||
"""Test that no cleanup happens when current_policy_version <= 1.""" | ||
# Create test directory structure | ||
state_dict_key = os.path.join(self.test_dir, "model") | ||
delim = "__" | ||
|
||
version_1 = f"{state_dict_key}{delim}1" | ||
os.makedirs(version_1) | ||
|
||
# Run cleanup for version 1 - should do nothing | ||
cleanup_old_weight_versions( | ||
state_dict_key=state_dict_key, | ||
delim=delim, | ||
current_policy_version=1, | ||
) | ||
|
||
# Version 1 should still exist | ||
self.assertTrue(os.path.exists(version_1)) | ||
|
||
def test_cleanup_old_weight_versions_version_2(self): | ||
"""Test cleanup with version 2 as current - should keep versions 1 and 2.""" | ||
# Create test directory structure | ||
state_dict_key = os.path.join(self.test_dir, "model") | ||
delim = "__" | ||
|
||
version_1 = f"{state_dict_key}{delim}1" # N-1 version | ||
version_2 = f"{state_dict_key}{delim}2" # Current version | ||
|
||
for dir_path in [version_1, version_2]: | ||
os.makedirs(dir_path) | ||
|
||
# Run cleanup for version 2 | ||
cleanup_old_weight_versions( | ||
state_dict_key=state_dict_key, | ||
delim=delim, | ||
current_policy_version=2, | ||
) | ||
|
||
# Both versions should still exist (no deletion for version 2) | ||
self.assertTrue(os.path.exists(version_1)) | ||
self.assertTrue(os.path.exists(version_2)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.
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.
How do we know the policy isn't currently reading from these weights?
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.
I think cleanup belongs to Policy since the Policy actor will know if an earlier version is still needed.
We can implement cleanup as an endpoint of Policy and we call it in the main loop to make sure everything is in sync.
(Later) once we figure out how to make the policy actors talk to each other after update_weights we can potentially move it to the inside of policy and do it automatically.
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.
HMM yeah good point. I think this requires more consideration. I don't want to introduce some tracking at this moment, maybe a fragile heuristic we can go with is "don't delete the last 2" since we're not going off policy more than 1? Can follow up more with #194 wdyt
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.
Sounds good. add the heuristics now just to make sure nothing breaks and we can add proper evict logic 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.
ok done!