# Synchronization for sharing/updating shared model state dict across multi-process

**URL:** <https://discuss.pytorch.org/t/synchronization-for-sharing-updating-shared-model-state-dict-across-multi-process/50102>\
**Category:** reinforcement-learning\
**Created:** [July 9, 2019, 9:59am UTC](https://discuss.pytorch.org/t/synchronization-for-sharing-updating-shared-model-state-dict-across-multi-process/50102 "2019-07-09T09:59:35Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![neoql](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/n/0ea827/32.png) [@neoql](https://discuss.pytorch.org/u/neoql)\
**Post date:** [October 6, 2020, 2:09pm UTC](https://discuss.pytorch.org/t/synchronization-for-sharing-updating-shared-model-state-dict-across-multi-process/50102/4 "2020-10-06T14:09:57Z")

</div>

I found a possible answer. @Yanzzzzz @wwiiiii

> [@Grad sharing problem in a3c](https://discuss.pytorch.org/t/grad-sharing-problem-in-a3c/10635/2):
>
> yeah it really there just to make sure initializing goes smoothly. async updates without locks mean they updates from the parallel processes are done asynchronously which means they are run on their own clock and the different process threads can actually make updates at the same time which can lead to bad updates. The reason they do this even though there is risk of bad updates being made is that updates are done much faster which speeds up training as the process of acquiring and releasing lo…

And I found another related answer

> [@Model update with "share\_memory" need lock protection](https://discuss.pytorch.org/t/model-update-with-share-memory-need-lock-protection/72857):
>
> TL;DR. Maybe a lock is needed for optimizer.step() while using multiprocessing. The example provided in [MULTIPROCESSING BEST PRACTICES] ([https://pytorch.org/docs/stable/notes/multiprocessing.html](https://pytorch.org/docs/stable/notes/multiprocessing.html)) is to update parameters without lock protection. import torch.multiprocessing as mp from model import MyModel def train(model): # Construct data\_loader, optimizer, etc. for data, labels in data\_loader: optimizer.zero\_grad() loss\_fn(model(data), labels).backward() o…

---

_[View the full topic](https://discuss.pytorch.org/t/synchronization-for-sharing-updating-shared-model-state-dict-across-multi-process/50102)._
