stanfordnlp / dspy

DSPy: The framework for programming—not prompting—foundation models
https://dspy-docs.vercel.app/
MIT License
18.29k stars 1.4k forks source link

List index error using MIPROv2 #1293

Closed eelang-sc closed 1 month ago

eelang-sc commented 3 months ago

https://github.com/stanfordnlp/dspy/blob/d8b8909773fc31e72cec093db2f26109590e524e/dspy/propose/grounded_proposer.py#L195C1-L197C55

The init pattern finds the Predict init first (instead of the intended dspy module's init) and that will lead to finding no matches in line 201 and thus a list index error in line 203.

class Predict(Module, Parameter):
    def __init__(self, signature, **config):
        self.stage = random.randbytes(8).hex()
        self.signature = ensure_signature(signature)
        self.config = config
        self.reset()

I solved it for myself temporarily replacing

init_content_match = re.search(init_pattern, self.program_code_string)
init_content = init_content_match.group(0)

with

init_content_match = re.findall(init_pattern, self.program_code_string)
init_content = init_content_match[-1]

but that's just a quick patch/hack.

okhat commented 3 months ago

cc @XenonMolecule @arnavsinghvi11 is this something we fixed recently?

okhat commented 1 month ago

fixed