Skip to content
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

Fix ci 2 #31

Open
wants to merge 3 commits into
base: feat-fsdp-diloco
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion open_diloco/simulate_multi_node.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mkdir -p logs
for i in $(seq 0 $(($N - 1 )))
do
> logs/log$i
CUDA_VISIBLE_DEVICES=$(get_cuda_devices $NUM_GPU $i) uv run torchrun --nproc_per_node=$NUM_GPU --node-rank $i --rdzv-endpoint localhost:9999 --nnodes=$N $@ > logs/log$i 2>&1 &
CUDA_VISIBLE_DEVICES=$(get_cuda_devices $NUM_GPU $i) torchrun --nproc_per_node=$NUM_GPU --node-rank $i --rdzv-endpoint localhost:9999 --nnodes=$N $@ > logs/log$i 2>&1 &
child_pids+=($!)
done

Expand Down
20 changes: 12 additions & 8 deletions open_diloco/train_pure_fsdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@

cpu_model = get_offloaded_param(
model
) # todo: in case of sharded grap op we need to offload the cpu model only once per nodes

Check failure on line 170 in open_diloco/train_pure_fsdp.py

View workflow job for this annotation

GitHub Actions / codespell

grap ==> grep, grape
outer_optimizer = torch.optim.SGD(cpu_model, lr=config.diloco.outer_lr, momentum=0.9, nesterov=True)

# for param in outer_optimizer.param_groups[0]["params"]:
Expand Down Expand Up @@ -240,14 +240,18 @@
for param_offloaded, param in zip(cpu_model, model.parameters()):
# todo check how to handle the SHARD_GRAD_OP strategy where the weight are replicated across the local devices
param_offloaded.grad = param_offloaded.data - param.data.to(param_offloaded.device)

if param_offloaded.grad.device == torch.device("cpu"):
# gloo does not support AVG
param_offloaded.grad = param_offloaded.grad / global_pg.size()
dist.all_reduce(param_offloaded.grad, op=dist.ReduceOp.SUM, group=global_pg)
else:
dist.all_reduce(param_offloaded.grad, op=dist.ReduceOp.AVG, group=global_pg)


mask = torch.rand_like(param_offloaded.grad) > 0.95

data_to_send = param_offloaded.grad * mask
data_to_send_pre_reduce = data_to_send.clone()

# gloo does not support AVG
data_to_send = data_to_send / global_pg.size()
dist.all_reduce(data_to_send, op=dist.ReduceOp.SUM, group=global_pg)

param_offloaded.grad += data_to_send - data_to_send_pre_reduce # removing the

outer_optimizer.step()
outer_optimizer.zero_grad()

Expand Down
Loading