Repository navigation
Conversation
`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>
|
VANDRANKI
left a comment
There was a problem hiding this comment.
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.
Changes
MIPROv2.compileapplied the seed withseed = seed or self.seed. In Python,0 or self.seedisself.seed, socompile(..., 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/Noneseed uses the constructor value;seed=0is kept.A unit test asserts that
compile(..., seed=0)calls_set_random_seeds(0).Fixes #10321.