feat: implement loglikelihood and loglikelihood_rolling for LiteLLMClient (closes #1093)#1244
Open
ALI-AL-MARJANI wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implements
loglikelihood()andloglikelihood_rolling()forLiteLLMClient,enabling deterministic MCQ benchmarks (MMLU, ARC, HellaSwag) and perplexity
evaluation over any LiteLLM-supported provider.
Previously both methods raised
NotImplementedError.How it works
Uses
litellm.atext_completionwithecho=True, logprobs=1, max_tokens=1, temperature=0.0(the/v1/completionsendpoint). A two-layer Token AlignmentEngine isolates the continuation log-probabilities from the echoed prompt:
text_offset(OpenAI exact)Concurrency is managed with
asyncio.Semaphore+asyncio.gather, matchingthe approach used by other async-capable backends.
Provider requirement
The
/v1/completionsendpoint withechosupport is required:gpt-3.5-turbo-instructA warning is emitted at runtime if the model is registered as
mode=chat.Changes
litellm_model.py— 9 new methods:loglikelihood,loglikelihood_rolling,async pipeline, token alignment engine, argmax check, provider guard, length guard
model_input.py— newto_litellm_text_completion_dict()method; also fixespresence_penaltysilently dropped fromto_litellm_dict()(bug fix)inference_providers_model.py— informativeNotImplementedErrormessagesexplaining why the HF Inference Providers backend cannot support this
use-litellm-as-backend.mdx— full documentation of both evaluation modesinstallation.mdx,models.mdx— updated to reflect new capabilitiestests.yaml— adds--extra litellmto CIlitellm_completion_model.yaml— example config for MCQ/perplexity benchmarksTests
80 new unit tests, all passing, no new regressions:
to_litellm_text_completion_dict(9 tests)to_litellm_dictpresence_penalty regression (4 tests)greedy_untilsplit iteration regression (2 tests)