fix IterableDataset may block model when num_workers > 0 #40541
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Bug fixes
PR changes
APIs
Describe
fix IterableDataset may block model when num_workers > 0
DataLoader
haspy_reader
andblocking_queue
after multi-process processing, blocking queue capacity is2 * num_workers
,which can store all prefetched data, so when_rcvd_idx
catch up_send_idx
, beside the situation that all data source drained, it can be all prefetch data stored in blocking queue to wait for network reading data. In this situation, thread ofDataLoader
should not occupy CPU time, simply let it go to_data_queue.get_data
,this method will blocking when_data_queue
do not have data, and CPU time can be used for model running.If use
continue
here,_rcvd_idx
and_send_idx
checking may keep looping, which may occupy CPU time for model running