Fix ParallelExecutor crash when Parallel called from within module forward() #9104
+6
−4
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.
## Summary
Fixes a bug where
dspy.Parallelsilently returnsNonefor all tasks when called from within a module'sforward()method while MLflow autologging is enabled.**## Problem
When using
mlflow.dspy.autolog(), callingdspy.Parallelfrom inside a module'sforward()method causes all results to silently returnNone.The root cause is twofold:
1. Incorrect ContextVar access in
parallelizer.py(line 95)thread_local_overridesis aContextVar, which requires.get()and.set()methods for access. The existing code incorrectly attempts to access an.overridesattribute directly:This raises
AttributeError: '_contextvars.ContextVar' object has no attribute 'overrides'.The bug only manifests when
usage_trackeris present in the parent context, which occurs when MLflow autologging is enabled.2. Silent exception handling (line ~155)
Worker exceptions are caught and silently discarded:
This masked the underlying
AttributeError.**## Solution
1. Restructured ContextVar access to build the complete overrides dictionary before setting:
2. Added error logging for worker failures:
**## Reproduction