Skip to content

Commit c80e41c

Browse files
gustavocidornelaswhoseoyster
authored andcommitted
Completes OPEN-4820 Add column with timestamp for each prediction for model runners
1 parent d409be3 commit c80e41c

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

examples/llms/general-llm/product-names.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@
356356
"outputs": [],
357357
"source": [
358358
"# There are costs in running this cell!\n",
359-
"dataset[\"model_output\"] = llm_runner.run(dataset)"
359+
"dataset[\"model_output\"] = llm_runner.run(dataset)[\"predictions\"]"
360360
]
361361
},
362362
{

examples/llms/ner/entity-extraction.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@
389389
"outputs": [],
390390
"source": [
391391
"# There are costs in running this cell!\n",
392-
"dataset[\"model_output\"] = llm_runner.run(dataset)"
392+
"dataset[\"model_output\"] = llm_runner.run(dataset)[\"predictions\"]"
393393
]
394394
},
395395
{

openlayer/model_runners/ll_model_runners.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55

66
import logging
7+
import time
78
import warnings
89
from abc import ABC, abstractmethod
910
from typing import Any, Dict, List, Optional, Union
@@ -67,10 +68,11 @@ def _run_in_memory(
6768
) -> pd.DataFrame:
6869
"""Runs the input data through the model in memory."""
6970
self.logger.info("Running LLM in memory...")
71+
7072
model_outputs = []
73+
timestamps = []
7174
run_exceptions = set()
7275
run_cost = 0
73-
7476
for input_data_row in input_data_df.iterrows():
7577
# Check if output column already has a value to avoid re-running
7678
if (
@@ -96,6 +98,7 @@ def _run_in_memory(
9698
except Exception as exc:
9799
model_outputs.append(None)
98100
run_exceptions.add(exc)
101+
timestamps.append(time.time())
99102

100103
self.logger.info("Successfully ran data through the model!")
101104

@@ -110,7 +113,7 @@ def _run_in_memory(
110113
)
111114
self.cost_estimates.append(run_cost)
112115

113-
return pd.DataFrame({"predictions": model_outputs})
116+
return pd.DataFrame({"predictions": model_outputs, "timestamps": timestamps})
114117

115118
def _inject_prompt(self, input_variables_dict: dict) -> List[Dict[str, str]]:
116119
"""Injects the input variables into the prompt template.

openlayer/model_runners/traditional_ml_model_runners.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import shutil
99
import tempfile
10+
import time
1011
from abc import ABC, abstractmethod
1112

1213
import pandas as pd
@@ -71,6 +72,7 @@ def _run_in_conda(self, input_data: pd.DataFrame) -> pd.DataFrame:
7172
output_data = pd.read_csv(f"{temp_dir}/output_data.csv")
7273

7374
output_data = self._post_process_output(output_data)
75+
output_data["timestamps"] = time.time()
7476

7577
return output_data
7678

0 commit comments

Comments
 (0)