Skip to content

fix(teleprompt): respect MIPROv2.compile seed=0 - #10322

Open
Zsanz3 wants to merge 25 commits into
stanfordnlp:mainfrom
Zsanz3:cursor/fix-miprov2-compile-seed-zero-88e7
Open

Zsanz3 wants to merge 25 commits into
stanfordnlp:mainfrom
Zsanz3:cursor/fix-miprov2-compile-seed-zero-88e7

Conversation

@Zsanz3

@Zsanz3 Zsanz3 commented Sep 2, 2026

Copy link
Copy Markdown

Changes

MIPROv2.compile applied the seed with seed = seed or self.seed. In Python, 0 or self.seed is self.seed, so compile(..., seed=0) silently used the constructor default (seed=9).

The fallback is now seed = seed if seed is not None else self.seed. Only a missing/None seed uses the constructor value; seed=0 is kept.

A unit test asserts that compile(..., seed=0) calls _set_random_seeds(0).

Fixes #10321.

`seed = seed or self.seed` treats 0 as missing and falls back to the
constructor default (9). Use an explicit None check so seed=0 is kept.

Co-authored-by: Zsanz3 <Zsanz3@users.noreply.github.com>
@greptile-apps

greptile-apps Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The change is safe to merge: it preserves an explicitly supplied zero seed while retaining the constructor fallback for None. No blocking findings remain.

Summary

MIPROv2.compile now keeps an explicit seed=0.

  • MIPROv2.compile keeps zero as an explicit random seed.

Reviews (25) · Last reviewed commit: "Merge branch 'main' into cursor/fix-mipr..." · Reviewed by Greptile

@VANDRANKI VANDRANKI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Community review, does not clear the merge gate.

Small, clear fix in dspy/teleprompt/mipro_optimizer_v2.py. compile() had seed = seed or self.seed, which is the classic Python truthy-vs-None bug: 0 or self.seed evaluates to self.seed because 0 is falsy, so calling compile(seed=0) silently ignored the caller's explicit 0 and fell back to whatever seed the constructor was given. Fixed to seed = seed if seed is not None else self.seed, which only falls back when the caller didn't pass a seed at all.

The new test mocks _set_random_seeds and _set_and_validate_datasets (raising to stop execution right after the seed line), calls compile(..., seed=0), and asserts _set_random_seeds was called with 0 specifically. That directly targets the bug rather than just checking compile succeeds.

Simple, correct, matches the referenced issue #10321. Comfortable approving.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] MIPROv2.compile(seed=0) ignores the seed

2 participants