You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PyTorch: increasing --shm-size to allow multiprocessing data loaders #937
This is because /dev/shm is at only 64M by default. The solution to this seems to be simply passing --shm-size with a higher value to docker run but if one is using sagemaker that option isn't there.
I've extended the PyTorch container and added a bunch of custom packages and settings in the Dockerfile with no problem, but can't set runtime flags/args meant to be passed to docker run (Note: docker build has a --shm-size args but that is NOT related to the /dev/shm size of the final container).
This becomes a huge bottleneck since training is very slow with num_workers = 0. Can't we just increase the default shared memory? Or provide an easier way for users to set it using the sagemaker sdk?
Exact command to reproduce:
Any example using DataLoader with num_workers > 0.
Reacted by vfrap, Artem Kozhevnikov, Kurniawan Kurniawan, Steve Bian, Austin Welch, Louis Douge, Leo Gallucci, gladenjoy, Son Duong, Ray Wang and 7 more
If you're not using local mode then, in fact docker containers running in SageMaker training do NOT use the 64MB default shm-size - we adjust it depending on the instance type.
You didn't mention the instance type you're using, which is it? And how much is the max shared memory is your algorithm meant to use?
thanks for the clarification! So it seems that we would need to find a way to expose shm-size as an option that would then get written into the docker-compose.yml file that is used for local mode. I'll open up an item in our internal backlog, which we're always reprioritizing based on feedback.
some potentially helpful links for anyone wanting to take a stab at this:
Hi @laurenyu, yes thanks! In an ideal world, we could pass some kind of run_hyperparameters dictionary so that we can add any flag for docker run, but having shm-size is good enough.
just wondering if this issue is resolved. This feature will really make debugging much easier.
Reacted by Steve Bian, Barnabas Molnar, Austin Welch, Zhe Sun, Dayyan Smith, Vlad Vinogradov, Leo Gallucci, Elio Quinton, Ian Tait, Brent Foster and 3 more
As a workaround I found a solution to change the default parameters of the Docker daemon. May be suitable for those who have rights to change them:
Open this file in your editor:
sudo vim /etc/docker/daemon.json
Add option "default-shm-size": "13G" as mentioned in the Docker docs. You can specify another value, I just set 13Gb as I have 16Gb of RAM on my server.
Restart Docker daemon:
sudo systemctl restart docker
Reacted by Dayyan Smith, Roman Bogachev, Leo Gallucci, ivan-saptech, Elio Quinton, t-ibayashi-safie, waynema02, Arkar Min Aung, Rahul Damineni, longbowzhang and 4 more
Reacted by Rahul Damineni, longbowzhang, Artem Vasenin and silverdeguzman
As a workaround I found a solution to change the default parameters of the Docker daemon. May be suitable for those who have rights to change them:
Open this file in your editor:
sudo vim /etc/docker/daemon.json
Add option "default-shm-size": "13G" as mentioned in the Docker docs. You can specify another value, I just set 13Gb as I have 16Gb of RAM on my server.
Restart Docker daemon:
sudo systemctl restart docker
Thanks! This is the only valid solution to this issue in my case. Finally found your solution after a few hours of searching.
As a workaround I found a solution to change the default parameters of the Docker daemon. May be suitable for those who have rights to change them:
Open this file in your editor:
sudo vim /etc/docker/daemon.json
Add option "default-shm-size": "13G" as mentioned in the Docker docs. You can specify another value, I just set 13Gb as I have 16Gb of RAM on my server.
Restart Docker daemon:
sudo systemctl restart docker
Thanks! This is the only valid solution to this issue in my case. Finally found your solution after a few hours of searching.
@ivan-saptech will we able to deploy the same into sagemaker and the sagemaker endpoint will get the same shm-size configuration?
This is happening in sagemaker studio as well. Is there a way to adjust the studio settings?
Reacted by dylan-uys, gladenjoy, kazuki229, Kohecchi, David Krisiloff, Brent Foster, Patrick Facheris, Peter McT, Yashwanth Dannamaneni, Daniel Hoyos and 10 more
Impossible to train popular YOLOv5 models in studio with such low shared memory (64M). Launching a single Notebook instance makes it possible as shared memory on the instance I spun up was 32G (ml.g4dn.4xlarge). If your premier service of Studio is less capable than the older Notebooks this should be called out and or prioritised. I spent quite some time trying to work out how I could use Studio before I found this post and simply dumped it in favour of a Notebook.
Thank you for reaching out! The latest SageMaker Studio release now offers increased shared memory on instances running Studio Apps. The memory size scales in proportion to the size of the instance being used. Please update your Studio Apps as described here, to see these improvements.
I'm running this on AWS studio with a notebook and my own processing container.
#000Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 808, in _try_get_data
data = self._data_queue.get(timeout=timeout)
File "/opt/conda/lib/python3.6/queue.py", line 173, in get
self.not_empty.wait(remaining)
File "/opt/conda/lib/python3.6/threading.py", line 299, in wait
gotit = waiter.acquire(True, timeout)
File "/opt/conda/lib/python3.6/site-packages/torch/utils/data/_utils/signal_handling.py", line 66, in handler
_error_if_any_worker_fails()
RuntimeError: DataLoader worker (pid 193) is killed by signal: Bus error. It is possible that dataloader's workers are out of shared memory. Please try to raise your shared memory limit.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 388, in __next__
data = self._next_data()
File "/opt/conda/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 1003, in _next_data
idx, data = self._get_data()
File "/opt/conda/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 960, in _get_data
success, data = self._try_get_data()
File "/opt/conda/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 821, in _try_get_data
raise RuntimeError('DataLoader worker (pid(s) {}) exited unexpectedly'.format(pids_str))
RuntimeError: DataLoader worker (pid(s) 193) exited unexpectedly
Hello, is it possible to set the size of /dev/shm now for SageMaker training jobs? We're running into the same issue.
I'm also keen to have either higher or configurable shared memory limits. We are using SageMaker Training with PyTorch in a custom container and use shared memory to cache the whole dataset and therefore avoid returning to S3 every epoch. This works on ml.p4d.24xlarge but not ml.g5.48xlarge, where the process runs out of shared memory. I really want to have the whole of system RAM available for caching, like I would when running outside a container.
Activity
ChoiByungWook commentedon Jul 16, 2019
Hello @ksanjeevan,
Thanks for bringing this issue to our attention.
Let me reach out to the team that owns the training platform.
ishaaq commentedon Sep 5, 2019
Are you using local mode training?
If you're not using local mode then, in fact docker containers running in SageMaker training do NOT use the 64MB default shm-size - we adjust it depending on the instance type.
You didn't mention the instance type you're using, which is it? And how much is the max shared memory is your algorithm meant to use?
ksanjeevan commentedon Sep 5, 2019
Yeah this was using local mode, using remote seems to be fine.
laurenyu commentedon Sep 5, 2019
thanks for the clarification! So it seems that we would need to find a way to expose shm-size as an option that would then get written into the docker-compose.yml file that is used for local mode. I'll open up an item in our internal backlog, which we're always reprioritizing based on feedback.
some potentially helpful links for anyone wanting to take a stab at this:
ksanjeevan commentedon Sep 9, 2019
Hi @laurenyu, yes thanks! In an ideal world, we could pass some kind of
run_hyperparametersdictionary so that we can add any flag fordocker run, but havingshm-sizeis good enough.bill10 commentedon Feb 19, 2020
just wondering if this issue is resolved. This feature will really make debugging much easier.
austinmw commentedon Mar 24, 2020
This is how you can monkey patch the sagemaker SDK to enable multiprocessing in local mode:
Example SageMaker SDK location:
/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/sagemaker/local/image.py:@laurenyu any chance we could get a PR with an option like this?
VladVin commentedon Nov 2, 2020
Any updates? The feature would be usefull indeed for debugging locally
VladVin commentedon Nov 3, 2020
As a workaround I found a solution to change the default parameters of the Docker daemon. May be suitable for those who have rights to change them:
"default-shm-size": "13G"as mentioned in the Docker docs. You can specify another value, I just set 13Gb as I have 16Gb of RAM on my server.ivan-saptech commentedon Mar 19, 2021
Thanks! This is the only valid solution to this issue in my case. Finally found your solution after a few hours of searching.
arulbharathi commentedon Mar 24, 2021
@ivan-saptech will we able to deploy the same into sagemaker and the sagemaker endpoint will get the same shm-size configuration?
CC - @VladVin
lou-k commentedon May 19, 2021
This is happening in sagemaker studio as well. Is there a way to adjust the studio settings?
jacquesboitreaud commentedon Nov 3, 2021
This is also a bottleneck in the sagemaker processing jobs, where we cannot pass arguments to the
docker runcommand. Any way to fix this ?NeilJonkers commentedon Nov 3, 2021
For processing jobs there exists no workaround to set
--shm-sizeat the moment.bertocast commentedon Mar 20, 2022
Any updates on this?
lou-k commentedon Mar 21, 2022
I've raised the issue to the sagemaker studio team nearly a year ago, but they have not taken any action.
titanium-cranium commentedon Jul 3, 2022
Impossible to train popular YOLOv5 models in studio with such low shared memory (64M). Launching a single Notebook instance makes it possible as shared memory on the instance I spun up was 32G (ml.g4dn.4xlarge). If your premier service of Studio is less capable than the older Notebooks this should be called out and or prioritised. I spent quite some time trying to work out how I could use Studio before I found this post and simply dumped it in favour of a Notebook.
knikure commentedon Oct 3, 2022
Thank you for reaching out! The latest SageMaker Studio release now offers increased shared memory on instances running Studio Apps. The memory size scales in proportion to the size of the instance being used. Please update your Studio Apps as described here, to see these improvements.
Ajay-Reva commentedon Oct 11, 2022
@knikure What do I do when I run from the notebook? Because I'm facing the same issue with my processing job when running from the notebook.
Ajay-Reva commentedon Oct 11, 2022
I'm running this on AWS studio with a notebook and my own processing container.
thvasilo commentedon Jan 26, 2024
Hello, is it possible to set the size of
/dev/shmnow for SageMaker training jobs? We're running into the same issue.ntw-au commentedon Feb 16, 2024
I'm also keen to have either higher or configurable shared memory limits. We are using SageMaker Training with PyTorch in a custom container and use shared memory to cache the whole dataset and therefore avoid returning to S3 every epoch. This works on
ml.p4d.24xlargebut notml.g5.48xlarge, where the process runs out of shared memory. I really want to have the whole of system RAM available for caching, like I would when running outside a container.gui-miotto commentedon Sep 12, 2024
I solved my shared memory issues by setting
pin_memorytoTruein all dataloaders (train, valid, test, etc.)