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

Improved output message when using inference cache #1686

Merged
merged 6 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions examples/inference_using_ibm_watsonx_ai.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import os

from unitxt.api import load_dataset
from unitxt.inference import WMLInferenceEngine
from unitxt.inference import WMLInferenceEngineGeneration
from unitxt.text_utils import print_dict

if __name__ == "__main__":
# Set required env variables using your WML credentials:
os.environ["WML_URL"] = ""
os.environ["WML_PROJECT_ID"] = ""
os.environ["WML_APIKEY"] = ""
# os.environ["WML_URL"] = ""
# os.environ["WML_PROJECT_ID"] = ""
# os.environ["WML_APIKEY"] = ""

# Preparing WML inference engine:
model_name = "google/flan-t5-xl"
wml_inference = WMLInferenceEngine(
wml_inference = WMLInferenceEngineGeneration(
model_name=model_name,
data_classification_policy=["public"],
random_seed=111,
Expand Down
5 changes: 3 additions & 2 deletions src/unitxt/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ def infer(
else:
missing_examples.append((i, item)) # each element is index in batch and example
# infare on missing examples only, without indices
logger.info(f"Inferring batch {batch_num} / {len(dataset) // self.cache_batch_size}")
if len(missing_examples) > 0:
logger.info(f"Inferring batch {batch_num} / {len(dataset) // self.cache_batch_size} with {len(missing_examples)} instances (found {len(cached_results)} instances in {self._cache.directory})")
if (len(missing_examples) > 0):
inferred_results = self._infer([e[1] for e in missing_examples], return_meta_data)
# recombined to index and value
inferred_results = list(zip([e[0] for e in missing_examples], inferred_results))
Expand All @@ -257,6 +257,7 @@ def infer(
cache_key = self._get_cache_key(item)
self._cache[cache_key] = prediction
else:

inferred_results = []

# Combine cached and inferred results in original order
Expand Down
Loading