Repository navigation
test: stop start-method leak between tests and run the whole suite under xdist - #968
Merged
Merged
Conversation
…der xdist - restore the multiprocessing start method after each test: optimize()/map() force it to spawn for the rest of the process, so later multi-worker dataloader tests re-imported torch and litdata in every worker - import lightning_sdk lazily so 'import litdata' (paid by every spawned worker) no longer loads it - run tests/processing and tests/raw in the same xdist run, with -n 4 Refs Lightning-AI#612 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
deependujha
requested review from
bhimrazy,
dhedey,
pwgardipee and
tchaton
as code owners
November 16, 2026 06:04
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #968 +/- ##
=====================================
Coverage 82% 82%
=====================================
Files 72 72
Lines 16445 16451 +6
=====================================
+ Hits 13505 13513 +8
+ Misses 2940 2938 -2 🚀 New features to boost your workflow:
|
…ait on macOS - test_optimize_with_queues_as_input built a default-context queue and passed it to optimize(), which spawns its workers; it only passed while an earlier test had left the start method on spawn. Create the queue from a spawn context. - on macOS, torch_shm_manager keeps each dataloader worker's exit pipe open, so the parent waits torch's 5s join timeout per worker at shutdown. Lower MP_STATUS_CHECK_INTERVAL to 0.5s in the test process on macOS. Refs Lightning-AI#612 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
8 tasks
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the multiprocessing test-isolation and parallel CI changes.
No open issues 🎉
What changed in this PR
Speeds up testing by isolating multiprocessing state, reducing worker overhead, and running the full suite in parallel. This addresses #612 and builds on the cache isolation introduced in #952.
Changes:
- Restore the multiprocessing start method after each test and use a spawn-compatible queue and producer.
- Load
litdata.Machinelazily and shorten dataloader shutdown waits on macOS during tests. - Consolidate CI into one four-worker xdist run and update testing guidance.
| File | Description |
|---|---|
tests/test_imports.py |
Adds regression tests for lazy SDK loading and the Machine export. |
tests/processing/test_functions.py |
Creates the queue and producer from a spawn context. |
tests/conftest.py |
Adds start-method restoration and a macOS shutdown-timeout fixture. |
src/litdata/__init__.py |
Resolves and caches Machine on first access. |
.github/workflows/ci-testing.yml |
Runs the whole suite with four xdist workers. |
.claude/skills/litdata/reference/testing.md |
Documents the unified CI command and new fixtures. |
Review effort: Balanced
1 of 2 tasks
deependujha
commented
Nov 17, 2026
tchaton
approved these changes
Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Fixes #612. Follow-ups are tracked in #969.
Five changes that cut test time:
1. Restore the multiprocessing start method after each test
optimize()/map()callmultiprocessing.set_start_method("spawn", force=True), and that sticks for the rest of the process. Once any test in a pytest worker callsoptimize(), every later test in that worker spawns its dataloader workers instead of forking them, and each spawned worker re-imports torch and litdata.tests/streaming/test_parallel.pyalone took ~848s of the ~1340s spent in the parallel step, on 20-item datasets.test_parallel_dataset_partial_iteration_resume[False-False-inf]takes 0.6s with forked workers, 70s when it runs after a test that callsoptimize(), and 0.24s with the new autouse fixture.This only helps where the platform default is
fork(Linux, Python 3.10–3.13).2. Fix
test_optimize_with_queues_as_inputIt built a default-context
multiprocessing.Queue()and passed it tooptimize(), which spawns its workers. It only passed while an earlier test had left the start method on spawn. The queue is now created from a spawn context.3. Import
lightning_sdklazilyimport litdataeagerly importedlightning_sdkjust to re-exportMachine, and every spawned dataloader / optimize worker paid for it.litdata.Machineis now resolved on first access via a module__getattr__;from litdata import Machinestill works andMachinestays in__all__. Locallyimport litdatagoes from ~1.2s to ~0.7s.4. Cut the dataloader shutdown wait on macOS (tests only)
On macOS a dataloader worker that sends tensors starts
torch_shm_manager, which inherits the pipe the parent uses to detect the worker's exit and outlives the worker.DataLoader._shutdown_workersthen waits its full 5s join timeout per worker at the end of every epoch, although the worker has already exited. Plaintorch.utils.data.DataLoaderdoes the same (spawn, 2 workers, tensor batches: 10.6s per epoch vs 0.8s without tensors).A macOS-only session fixture lowers torch's
MP_STATUS_CHECK_INTERVALto 0.5s in the test process.test_combined_dataset_dataloader_states_partial_iterations[4-15]goes from 64s to 9.9s. Trade-off: on macOS a worker that needs more than 0.5s to exit is terminated by torch instead of joined.5. Run the whole suite in one xdist step with
-n 4After #952 the processing and raw tests no longer share cache dirs, so they don't need a separate sequential step.
CI job time, before and after
Local (macOS, 6 cores, whole suite,
-n 4, no coverage): 8:22 before the macOS shutdown fixture, 4:41 with it.🤖 Generated with Claude Code