-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add top_k
to PromptNode
#4159
Conversation
@@ -979,4 +988,4 @@ def run_batch( | |||
def _prepare_model_kwargs(self): | |||
# these are the parameters from PromptNode level | |||
# that are passed to the prompt model invocation layer | |||
return {"stop_words": self.stop_words} | |||
return {"stop_words": self.stop_words, "top_k": self.top_k} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be pushed down to PromptModel.invoke
and InvocationLayer.invoke
haystack/nodes/prompt/prompt_node.py
Outdated
if "top_k" in kwargs: | ||
kwargs["n"] = kwargs.pop("top_k") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handling in OpenAIInvocationLayer
if top_k: | ||
model_input_kwargs["num_return_sequences"] = top_k | ||
model_input_kwargs["num_beams"] = top_k |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handling in HFInvocationLayer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In AnswerGenerator we warn if num_beams
< num_return_sequences
. If the user wants to control them separately, she can do so via model_kwargs
, but I can't even imagine why one would do so.
Yeah this approach is correct @tstadel Handle top_k on a conceptual level, but each implementation layer handles the specifics of the top_k concept appropriately. |
#4151 will merge first to master. I will resolve conflicts if they arise. |
Ok, if @sjrl doesn't object let's go with top_k |
Sounds good to me! |
|
||
pipe = Pipeline() | ||
pipe.add_node(component=node, name="prompt_node", inputs=["Query"]) | ||
result = pipe.run(query="not relevant", documents=[Document("Berlin is the capital of Germany")]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the test! I wanted to ask if it would make more sense to be setting query=None
instead of "not relevant"
for general use case when using a node that ignores the query? Doesn't matter for tests though, just wanted to ask.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sjrl I think there is still something that required the query to be set. Ideally, we shouldn't have to add query
add all here. As long query
is required, it doesn't make a difference, I'd say.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks for adding this feature!
@tstadel Please update your branch with main and rerun CI, then it should be good to go! |
Related Issues
top_k
toPromptNode
#4158Proposed Changes:
top_k
parameter toPromptNode
top_k
to invocation layers and map them to their invocation interfaceHow did you test it?
Notes for the reviewer
test/nodes/test_audio.py::TestTextToSpeech::test_text_to_speech_compress_audio
fails. The code didn't touch any of TestToSpeech. Also other PR CIs are failing because of this. Maybe a dependency update?...Checklist
fix:
,feat:
,build:
,chore:
,ci:
,docs:
,style:
,refactor:
,perf:
,test:
.