mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 20:44:00 +00:00
feat(python): default StreamingDataLoader workers to forkserver (#5112)
## Problem `StreamingDataLoader` left PyTorch's platform default in place for worker processes, which is `fork` on Linux. Forked workers inherit the parent process's native runtime and connections, which is the failure mode behind the fork-isolation work. ## Behavior When `num_workers > 0` and `multiprocessing_context` is omitted or `None`, workers now use `forkserver` when the platform provides it, otherwise `spawn`. Explicit start-method names and context objects are unchanged. With `num_workers == 0`, no context is selected, preserving PyTorch's single-process handling. Callbacks and worker state must be picklable under the selected start method, following PyTorch's DataLoader rules. Existing `StreamingDataset` serialization is sufficient for the default worker path. This does not change the explicit fork opt-in or the native client reopen path in #3851.
This commit is contained in:
@@ -54,6 +54,8 @@ Python's built-in `torch.utils.data.DataLoader` produces a safe checkpoint when
|
||||
alongside every internal batch and commits it to the parent `StreamingDataset` only when that batch is returned to the
|
||||
trainer. The trainer receives the same collated batch it would receive from a standard `DataLoader`.
|
||||
|
||||
With `num_workers > 0` and `multiprocessing_context` omitted or `None`, `StreamingDataLoader` uses `forkserver` where the platform provides it and falls back to `spawn`. Callback functions and worker state must be picklable under that start method. Multi-worker scripts should keep their entry point behind the standard `if __name__ == "__main__":` guard so spawned workers can import the module safely.
|
||||
|
||||
<CodeGroup>
|
||||
```py Python icon=Python
|
||||
from lancedb.streaming import StreamingDataset, StreamingDataLoader
|
||||
|
||||
Reference in New Issue
Block a user