Skip to content
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

Changed litellm prints to tqdm and added execution metrics #45

Merged
merged 16 commits into from
Dec 7, 2024
Merged
12 changes: 9 additions & 3 deletions lotus/models/lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from litellm.utils import token_counter
from openai import OpenAIError
from tokenizers import Tokenizer
from tqdm import tqdm

import lotus
from lotus.cache import Cache
Expand Down Expand Up @@ -65,14 +66,19 @@ def __call__(self, messages: list[list[dict[str, str]]], **kwargs: dict[str, Any
[self._get_top_choice_logprobs(resp) for resp in all_responses] if all_kwargs.get("logprobs") else None
)

self.print_total_usage()
sidjha1 marked this conversation as resolved.
Show resolved Hide resolved
self.reset_stats()
sidjha1 marked this conversation as resolved.
Show resolved Hide resolved

return LMOutput(outputs=outputs, logprobs=logprobs)

def _process_uncached_messages(self, uncached_data, all_kwargs):
"""Processes uncached messages in batches and returns responses."""
uncached_responses = []
for i in range(0, len(uncached_data), self.max_batch_size):
batch = [msg for msg, _ in uncached_data[i : i + self.max_batch_size]]
uncached_responses.extend(batch_completion(self.model, batch, drop_params=True, **all_kwargs))
with tqdm(total=len(uncached_data), desc="Processing uncached messages") as pbar:
sidjha1 marked this conversation as resolved.
Show resolved Hide resolved
for i in range(0, len(uncached_data), self.max_batch_size):
batch = [msg for msg, _ in uncached_data[i : i + self.max_batch_size]]
uncached_responses.extend(batch_completion(self.model, batch, drop_params=True, **all_kwargs))
pbar.update(len(batch))
return uncached_responses

def _cache_response(self, response, hash):
Expand Down
Loading