-
Notifications
You must be signed in to change notification settings - Fork 16
factor out weight cleanup to separate file, also non-blocking now #292
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
7643064
e66efee
c8b2b42
73d233c
cee8d29
0b5edb7
19e5100
cf5dab5
5fe537f
e91f66c
d517a9a
90a2dba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 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 time | ||
|
||
import torchstore as ts | ||
|
||
from forge.actors._torchstore_utils import ( | ||
get_dcp_whole_state_dict_key, | ||
get_param_prefix, | ||
) | ||
|
||
|
||
async def drop_weights(version: int): | ||
|
||
print(f"Dropping weights @ version {version}") | ||
|
||
start_time = time.perf_counter() | ||
prefix = get_param_prefix(version) | ||
matching_keys = await ts.keys(prefix) | ||
# TODO: once we have something like `get_meta()` in torchstore, we can just | ||
# query the type of the object instead of relying on keys. | ||
dcp_key = get_dcp_whole_state_dict_key(version) | ||
if dcp_key in matching_keys: | ||
dcp_handle = await ts.get(dcp_key) | ||
dcp_handle.drop() | ||
for key in matching_keys: | ||
await ts.delete(key) | ||
elapsed = time.perf_counter() - start_time | ||
print(f"Dropped weights @ version {version}, took {elapsed:.2f} seconds") | ||
|
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.
Can this be truly async or does it have to be blocking like this?
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.
this can be truly async, if we just create a task and not await on it.