Open kozlov721 opened 2 months ago
That's a bug in torch's dataloader, or in your way of calling it. They fork the process with multiprocessing, which is outright dangerous. As they confirm in their docs:
https://pytorch.org/docs/stable/notes/multiprocessing.html#avoiding-and-fighting-deadlocks
There are a lot of things that can go wrong when a new process is spawned, with the most common cause of deadlocks being background threads. If there’s any thread that holds a lock or imports a module, and fork is called, it’s very likely that the subprocess will be in a corrupted state and will deadlock or fail in a different way. Note that even if you don’t, Python built in libraries do - no need to look further than [multiprocessing](https://docs.python.org/3/library/multiprocessing.html#module-multiprocessing). [multiprocessing.Queue](https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Queue) is actually a very complex class, that spawns multiple threads used to serialize, send and receive objects, and they can cause aforementioned problems too. If you find yourself in such situation try using a SimpleQueue, that doesn’t use any additional threads.
We’re trying our best to make it easy for you and ensure these deadlocks don’t happen but some things are out of our control. If you have any issues you can’t cope with for a while, try reaching out on forums, and we’ll see if it’s an issue we can fix.
It is also written in our user guide: https://docs.pola.rs/user-guide/misc/multiprocessing/
TL,DR: if a library/user forks a process when there is any other library in the process that has a mutex, it is a logical bug!
Thanks for the response. I was confused because the above snippet works just fine when I replace polars
with pandas
so I assumed there's a bug in polars
somewhere.
Checks
Reproducible example
Log output
Issue description
When
polars.DataFrame
is used insidetorch.utils.data.DataLoader
withnum_workers
set to a non-zero value, theDataFrame.filter
method freezes.The version of
torch
used isv2.3.0
.Expected behavior
DataFrame.filter
should not freeze when used intorch.utils.data.DataLoader
with non-zero number of workers.Installed versions