revert: perf: lazy-load SDK symbols so import litellm stays under 60 MB RSS (#39121) - #39969
Conversation
…MB RSS (…" This reverts commit c091dd4.
|
Issue reopened: LIT-6607 import litellm costs ~200 MB RSS |
Greptile SummaryThis PR reverts SDK symbol lazy loading and restores eager package initialization to repair import cycles and interactions response bindings
Confidence Score: 4/5The functional revert appears sound, but repository requirements for focused regression coverage and source comments must be satisfied before merging The eager imports restore the intended namespace and no behavioral failure was established, but the exact interactions failure lacks deterministic regression coverage and restored comments violate repository guidance Files Needing Attention: litellm/init.py, tests/test_litellm/test_lazy_imports.py
|
| Filename | Overview |
|---|---|
| litellm/init.py | Restores eager SDK imports and module-level response symbols, with repository-prohibited explanatory comments |
| litellm/_lazy_imports.py | Removes SDK symbol, module alias, submodule fallback, and shadowable-function lazy-loading machinery |
| litellm/_lazy_imports_registry.py | Removes the large SDK import maps and public star-import registry introduced by the reverted change |
| litellm/proxy/init.py | Replaces dynamic proxy submodule resolution with the previous package initialization |
| tests/test_litellm/test_lazy_imports.py | Removes tests for reverted lazy behavior without adding deterministic coverage for the interactions bridge regression |
Reviews (1): Last reviewed commit: "Revert "perf: lazy-load SDK symbols so i..." | Re-trigger Greptile
| @@ -353,83 +346,3 @@ def test_utils_module_lazy_imports(): | |||
| assert name in utils_globals | |||
There was a problem hiding this comment.
Interactions Regression Untested
This bug fix lacks a deterministic interactions bridge regression test, violating the repository requirement that exact failures remain covered. Add one before merging
Context Used: CLAUDE.md (source)
|
|
||
| _key_management_settings: KeyManagementSettings = KeyManagementSettings() |
There was a problem hiding this comment.
These routine import-order comments, also at lines 1282-1286 and 2189-2198, violate the repository's source-comment restrictions and must be removed before merging
Context Used: CLAUDE.md (source)
…1 budget The revert restored the dict annotation that #39121 had loosened to Mapping, and the LIT001 ceiling has been ratcheted down since, so the gate rejected the one reintroduced hit. Annotation only, no behavior change.
b1e2f5b
into
litellm_internal_staging
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
TLDR
Problem this solves:
import litellmlazy and turned five CircleCI jobs red on staginglitellm.cost_calculator, the Bedrock token counter and proxy auth checks now hit circular importslitellm.responsesandlitellm.aresponsesare no longer in the module namespaceHow it solves it:
litellm/__init__.pyeagerly wires the SDK symbols againresponses/aresponsesattributesUser Flow
Before: a developer importing a litellm submodule on its own gets a circular ImportError, and the Interactions API bridge crashes on its first request
python -c "from litellm.cost_calculator import batch_cost_calculator"ImportError: cannot import name 'RealtimeAPITokenUsageProcessor' from partially initialized module 'litellm.cost_calculator' (most likely due to a circular import)litellm.interactions.create(model="gpt-5.5", input="What is 2 + 2?")APIConnectionError: OpenAIException - 'module' object is not callableinstead of returning an interactionAfter: the same import and the same call work as they did before #39121
python -c "from litellm.cost_calculator import batch_cost_calculator"litellm.interactions.create(model="gpt-5.5", input="What is 2 + 2?")InteractionsAPIResponsewithstatus="completed"Relevant issues
Reverts #39121
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Both sides ran from a fresh worktree with
OPENAI_API_KEYset. The Interactions API call is a real request to OpenAI. The pytest runs are the two CircleCI test files that fail at collection time on staging (thebatches_testingandlitellm_utils_testingjobs)Before (a0c9095)
Importing a submodule first
python -c "from litellm.cost_calculator import batch_cost_calculator"ImportError: cannot import name 'RealtimeAPITokenUsageProcessor' from partially initialized module 'litellm.cost_calculator' (most likely due to a circular import)Interactions API bridged to /v1/responses
python -c 'import litellm; r = litellm.interactions.create(model="gpt-5.5", input="What is 2 + 2? Answer with one number."); print(type(r).__name__, "status", r.status)'litellm.exceptions.APIConnectionError: litellm.APIConnectionError: APIConnectionError: OpenAIException - 'module' object is not callableThe two CircleCI test files
pytest tests/litellm_utils_tests/test_bedrock_token_counter.py tests/batches_tests/test_batch_custom_pricing.py -q4 warnings, 2 errors in 0.69sAfter (eee162b)
Importing a submodule first
python -c "from litellm.cost_calculator import batch_cost_calculator"Interactions API bridged to /v1/responses
python -c 'import litellm; r = litellm.interactions.create(model="gpt-5.5", input="What is 2 + 2? Answer with one number."); print(type(r).__name__, "status", r.status)'InteractionsAPIResponse status completedThe two CircleCI test files
pytest tests/litellm_utils_tests/test_bedrock_token_counter.py tests/batches_tests/test_batch_custom_pricing.py -q12 passed, 1 skipped in 0.10sType
🐛 Bug Fix
Caveats (if any)
Medium
litellm.responses/litellm.aresponsesthroughgetattr, notvars()Low
test_star_import_exports_public_api, so test(lazy_imports): check star-import exports against globals(), not dir() #39958 (which only fixed that test'sdir()scoping bug) should be closed if this mergestests/proxy_admin_ui_tests/test_access_group_team_sync.pycollects again after the revert; its tests then need a PostgresDATABASE_URLlocally, which CircleCI providesFinal Attestation