Skip to content

[draft] snippet for shardedtensor to dtensor conversion #3337

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion composer/utils/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,16 @@ def _restore_checkpoint(
# Ensure state exists
state_dict['state'] = state_dict.get('state', {})
log.debug(f"Loaded checkpoint with keys {state_dict.keys()} and state keys {state_dict['state'].keys()}")

from torch.distributed._tensor import DeviceMesh, DTensor, Placement, Shard
from torch.distributed._shard.sharded_tensor import ShardedTensor
for k, v in state_dict['state']['model'].items():
if isinstance(v, ShardedTensor):
dtensor = DTensor.from_local(
v.local_tensor(),
device_mesh=,#get device mesh from state.model,
placements=,#get device mesh placements from state.model,
run_check=False,)
state_dict['state']['model'][k] = torch.nn.Parameter(dtensor)
if is_model_deepspeed(state.model):
if extracted_checkpoint_folder is None:
raise RuntimeError('Deepspeed checkpoints require a tarball, not a weights file.')
Expand Down
Loading