Execute predefined task instructions #13993
Draft
+635
−42
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.
Title
Performance Optimization: Reduce Latency in
completion
andacompletion
CallsRelevant issues
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/
directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit
Type
🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
Changes
This PR introduces significant performance optimizations to LiteLLM's core
completion
andacompletion
paths, targeting bottlenecks identified through profiling. The goal is to reduce latency and improve throughput for completion-heavy workloads by an estimated 17-20%.Key Optimizations:
LlmProviders
Enum Values: Replaced expensive list comprehensions ([provider.value for provider in LlmProviders]
) with a pre-computedLlmProvidersSet
for O(1) lookups, eliminating ~6.5% of execution time.get_optional_params()
:provider_config
to avoid redundant calls toget_supported_openai_params()
.anthropic_text
provider calledmap_openai_params()
twice.pre_process_non_default_params()
:for
loop.excluded_params
anddropped_params
for faster O(1) lookups.Impact:
These changes collectively aim for a 17-20% overall performance improvement in completion request processing. New profiling (
test_profile_mock_response.py
), benchmarking (benchmark_optimization.py
), and regression test (test_optimization_regression.py
) scripts have been added to validate these gains and ensure no functionality regressions.