fix(eval): serialize synthetic CUDA batch jobs#315
Conversation
📝 WalkthroughWalkthroughAdds ChangesCUDA parallelism control
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR addresses GPU memory contention when generating synthetic structure factors or density maps with joblib multiprocessing by clamping CUDA batch execution to a single worker, while preserving the caller’s requested parallelism for CPU execution.
Changes:
- Add a shared
resolve_parallel_jobs()utility that warns and forcesn_jobs=1for CUDA when the request would imply multiple processes. - Apply the shared guard to both synthetic structure-factor and synthetic density batch processing paths.
- Add focused unit tests covering CUDA clamping and CPU pass-through behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/eval/test_synthetic_utils.py | Adds unit tests validating CUDA serialization and CPU parallelism preservation. |
| src/sampleworks/eval/synthetic_utils.py | Introduces resolve_parallel_jobs() with a warning + clamp behavior for CUDA multiprocessing. |
| src/sampleworks/eval/generate_synthetic_sf.py | Uses the shared guard to compute effective_n_jobs for SF batch processing. |
| src/sampleworks/eval/generate_synthetic_density.py | Uses the shared guard to compute effective_n_jobs for density batch processing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/sampleworks/eval/generate_synthetic_density.py (1)
274-275: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
n_jobsdocstring doesn't mention CUDA clamping in bothprocess_batchfunctions. Bothprocess_batchdocstrings describen_jobsas "Number of parallel jobs. -1 means use all available CPUs." but don't mention thatresolve_parallel_jobsnow clamps to 1 on CUDA devices. Adding a brief note would help users understand the effective behavior.
src/sampleworks/eval/generate_synthetic_density.py#L274-L275: Add a note about CUDA clamping to then_jobsparameter description.src/sampleworks/eval/generate_synthetic_sf.py#L460-L461: Apply the same docstring update.📝 Suggested docstring update (apply to both files)
n_jobs Number of parallel jobs. -1 means use all available CPUs. + On CUDA devices, n_jobs is automatically limited to 1 to prevent + GPU memory contention from multiple CUDA contexts.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/sampleworks/eval/generate_synthetic_density.py` around lines 274 - 275, Update the n_jobs parameter descriptions in both process_batch functions to document that resolve_parallel_jobs clamps the effective job count to 1 when running on CUDA devices. Apply the same concise clarification in src/sampleworks/eval/generate_synthetic_density.py lines 274-275 and src/sampleworks/eval/generate_synthetic_sf.py lines 460-461.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/sampleworks/eval/generate_synthetic_density.py`:
- Around line 274-275: Update the n_jobs parameter descriptions in both
process_batch functions to document that resolve_parallel_jobs clamps the
effective job count to 1 when running on CUDA devices. Apply the same concise
clarification in src/sampleworks/eval/generate_synthetic_density.py lines
274-275 and src/sampleworks/eval/generate_synthetic_sf.py lines 460-461.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 24e66d64-d5a2-4493-a25b-a8ae27db2dff
📒 Files selected for processing (4)
src/sampleworks/eval/generate_synthetic_density.pysrc/sampleworks/eval/generate_synthetic_sf.pysrc/sampleworks/eval/synthetic_utils.pytests/eval/test_synthetic_utils.py
|
The fix seems to be enforcing n_jobs = 1 on CUDA device. Unless we plan on parallelize across multiple GPUs (which I don't think we need for the 40 synthetic dataset at the moment?), this PR looks good to me. Make sure to rebase before merge. |
Summary
Closes #242
Validation
pytest tests/eval/test_synthetic_utils.py -q(10 passed)pytest tests/eval/test_generate_synthetic_density.py tests/eval/test_generate_synthetic_sf.py -q(14 passed)ty check src/sampleworks/eval/synthetic_utils.py src/sampleworks/eval/generate_synthetic_density.py src/sampleworks/eval/generate_synthetic_sf.py tests/eval/test_synthetic_utils.pyruff checkandruff format --checkon touched filesSummary by CodeRabbit
Bug Fixes
Tests