Open felixgao opened 1 month ago
Is thread_count
set to 2? Maybe an issue with multithreading/batching
breadth
is passed to the model as n
- so you need to set breadth to 1 if you're using gemini.
I set the thread_count
to 1 and still failed.
Here is the updated code
def signature_optimization(module, train, metric_fn, thread_count:int=1) -> SimpleDocumentTextQA:
from dspy.teleprompt import COPRO
teleprompter = COPRO(metric=metric_fn, verbose=True, depth=2, breadth=1)
config = dict(num_threads=thread_count, display_progress=True)
optmized = teleprompter.compile(
module,
trainset=train,
eval_kwargs=config
)
optmized.save("optimized_signature.json")
return SimpleDocumentTextQA(optmized)
when I set breadth
to 1 the code failed with the following error
Evaluation Result (Before Optimization): 0.0
Signature Optimization...
Traceback (most recent call last):
File "/Users/ggao/projects/gemini/gemini/doc_qa.py", line 341, in <module>
fire.Fire(main)
File "/Users/ggao/projects/gemini/.venv/lib/python3.11/site-packages/fire/core.py", line 143, in Fire
component_trace = _Fire(component, args, parsed_flag_args, context, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ggao/projects/gemini/.venv/lib/python3.11/site-packages/fire/core.py", line 477, in _Fire
component, remaining_args = _CallAndUpdateTrace(
^^^^^^^^^^^^^^^^^^^^
File "/Users/ggao/projects/gemini/.venv/lib/python3.11/site-packages/fire/core.py", line 693, in _CallAndUpdateTrace
component = fn(*varargs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ggao/projects/gemini/gemini/doc_qa.py", line 331, in main
optmized = signature_optimization(module, train, metric_fn, thread_count)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ggao/projects/gemini/gemini/doc_qa.py", line 263, in signature_optimization
teleprompter = COPRO(metric=metric_fn, verbose=True, depth=2, breadth=1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ggao/projects/gemini/.venv/lib/python3.11/site-packages/dspy/teleprompt/copro_optimizer.py", line 69, in __init__
raise ValueError("Breadth must be greater than 1")
ValueError: Breadth must be greater than 1
The error makes sense because the COPRO code is specifically looking for breadth to be greater than 1. Can someone help me understand what is this breadth variable. There isn't enough documentation on what the variable is controlling.
class COPRO(Teleprompter):
def __init__(
self,
prompt_model=None,
metric=None,
breadth=10,
depth=3,
init_temperature=1.4,
track_stats=False,
**_kwargs,
):
if breadth <= 1:
raise ValueError("Breadth must be greater than 1")
self.metric = metric
self.breadth = breadth
self.depth = depth
self.init_temperature = init_temperature
self.prompt_model = prompt_model
self.track_stats = track_stats
Just check the code and n
is set to
n=self.breadth - 1,
I would set breadth
to 2, so that n
becomes one. Not confident at all though that this works
Later in COPRO it uses n=breath
iirc. Think a problem with gemini + model-garden API.
Hmm are we seeing a collision between parameter names in DSPy and parameter names in Gemini? ...
The model garden API serves multiple models with a common generation config model. For gemini [candidateCount] must be 1 - but it's being set to 2 by n
The code throws
google.api_core.exceptions.InvalidArgument: 400 Unable to submit request because candidateCount must be 1 but the entered value was 2. Update the candidateCount value and try again.
error in my compile code.The stack trace
Any ideas on what is the cause of this?