Skip to content

[WIP] [CUDA] fsdp#3768

Draft
nastya236 wants to merge 1 commit into
mainfrom
fsdp2
Draft

[WIP] [CUDA] fsdp#3768
nastya236 wants to merge 1 commit into
mainfrom
fsdp2

Conversation

@nastya236

Copy link
Copy Markdown
Collaborator

FSDP

Usage [it is questionable]:

dtype = mx.bfloat16
for i, layer in enumerate(model.layers):
    model.layers[i] = fully_shard(layer, group=groups["fsdp"], cast_dtype=dtype)
model.embed_tokens = fully_shard(model.embed_tokens, group=groups["fsdp"], cast_dtype=dtype)

The difference in peak memory is exactly as expected 14 GB [4B * 4 = 16GB -- master copy weights, therefore each rank holds only 16GB / 8 =2 GB 2 instead of 16GB].

It is incomplete, because bf16 weights that are gathered during forward are not resharded and used in backward. So we can cut another ~6GB by resharding and gathering back during backward.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant