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

Add multiple sampling support to lf.query and introduce lf.query_and_reduce. #374

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

copybara-service[bot]
Copy link

@copybara-service copybara-service bot commented Dec 17, 2024

Add multiple sampling support to lf.query and introduce lf.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 corresponding num_samples argument.

Additionally, this change introduces a new API, lf.query_and_reduce, which enables a map-reduce style workflow using lf.query. The motivation for lf.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:

    • Supports multiple language models queried in parallel.
    • Allows sampling multiple outputs from each model using the num_samples argument.
  • lf.query_and_reduce:

    • A drop-in replacement for lf.query with compatible arguments and default behavior.
    • Provides a 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.

lf.query_and_reduce(
  'compute 256 * 345',
  int,
  reduce=lambda answers: lf.query('Find majority from {{answers}}', int, lm=lf.llms.Gpt4(), answers=answers),
  lm=[lf.llms.Gpt4(), lf.llms.Gemini2()],
  num_samples=5,
  ...
)

@copybara-service copybara-service bot force-pushed the test_701557382 branch 4 times, most recently from e21e0ca to 7dc776e Compare December 17, 2024 20:52
@copybara-service copybara-service bot changed the title Add lf.query_with_consistency. Multiple sampling support through lf.query and add lf.query_and_reduce. Dec 17, 2024
@copybara-service copybara-service bot force-pushed the test_701557382 branch 2 times, most recently from 44ea310 to d022ca0 Compare December 17, 2024 22:08
@copybara-service copybara-service bot changed the title Multiple sampling support through lf.query and add lf.query_and_reduce. Add multiple sampling support to lf.query and introduce lf.query_and_reduce. Dec 17, 2024
…nd_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 corresponding `num_samples` argument.

Additionally, this change introduces a new API, `lf.query_and_reduce`, which enables a map-reduce style workflow using `lf.query`. The motivation for `lf.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:
  * Supports multiple language models queried in parallel.
  * Allows sampling multiple outputs from each model using the `num_samples` argument.

- `lf.query_and_reduce`:
  * A drop-in replacement for `lf.query` with compatible arguments and default behavior.
  * Provides a `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.

```python
lf.query_and_reduce(
  'compute 256 * 345',
  int,
  reduce=lambda answers: lf.query('Find majority from {{answers}}', int, lm=lf.llms.Gpt4(), answers=answers),
  lm=[lf.llms.Gpt4(), lf.llms.Gemini2()],
  num_samples=5,
  ...
)
```

PiperOrigin-RevId: 707260742
@copybara-service copybara-service bot merged commit 2ab5e48 into main Dec 17, 2024
1 check passed
@copybara-service copybara-service bot deleted the test_701557382 branch December 17, 2024 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant