fixes: expose flag to disable token counter (#11344)

* fixes: expose flag to disable token counter

* fix add disable_token_counter
This commit is contained in:
Ishaan Jaff 2025-06-02 21:53:08 -07:00 committed by GitHub
parent 3db272b6d2
commit a73cf185ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 3 deletions

View file

@ -217,6 +217,7 @@ use_client: bool = False
ssl_verify: Union[str, bool] = True
ssl_certificate: Optional[str] = None
disable_streaming_logging: bool = False
disable_token_counter: bool = False
disable_add_transform_inline_image_block: bool = False
in_memory_llm_clients_cache: LLMClientCache = LLMClientCache()
safe_memory_mode: bool = False

View file

@ -362,6 +362,15 @@ def token_counter(
"""
from litellm.utils import convert_list_message_to_dict
#########################################################
# Flag to disable token counter
# We've gotten reports of this consuming CPU cycles,
# exposing this flag to allow users to disable
# it to confirm if this is indeed the issue
#########################################################
if litellm.disable_token_counter is True:
return 0
verbose_logger.debug(
f"messages in token_counter: {messages}, text in token_counter: {text}"
)

View file

@ -4,6 +4,5 @@ model_list:
model: openai/*
litellm_settings:
disable_token_counter: True

View file

@ -1697,6 +1697,16 @@ def token_counter(
Kept for backwards compatibility.
"""
#########################################################
# Flag to disable token counter
# We've gotten reports of this consuming CPU cycles,
# exposing this flag to allow users to disable
# it to confirm if this is indeed the issue
#########################################################
if litellm.disable_token_counter is True:
return 0
return token_counter_new(
model,
custom_tokenizer,