From f3b97356fb28bfb25099ed3a58f6eeaa8603ec13 Mon Sep 17 00:00:00 2001 From: Alexsander Hamir Date: Fri, 19 Dec 2025 13:00:57 -0800 Subject: [PATCH] Add lazy loading for GaladrielChatConfig to reduce import memory overhead (#18260) Implements lazy loading pattern for GaladrielChatConfig following the existing approach used for other LLM config classes. This defers the import until the config is actually accessed, reducing memory usage during module initialization. --- litellm/__init__.py | 1 - litellm/_lazy_imports.py | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/litellm/__init__.py b/litellm/__init__.py index 9b69beccd79..0463282c089 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -1066,7 +1066,6 @@ from .utils import client from .llms.bytez.chat.transformation import BytezChatConfig from .llms.custom_llm import CustomLLM from .llms.aiohttp_openai.chat.transformation import AiohttpOpenAIChatConfig -from .llms.galadriel.chat.transformation import GaladrielChatConfig from .llms.github.chat.transformation import GithubChatConfig from .llms.compactifai.chat.transformation import CompactifAIChatConfig from .llms.empower.chat.transformation import EmpowerChatConfig diff --git a/litellm/_lazy_imports.py b/litellm/_lazy_imports.py index 94b3e4a8da1..14772862686 100644 --- a/litellm/_lazy_imports.py +++ b/litellm/_lazy_imports.py @@ -158,6 +158,7 @@ DOTPROMPT_NAMES = ( LLM_CONFIG_NAMES = ( "AmazonConverseConfig", "OpenAILikeChatConfig", + "GaladrielChatConfig", ) # Types that support lazy loading via _lazy_import_types @@ -660,4 +661,12 @@ def _lazy_import_llm_configs(name: str) -> Any: _globals["OpenAILikeChatConfig"] = _OpenAILikeChatConfig return _OpenAILikeChatConfig + if name == "GaladrielChatConfig": + from .llms.galadriel.chat.transformation import ( + GaladrielChatConfig as _GaladrielChatConfig, + ) + + _globals["GaladrielChatConfig"] = _GaladrielChatConfig + return _GaladrielChatConfig + raise AttributeError(f"LLM config lazy import: unknown attribute {name!r}") \ No newline at end of file