Skip to content
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

fix: num_return_sequences should be less than num_beams, not top_k #5280

Merged
merged 13 commits into from
Jul 11, 2023

Conversation

faaany
Copy link
Contributor

@faaany faaany commented Jul 5, 2023

Related Issues

Proposed Changes:

  1. use num_beams instead of top_k and remove top_k, because the real top_k is used for top-k sampling or sampling decoding methods not beam search
  2. let user set the num_return_sequences, not by us

How did you test it?

manual test

Notes for the reviewer

Checklist

@faaany faaany requested a review from a team as a code owner July 5, 2023 16:59
@faaany faaany requested review from julian-risch and removed request for a team July 5, 2023 16:59
@coveralls
Copy link
Collaborator

coveralls commented Jul 5, 2023

Pull Request Test Coverage Report for Build 5518507439

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 180 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.2%) to 45.011%

Files with Coverage Reduction New Missed Lines %
nodes/prompt/invocation_layer/hugging_face.py 3 91.73%
document_stores/elasticsearch/es7.py 8 80.43%
nodes/retriever/dense.py 169 26.45%
Totals Coverage Status
Change from base Build 5487781909: 0.2%
Covered Lines: 10379
Relevant Lines: 23059

💛 - Coveralls

Copy link
Member

@julian-risch julian-risch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@faaany Thank you for this contribution! The pull request looks very good to me already. Just two small things that could be improved and then we can merge it.
The warning message should include both values num_beams and num_return_sequences to make it easier for the user to understand how to set the parameters correctly.
Second, could you please add a small unit test that checks that the warning is displayed if
num_return_sequences > num_beams? You can add the test to the file test/prompt/invocation_layer/test_hugging_face.py and it should be similar to the test called test_ensure_token_limit_negative here: https://github.com/deepset-ai/haystack/blob/main/test/prompt/invocation_layer/test_hugging_face.py#L189
You shouldn't need a real model for that test so you can use mocking as in this other test:

def test_constructor_with_various_kwargs(mock_pipeline, mock_get_task):

Happy to help with the mocking if that part is unclear. Just let me know. 🙂

@faaany
Copy link
Contributor Author

faaany commented Jul 7, 2023

done. My test run through, but I am not quite sure whether there is a better way to write this test. Feel free to leave comments, so I can update it quickly and write better unit tests in the future. Thanks a lot!

@faaany
Copy link
Contributor Author

faaany commented Jul 11, 2023

@julian-risch any feedback on this?

@julian-risch julian-risch self-requested a review July 11, 2023 07:07
@github-actions github-actions bot added the type:documentation Improvements on the docs label Jul 11, 2023
Copy link
Member

@julian-risch julian-risch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@faaany Thank you for another contribution to Haystack! The pull request looks very good to me now. 👍 I extended the tests a bit to also check that num_return_sequences is set to num_beams as expected. I also changed the docstring describing the test accordingly. The init of HFLocalInvocationLayer I was able to simplify. Have a look if you're interested. Your test was quite good already before this final polishing step. Great work! 🙂

@julian-risch julian-risch merged commit 514f93a into deepset-ai:main Jul 11, 2023
@faaany
Copy link
Contributor Author

faaany commented Jul 11, 2023

@faaany Thank you for another contribution to Haystack! The pull request looks very good to me now. 👍 I extended the tests a bit to also check that num_return_sequences is set to num_beams as expected. I also changed the docstring describing the test accordingly. The init of HFLocalInvocationLayer I was able to simplify. Have a look if you're interested. Your test was quite good already before this final polishing step. Great work! 🙂

Wow, the tests look really good now! Thanks so much! Learned new stuff again. lol

anakin87 pushed a commit that referenced this pull request Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:tests type:documentation Improvements on the docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

num_return_sequences should be less than num_beams, not top_k
3 participants