Shm error in docker

qzying: <p>When I run pytorch in docker, there is an error as follows. And I check the path of shm is fixed in the source code, “/torch_XXX”. So is there any way that I can change the shm path without compile the source code? Or just close the shm in python?</p>
<p><strong>ERROR: Unexpected bus error encountered in worker. This might be caused by insufficient shared memory (shm).</strong><br>
<strong>ERROR: Unexpected bus error encountered in worker. This might be caused by insufficient shared memory (shm).</strong><br>
<strong>ERROR: Unexpected bus error encountered in worker. This might be caused by insufficient shared memory (shm).</strong><br>
<strong>ERROR: Unexpected bus error encountered in worker. This might be caused by insufficient shared memory (shm).</strong><br>
<strong>ERROR: Unexpected bus error encountered in worker. This might be caused by insufficient shared memory (shm).</strong><br>
<strong>ERROR: Unexpected bus error encountered in worker. This might be caused by insufficient shared memory (shm).</strong><br>
<strong>ERROR: Unexpected bus error encountered in worker. This might be caused by insufficient shared memory (shm).</strong><br>
<strong>ERROR: Unexpected bus error encountered in worker. This might be caused by insufficient shared memory (shm).</strong><br>
<strong>Process Process-3:</strong><br>
<strong>Traceback (most recent call last):</strong><br>
**  File “pytorch/main.py”, line 205, in **<br>
**    main()**<br>
**  File “pytorch/main.py”, line 116, in main**<br>
**    train(train_loader, model, criterion, optimizer, epoch)**<br>
**  File “pytorch/main.py”, line 136, in train**<br>
**    for i, (input, target) in enumerate(train_loader):**<br>
**  File “/usr/local/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py”, line 286, in <strong>next</strong>**<br>
**    return self._process_next_batch(batch)**<br>
**  File “/usr/local/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py”, line 307, in _process_next_batch**<br>
**    raise batch.exc_type(batch.exc_msg)**<br>
<strong>RuntimeError: Traceback (most recent call last):</strong><br>
**  File “/usr/local/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py”, line 57, in _worker_loop**<br>
**    samples = collate_fn([dataset[i] for i in batch_indices])**<br>
**  File “/usr/local/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py”, line 138, in default_collate**<br>
**    return [default_collate(samples) for samples in transposed]**<br>
**  File “/usr/local/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py”, line 138, in **<br>
**    return [default_collate(samples) for samples in transposed]**<br>
**  File “/usr/local/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py”, line 113, in default_collate**<br>
**    storage = batch[0].storage()._new_shared(numel)**<br>
**  File “/usr/local/anaconda3/lib/python3.6/site-packages/torch/storage.py”, line 114, in _new_shared**<br>
**    return cls._new_using_filename(size)**<br>
<strong>RuntimeError: unable to write to file &lt;/torch_76_3625483894&gt; at /pytorch/aten/src/TH/THAllocator.c:383</strong></p>
<p><strong>Error in atexit._run_exitfuncs:</strong><br>
<strong>Traceback (most recent call last):</strong><br>
**  File “/usr/local/anaconda3/lib/python3.6/multiprocessing/popen_fork.py”, line 35, in poll**<br>
**    pid, sts = os.waitpid(self.pid, flag)**<br>
**  File “/usr/local/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py”, line 178, in handler**<br>
**    _error_if_any_worker_fails()**<br>
<strong>RuntimeError: DataLoader worker (pid 87) is killed by signal: Bus error.</strong></p>

ptrblck: <p>Could you try to start your docker container with <code>--ipc=host</code>?<br>
From the <a href="https://github.com/pytorch/pytorch#docker-image">github doc</a>:</p>
<blockquote>
<p>Please note that PyTorch uses shared memory to share data between processes, so if torch multiprocessing is used (e.g. for multithreaded data loaders) the default shared memory segment size that container runs with is not enough, and you should increase shared memory size either with --ipc=host or --shm-size command line options to nvidia-docker run.</p>
</blockquote>

qzying: <p>For the security, it is not allowed to add “–ipc=host” in our company.<br>
So if I can change the path of shm from /torch_XXX to /cahe in pytorch without source code?<br>
The path is fixed in the source as follows:</p>
<p><span class="hashtag">#ifndef</span> THC_GENERIC_FILE<br>
// TODO: move this somewhere - we only need one version<br>
static std::string THPStorage_(_<em>newHandle)() {<br>
static std::random_device rd;<br>
std::string handle = "/torch</em>";<br>
<span class="hashtag">#ifdef</span> <em>MSC_VER<br>
handle += std::to_string(GetCurrentProcessId());<br>
<span class="hashtag">#else</span><br>
handle += std::to_string(getpid());<br>
<span class="hashtag">#endif</span><br>
handle += "</em>";<br>
handle += std::to_string(rd());<br>
return handle;<br>
}</p>

ptrblck: <p>What about setting <code>--shm-size</code>? Would that be allowed in your company?</p>

qzying: <p>Yeah, but the size can not be too large <img src="https://discuss.pytorch.org/images/emoji/apple/joy.png?v=5" title=":joy:" class="emoji" alt=":joy:"><br>
Maybe it is better if I can change the path.</p>

immuaz: <p>Hey, could you find solution to it?</p>

RachelGomez161999: <p>General troubleshooting steps<br>
Check the logs: The logs are the first place to look.<br>
Restart Docker Desktop: Restarting the Docker Desktop often resolves an issue.<br>
Clean mapped volume data: If your containers use mapped volumes for persistent storage, your issue can be come from stale data in these folders.</p>
<p>Regards,<br>
Rachel Gomez</p>