Skip to content

Instantly share code, notes, and snippets.

@dasayan05
Created February 27, 2019 10:19
Show Gist options
  • Save dasayan05/c4f7ab5b6508eb1942ce661bf11497b2 to your computer and use it in GitHub Desktop.
Save dasayan05/c4f7ab5b6508eb1942ce661bf11497b2 to your computer and use it in GitHub Desktop.
Synchronize intial weights
def sync_initial_weights(model, rank, world_size):
for param in model.parameters():
if rank == 0:
# Rank 0 is sending it's own weight
# to all it's siblings (1 to world_size)
for sibling in range(1, world_size):
dist.send(param.data, dst=sibling)
else:
# Siblings must recieve the parameters
dist.recv(param.data, src=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment