Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix UsageTracker AttributeError when using ParallelExecutor with dspy.context#9095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge3 commits intomain
base:main
Choose a base branch
Loading
fromcopilot/fix-usage-tracker-attribute-error

Conversation

Copy link
Contributor

CopilotAI commentedNov 27, 2025
edited
Loading

📝 Changes Description

UsingUsageTracker withParallelExecutor inside adspy.context() block raisesAttributeError: '_contextvars.ContextVar' object has no attribute 'overrides'.

tracker=UsageTracker()withdspy.context(usage_tracker=tracker):executor=ParallelExecutor(num_threads=2)results=executor.execute(do_infer,batch_data)# AttributeError

Root cause:parallelizer.py line 95 incorrectly accessedthread_local_overrides.overrides — butthread_local_overrides is aContextVar, not a dict.

Fix: Build the overrides dict first, deep copyusage_tracker if present, then call.set():

new_overrides= {**original,**parent_overrides.copy()}ifnew_overrides.get("usage_tracker"):new_overrides["usage_tracker"]=copy.deepcopy(new_overrides["usage_tracker"])token=thread_local_overrides.set(new_overrides)
  • dspy/utils/parallelizer.py: Fixed ContextVar API usage
  • tests/utils/test_parallelizer.py: Added tests for UsageTracker with dspy.context

✅ Contributor Checklist

  • Pre-Commit checks are passing (locally and remotely)
  • Title of your PR / MR corresponds to the required format
  • Commit message follows required format {label}(dspy): {message}

⚠️ Warnings

None.

Original prompt

This section details on the original issue you should resolve

<issue_title>UsageTracker with MIPROv2 Report AttributeError</issue_title>
<issue_description>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 causesMIPROv2._optimize_prompt_parameters() to fail when evaluating the optimized prompts—because it's running inside awith dspy.context(lm=self.task_model):block, and theEvaluate call uses ParallelExecutor under the hood.

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

importdspyfromdspy.utils.parallelizerimportParallelExecutorfromdspy.utils.usage_trackerimportUsageTrackerdspy.configure(lm=lm)dspy.settings.configure(usage_track=True,usage_tracker=UsageTracker())defdo_infer(text):returnlm(text)withdspy.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?

</issue_description>

<agent_instructions>The error only happens when dspy.context is in use. If just using global configdspy.configure this error is not spotted.

Meanwhile, if just usingdspy.configure globally, the returned result from dspy.Parallel call seems to not contain the usage data, please also confirm. thank you!</agent_instructions>

Comments on the Issue (you are@copilot in this section)

@chenmoneygithub@Mutouboy Thanks for reporting the issue! I can confirm that this is a real bug, will work on a fix.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our2 minute survey.

CopilotAIand others added2 commitsNovember 27, 2025 02:25
….contextCo-authored-by: chenmoneygithub <22925031+chenmoneygithub@users.noreply.github.com>
… parent_overridesCo-authored-by: chenmoneygithub <22925031+chenmoneygithub@users.noreply.github.com>
CopilotAI changed the title[WIP] Fix AttributeError in UsageTracker with MIPROv2Fix UsageTracker AttributeError when using ParallelExecutor with dspy.contextNov 27, 2025
Copilot finished work on behalf ofchenmoneygithubNovember 27, 2025 02:29
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@chenmoneygithubchenmoneygithubAwaiting requested review from chenmoneygithub

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

UsageTracker with MIPROv2 Report AttributeError

2 participants

@chenmoneygithub

[8]ページ先頭

©2009-2025 Movatter.jp