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

Add methods to log the results of the api runner to a server #177

Merged
merged 10 commits into from
Jun 24, 2024
23 changes: 15 additions & 8 deletions eval/api_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def run_api_eval(args):
logprobs = args.logprobs
cot_table_alias = args.cot_table_alias
sql_lora_path = args.adapter if args.adapter else None
run_name = args.run_name if args.run_name else None
if sql_lora_path:
print("Using LoRA adapter at:", sql_lora_path)
if logprobs:
Expand Down Expand Up @@ -302,11 +303,17 @@ def run_api_eval(args):
# with open(prompt_file, "r") as f:
# prompt = f.read()

# if args.upload_url is not None:
# upload_results(
# results=results,
# url=args.upload_url,
# runner_type="api_runner",
# prompt=prompt,
# args=args,
# )
if run_name is None:
run_name = output_file.split("/")[-1].replace(".csv", "")
print(
"Run name not provided. Using a output filename for run name:", run_name
)

if args.upload_url is not None:
upload_results(
results=results,
Copy link
Collaborator

@wongjingping wongjingping Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like results is only created in L289 when logprobs is true:

results = output_df.to_dict("records")

And I think this might fail if logprobs is True and upload_url is provided (eg if the user is not exporting logprobs, say when using TGI or some other inference API), since results hasn't yet been defined in that code path.

Shall we update the code before the check in L285 to output results regardless of whether logprobs is provided?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point, done!

url=args.upload_url,
runner_type="api_runner",
args=args,
run_name=run_name,
)
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
parser.add_argument("-v", "--verbose", action="store_true")
parser.add_argument("-l", "--logprobs", action="store_true")
parser.add_argument("--upload_url", type=str)
parser.add_argument("--run_name", type=str, required=False)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a param to optionally add a run name when we are running an eval

this run name is then stored as a static JSON object, and can be used by the eval visualizer

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! nit: shall we update the README with the new option as well? 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thank you for pointing this out!

parser.add_argument(
"-qz", "--quantized", default=False, action=argparse.BooleanOptionalAction
)
Expand Down
2 changes: 1 addition & 1 deletion utils/creds.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"creds": os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"),
},
"sqlite": {
"path_to_folder": f"{os.path.expanduser('~')}/workspace/defog-data/sqlite_dbs/", # Path to folder containing sqlite dbs
"path_to_folder": f"./defog-data/sqlite_dbs/", # Path to folder containing sqlite dbs
},
"tsql": {
"server": os.getenv("TSQL_SERVER"),
Expand Down
16 changes: 2 additions & 14 deletions utils/reporting.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import json
import requests
from uuid import uuid4
from datetime import datetime
import os
import hashlib


# get the GPU name this is running on
Expand Down Expand Up @@ -81,8 +79,8 @@ def num_gpus():
def upload_results(
results: list,
url: str,
run_name: str,
runner_type: str,
prompt: str,
args: dict,
):
"""
Expand All @@ -94,26 +92,16 @@ def upload_results(
# Create a unique id for the request
run_id = uuid4().hex

# Create a unique id for the prompt, based on a hash of the prompt
prompt_id = hashlib.md5(prompt.encode()).hexdigest()

# Create a dictionary with the request id and the results
data = {
"run_id": run_id,
"results": results,
"timestamp": datetime.now().isoformat(),
"runner_type": runner_type,
"prompt": prompt,
"prompt_id": prompt_id,
"model": args.model,
"num_beams": args.num_beams,
"db_type": args.db_type,
"gpu_name": get_gpu_name(),
"gpu_memory": get_gpu_memory(),
"gpu_driver_version": get_gpu_driver_version(),
"gpu_cuda_version": get_gpu_cuda_version(),
"num_gpus": num_gpus(),
"run_args": vars(args),
"run_name": run_name,
}
# Send the data to the server
response = requests.post(url, json=data)
Expand Down
19 changes: 19 additions & 0 deletions utils/upload_report_gcloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# this is a Google cloud function for receiving the data from the web app and storing it in the database
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: shall we add the command for launching this cloud function (in case we need to modify it and relaunch in the future)?


import functions_framework
from google.cloud import storage
import json

BUCKET_NAME = "YOUR-BUCKET-NAME"


@functions_framework.http
def hello_http(request):
request_json = request.get_json(silent=True)
results = request_json["results"]
run_name = request_json["run_name"]
storage_client = storage.Client()
bucket = storage_client.bucket(BUCKET_NAME)
blob = bucket.blob(run_name + ".json")
blob.upload_from_string(json.dumps(results))
return "success"
Loading