Add multiple sampling support to lf.query
and introduce lf.query_and_reduce
.
#374
+341
−80
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add multiple sampling support to
lf.query
and introducelf.query_and_reduce
.This CL enhances
lf.query
to support parallel queries to multiple LLMs with multiple samples by accepting a list of models (lm
) and the correspondingnum_samples
argument.Additionally, this change introduces a new API,
lf.query_and_reduce
, which enables a map-reduce style workflow usinglf.query
. The motivation forlf.query_and_reduce
is to maintain a clean 1:1 mapping at the interface level while providing a flexible mechanism for users to regularize or aggregate outputs using a reduce function.Key Features:
lf.query
Enhancements:num_samples
argument.lf.query_and_reduce
:lf.query
with compatible arguments and default behavior.reduce
function that processes multiple LLM outputs, enabling operations like majority voting, aggregation, or other forms of output post-processing.Example usage: sampling Gpt4 and Gemini2 each with 5 samples and obtain the final output through majority voting.