Skip to content

Commit b03746b

Browse files
Delay client import to reduce early import memory usage
- Move client import from line 1053 to right before main.py import (line 1328) - This delays loading utils.py (which imports tiktoken) until after most other imports - client cannot be fully lazy-loaded because main.py needs it at import time for @client decorator - Reduces memory footprint during early import phase
1 parent 44df16e commit b03746b

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

litellm/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,10 +1047,6 @@ def add_known_models():
10471047
from .timeout import timeout
10481048
from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider
10491049
# Note: remove_index_from_tool_calls is lazy-loaded via __getattr__ to reduce import-time memory cost
1050-
# Note: get_modified_max_tokens is not exported from __init__.py and is only used
1051-
# internally in utils.py, so we don't need to import it here
1052-
# client must be imported immediately as it's used as a decorator at function definition time
1053-
from .utils import client
10541050
# Note: Most other utils imports are lazy-loaded via __getattr__ to avoid loading utils.py
10551051
# (which imports tiktoken) at import time
10561052

@@ -1324,6 +1320,7 @@ def add_known_models():
13241320
from .llms.cometapi.embed.transformation import CometAPIEmbeddingConfig
13251321
from .llms.lemonade.chat.transformation import LemonadeChatConfig
13261322
from .llms.snowflake.embedding.transformation import SnowflakeEmbeddingConfig
1323+
from .utils import client
13271324
from .main import * # type: ignore
13281325
from .integrations import *
13291326
from .llms.custom_httpx.async_client_cleanup import close_litellm_async_clients

0 commit comments

Comments
 (0)