How does number of workers in pytorch actually work?












3















1- If num_workers is 2, Does that mean that it will put 2 batches in the RAM and send 1 of them to the GPU or Does it put 3 batches in the RAM then sends 1 of them to the GPU?

2- What does actually happen when the number of workers is higher than the number of CPU cores? I tried it and it worked fine but How does it work?(I thought that the maximum number of workers I can choose is the number of cores)

3- If I set num_workers to 3 and during the training there were no batches in the memory for the GPU, Does the main process waits for its workers to read the batches or Does it read a single batch(without waiting for the workers)?










share|improve this question





























    3















    1- If num_workers is 2, Does that mean that it will put 2 batches in the RAM and send 1 of them to the GPU or Does it put 3 batches in the RAM then sends 1 of them to the GPU?

    2- What does actually happen when the number of workers is higher than the number of CPU cores? I tried it and it worked fine but How does it work?(I thought that the maximum number of workers I can choose is the number of cores)

    3- If I set num_workers to 3 and during the training there were no batches in the memory for the GPU, Does the main process waits for its workers to read the batches or Does it read a single batch(without waiting for the workers)?










    share|improve this question



























      3












      3








      3


      0






      1- If num_workers is 2, Does that mean that it will put 2 batches in the RAM and send 1 of them to the GPU or Does it put 3 batches in the RAM then sends 1 of them to the GPU?

      2- What does actually happen when the number of workers is higher than the number of CPU cores? I tried it and it worked fine but How does it work?(I thought that the maximum number of workers I can choose is the number of cores)

      3- If I set num_workers to 3 and during the training there were no batches in the memory for the GPU, Does the main process waits for its workers to read the batches or Does it read a single batch(without waiting for the workers)?










      share|improve this question
















      1- If num_workers is 2, Does that mean that it will put 2 batches in the RAM and send 1 of them to the GPU or Does it put 3 batches in the RAM then sends 1 of them to the GPU?

      2- What does actually happen when the number of workers is higher than the number of CPU cores? I tried it and it worked fine but How does it work?(I thought that the maximum number of workers I can choose is the number of cores)

      3- If I set num_workers to 3 and during the training there were no batches in the memory for the GPU, Does the main process waits for its workers to read the batches or Does it read a single batch(without waiting for the workers)?







      pytorch






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 1 at 19:37







      floyd

















      asked Jan 1 at 19:23









      floydfloyd

      221111




      221111
























          1 Answer
          1






          active

          oldest

          votes


















          3















          1. When num_workers>0, only these workers will retrieve data, main process won't. So when num_workers=2 you have at most 2 workers simultaneously putting data into RAM, not 3.

          2. Well our CPU can usually run like 100 processes without trouble and these worker processes aren't special in anyway, so having more workers than cpu cores is ok. But is it efficient? it depends on how busy your cpu cores are for other tasks, speed of cpu, speed of your hard disk etc. In short, its complicated, so setting workers to number of cores is like good rule of thumb, nothing more.

          3. Nope. Remember DataLoader doesn't just randomly return from what's available in RAM right now, it uses batch_sampler to decide which batch to return next. Each batch is assigned to a worker, and main process will wait until the desired batch is retrieved by assigned worker.


          Lastly to clarify, it isn't DataLoader's job to send anything directly to GPU, you explicitly call cuda() for that, or modify Dataset's __getitem__() method.






          share|improve this answer


























          • Thank you so much. that was really really helpful

            – floyd
            Jan 2 at 12:36











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998282%2fhow-does-number-of-workers-in-pytorch-actually-work%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3















          1. When num_workers>0, only these workers will retrieve data, main process won't. So when num_workers=2 you have at most 2 workers simultaneously putting data into RAM, not 3.

          2. Well our CPU can usually run like 100 processes without trouble and these worker processes aren't special in anyway, so having more workers than cpu cores is ok. But is it efficient? it depends on how busy your cpu cores are for other tasks, speed of cpu, speed of your hard disk etc. In short, its complicated, so setting workers to number of cores is like good rule of thumb, nothing more.

          3. Nope. Remember DataLoader doesn't just randomly return from what's available in RAM right now, it uses batch_sampler to decide which batch to return next. Each batch is assigned to a worker, and main process will wait until the desired batch is retrieved by assigned worker.


          Lastly to clarify, it isn't DataLoader's job to send anything directly to GPU, you explicitly call cuda() for that, or modify Dataset's __getitem__() method.






          share|improve this answer


























          • Thank you so much. that was really really helpful

            – floyd
            Jan 2 at 12:36
















          3















          1. When num_workers>0, only these workers will retrieve data, main process won't. So when num_workers=2 you have at most 2 workers simultaneously putting data into RAM, not 3.

          2. Well our CPU can usually run like 100 processes without trouble and these worker processes aren't special in anyway, so having more workers than cpu cores is ok. But is it efficient? it depends on how busy your cpu cores are for other tasks, speed of cpu, speed of your hard disk etc. In short, its complicated, so setting workers to number of cores is like good rule of thumb, nothing more.

          3. Nope. Remember DataLoader doesn't just randomly return from what's available in RAM right now, it uses batch_sampler to decide which batch to return next. Each batch is assigned to a worker, and main process will wait until the desired batch is retrieved by assigned worker.


          Lastly to clarify, it isn't DataLoader's job to send anything directly to GPU, you explicitly call cuda() for that, or modify Dataset's __getitem__() method.






          share|improve this answer


























          • Thank you so much. that was really really helpful

            – floyd
            Jan 2 at 12:36














          3












          3








          3








          1. When num_workers>0, only these workers will retrieve data, main process won't. So when num_workers=2 you have at most 2 workers simultaneously putting data into RAM, not 3.

          2. Well our CPU can usually run like 100 processes without trouble and these worker processes aren't special in anyway, so having more workers than cpu cores is ok. But is it efficient? it depends on how busy your cpu cores are for other tasks, speed of cpu, speed of your hard disk etc. In short, its complicated, so setting workers to number of cores is like good rule of thumb, nothing more.

          3. Nope. Remember DataLoader doesn't just randomly return from what's available in RAM right now, it uses batch_sampler to decide which batch to return next. Each batch is assigned to a worker, and main process will wait until the desired batch is retrieved by assigned worker.


          Lastly to clarify, it isn't DataLoader's job to send anything directly to GPU, you explicitly call cuda() for that, or modify Dataset's __getitem__() method.






          share|improve this answer
















          1. When num_workers>0, only these workers will retrieve data, main process won't. So when num_workers=2 you have at most 2 workers simultaneously putting data into RAM, not 3.

          2. Well our CPU can usually run like 100 processes without trouble and these worker processes aren't special in anyway, so having more workers than cpu cores is ok. But is it efficient? it depends on how busy your cpu cores are for other tasks, speed of cpu, speed of your hard disk etc. In short, its complicated, so setting workers to number of cores is like good rule of thumb, nothing more.

          3. Nope. Remember DataLoader doesn't just randomly return from what's available in RAM right now, it uses batch_sampler to decide which batch to return next. Each batch is assigned to a worker, and main process will wait until the desired batch is retrieved by assigned worker.


          Lastly to clarify, it isn't DataLoader's job to send anything directly to GPU, you explicitly call cuda() for that, or modify Dataset's __getitem__() method.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered Jan 2 at 6:33









          Shihab ShahriarShihab Shahriar

          1,392714




          1,392714













          • Thank you so much. that was really really helpful

            – floyd
            Jan 2 at 12:36



















          • Thank you so much. that was really really helpful

            – floyd
            Jan 2 at 12:36

















          Thank you so much. that was really really helpful

          – floyd
          Jan 2 at 12:36





          Thank you so much. that was really really helpful

          – floyd
          Jan 2 at 12:36




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998282%2fhow-does-number-of-workers-in-pytorch-actually-work%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          The term 'EXEC' is not recognized as the name of a cmdlet Powershell

          NPM command prompt closes immediately [closed]

          Error binding properties and functions in emscripten