-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[Fix] Router: optimize provider tracking in _set_model_group_info (O(n*p) → O(n)) #15107
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
base: main
Are you sure you want to change the base?
Conversation
Replace O(n×p) list-based provider deduplication with O(n) set-based approach in _set_model_group_info(). Previously, the function checked `if llm_provider not in providers` on each iteration, resulting in O(p) list scans per model. Changes: - Track providers in a set during iteration for O(1) deduplication - Convert set to list after loop to maintain API contract - Reduces time complexity from O(n×p) to O(n) Impact: Improves performance for /model_group/info endpoint (which iterates over all models without caching) and on LRU cache misses for set_response_headers.
The latest updates on your projects. Learn more about Vercel for GitHub.
|
ce04ebb
to
47c83a4
Compare
): | ||
model_group_info.supports_url_context = True | ||
|
||
# Track provider in set for O(1) deduplication |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most changes are just indentation from removal of if statement.
Actual Changes:
- Use set for deduplication
- Add providers at the end
cast, | ||
) | ||
|
||
from fastapi import HTTPException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc quality pointed this was missing.
Title
[Fix] Router: optimize provider tracking in _set_model_group_info (O(n*p) → O(n))
Relevant 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
🧹 Refactoring
Changes
Performance Gains