Skip to content

UsageTracker with MIPROv2 Report AttributeError #9093

@Mutouboy

Description

@Mutouboy

python version : 3.10
dspy version : 3.0.4

When using UsageTracker together with MIPROv2, the following error occurs:
AttributeError: '_contextvars.ContextVar' object has no attribute 'overrides'

After debugging, I found that this error is triggered when using ParallelExecutor inside a with dspy.context(...): block.

This causes MIPROv2._optimize_prompt_parameters() to fail when evaluating the optimized prompts—because it's running inside a with dspy.context(lm=self.task_model): block, and the Evaluate call uses ParallelExecutor under the hood.

Below is a minimal reproducible example.
The error can be observed at line 153 in parallelizer.py.

import dspy
from dspy.utils.parallelizer import ParallelExecutor
from dspy.utils.usage_tracker import UsageTracker


dspy.configure(lm=lm)
dspy.settings.configure(usage_track=True,usage_tracker=UsageTracker())


def do_infer(text):
    return lm(text)

with dspy.context(lm=lm):
    executor = ParallelExecutor(num_threads=2)
    results = executor.execute(do_infer, batch_data)

I’m wondering—is this my fault, or is it actually a bug?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions