Memory Consumption Issues with Dataloader2 using Reading Service in Torch DataPipe

priyansh_sharma: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/f/0f124c6c88968b25c888ca5ce86cae87454803bb.png" data-download-href="https://discuss.pytorch.org/uploads/default/0f124c6c88968b25c888ca5ce86cae87454803bb" title="Screenshot 2023-09-28 at 12.57.53 AM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/f/0f124c6c88968b25c888ca5ce86cae87454803bb_2_140x500.png" alt="Screenshot 2023-09-28 at 12.57.53 AM" data-base62-sha1="29kmIK9Iea6bFzyURw3mNoKCrmb" width="140" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/f/0f124c6c88968b25c888ca5ce86cae87454803bb_2_140x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/0/f/0f124c6c88968b25c888ca5ce86cae87454803bb_2_210x750.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/0/f/0f124c6c88968b25c888ca5ce86cae87454803bb_2_280x1000.png 2x" data-dominant-color="F0F1F0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot 2023-09-28 at 12.57.53 AM</span><span class="informations">628×2234 50.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Hello,<br>
I am currently working on training a segmentation model and have incorporated Torch DataPipe into my pipeline(Please refer the above pipeline graph). I am using Dataloader2 at the end of this pipeline and have observed some peculiar behavior with and without the multiprocessing reading service. I’d appreciate some insights and guidance on the correct usage and potential solutions.</p>
<p>Note: I am using single GPU for training.<br>
TorchData version: 0.6.1</p>
<p>Case 1: With Reading Service</p>
<p>Memory Consumption: I’ve noticed a significant increase in memory consumption at each epoch(For example if the memory occupied in epoch-1 is around 25gb then at the starting of 2nd epoch it gets doubled to more than 50gbs and so on).This hike in the memory occupancy seems concerning to me.</p>
<p>Epoch Completion Time: The time taken for each epoch to complete is approximately 700 seconds.</p>
<p>Case 2: Without Reading Service**</p>
<p>Memory Consumption: The memory stabilizes after a certain point and does not show the same increase as observed in Case 1.(i.e the memory occupied in the first epoch does not doubles up but just remains somewhat constant throughout all epochs)<br>
Epoch Completion Time: The epoch completion time, however, doubles to around 1500 seconds.</p>
<p>Given these observations, I have a few questions:</p>
<ol>
<li>Correct Usage of Reading Services with Dataloader2: Is there a recommended or best-practice way to use the reading service with Dataloader2 to ensure efficient memory usage without compromising too much on speed?</li>
<li>Usage of initialize_iteration() and finalize() Methods: I’ve come across the initialize_iteration() and finalize() methods that can be used at the beginning and end of each epoch, respectively. I am not sure if these could solve the above problem, if yes can someone provide guidance or examples on how to correctly implement these methods in the context of Dataloader2 and Torch DataPipe?</li>
</ol>
<p>I’d be grateful for any insights, suggestions, or references to relevant documentation or threads that might help address these issues. Thank you in advance for your time and assistance!</p>
<p>Best regards,<br>
Priyanshu</p>

priyansh_sharma: <p>Hello,</p>
<p><a class="mention" href="/u/nivek">@nivek</a> <a class="mention" href="/u/ptrblck">@ptrblck</a> <a class="mention" href="/u/ejguan">@ejguan</a> I’ve noticed your contributions in related threads and was hoping you might have some insights or could point me in the right direction, against the above issue(<a href="https://discuss.pytorch.org/t/memory-consumption-issues-with-dataloader2-using-reading-service-in-torch-datapipe/189065" class="inline-onebox">Memory Consumption Issues with Dataloader2 using Reading Service in Torch DataPipe</a>).</p>
<p>Thanks</p>