dspy
dspy copied to clipboard
Error loading program compiled using the Ensemble optimizer
The app crashes in below code with a keyerror: File "/home/drawal/miniconda3/envs/xray/lib/python3.11/site-packages/dspy/primitives/module.py", line 75, in load_state param.load_state(state[name])
This is because the load function expects the top level keys in the saved json file to look like this: "predict_func": { But the key entry in the json file looks like this instead: "programs[1].predict_func": {
Deserializing a compiled ensemble program is not implemented?
Hi @drawal1 , could you share your program and stack trace? I suspect this is because dspy.Ensemble
returns a list of DSPy programs and that's how they got saved in the serialization, which can be resolved by looping over that list and saving each one but we can also add a Ensemble-specific function to handle that if it makes sense.
@arnavsinghvi11 - I see the problem now. Its probably same time to fix as creating a program (my program is too complex).
Revised thinking:
- Make reduce_fn, size, and deterministic - members of the
EnsembledProgram
class - Override save and load to handle loading an array of programs as well as the other member variables
Old thinking:
Thinking I can implement load/save as static methods in the EnsembledProgram
class with some minor refactoring.
- Make the
reduce_fn
a property of theEnsembledProgram
class instead of the Ensemble class -
save()
would take a filename as input. It would save all the properties of theEnsembledProgram
class -
load()
would take a filename and deserialize and return an instance of theEnsembledProgram
class
Thoughts?
@arnavsinghvi11 - I did what you suggested and used loops to load/save the candidate programs. But I noticed that the json for candidate program at index 0 actually had ALL the other programs in it. So really, it should be possible to reconstruct ALL the candidate programs from the information in just that 1 file. What is your Discord id? Would like to discuss 1-1
@arnavsinghvi11 - I have submitted PR #843 for this issue. Ready for review
I have punted on the "json for candidate program at index 0 actually had ALL the other programs in it" for now. We can revisit that as an optimization at some later date