Skip to content

[WIP] [CUDA] fsdp#3768

Open
nastya236 wants to merge 3 commits into
mainfrom
fsdp2
Open

[WIP] [CUDA] fsdp#3768
nastya236 wants to merge 3 commits into
mainfrom
fsdp2

Conversation

@nastya236

@nastya236 nastya236 commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Fully sharded data parallel.

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

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

Peak memory difference between sharded optimizer and this PR is 14 GB [4B * 4 = 16GB -- master copy weights, therefore each rank holds only 16GB / 8 =2 GB 2 instead of 16GB] as expected.

@nastya236 nastya236 marked this pull request as ready for review July 12, 2026 17:55
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