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

perf: improve logging for MLflow metrics #42

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Changes from 3 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
23 changes: 12 additions & 11 deletions src/autora/doc/pipelines/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def eval_prompts(
predictor = Predictor(model_path)
for i in range(len(prompts_list)):
logger.info(f"Starting to run model on prompt {i}")
eval_result = eval_prompt(data_file, predictor, prompts_list[i], param_dict)
eval_result = eval_prompt(data_file, predictor, prompts_list[i], param_dict, i)
logger.info(f"Model run completed on prompt {i}: {prompts_list[i]}")
results_list.append(eval_result)
return results_list
Expand Down Expand Up @@ -96,7 +96,9 @@ def eval(
return eval_prompt(data_file, pred, prompt, param_dict)


def eval_prompt(data_file: str, pred: Predictor, prompt: str, param_dict: Dict[str, float]) -> EvalResult:
def eval_prompt(
data_file: str, pred: Predictor, prompt: str, param_dict: Dict[str, float], prompt_index: int = 0
) -> EvalResult:
import mlflow

inputs, labels = load_data(data_file)
Expand All @@ -107,22 +109,21 @@ def eval_prompt(data_file: str, pred: Predictor, prompt: str, param_dict: Dict[s
bleu, meteor = eval_bleu_meteor(predictions, labels)
semscore = eval_semscore(predictions, labels)
pred_time = timer_end - timer_start
prompt_hash = hash(prompt)
mlflow.log_metric("prediction_time/doc", pred_time / (len(inputs)))
for i in range(len(inputs)):
mlflow.log_text(labels[i], f"{prompt_hash}_label_{i}.txt")
mlflow.log_text(inputs[i], f"{prompt_hash}_input_{i}.py")
mlflow.log_text(predictions[i], f"{prompt_hash}_prediction_{i}.txt")
mlflow.log_text(labels[i], f"prompt_{prompt_index}_label_{i}.txt")
anujsinha3 marked this conversation as resolved.
Show resolved Hide resolved
mlflow.log_text(inputs[i], f"prompt_{prompt_index}_input_{i}.py")
mlflow.log_text(predictions[i], f"prompt_{prompt_index}_prediction_{i}.txt")

# flatten predictions for counting tokens
predictions_flat = list(itertools.chain.from_iterable(predictions))
tokens = pred.tokenize(predictions_flat)["input_ids"]
total_tokens = sum([len(token) for token in tokens])
mlflow.log_metric("total_tokens", total_tokens)
mlflow.log_metric("tokens/sec", total_tokens / pred_time)
mlflow.log_metric("bleu_score", round(bleu, 5))
mlflow.log_metric("meteor_score", round(meteor, 5))
mlflow.log_metric("semscore", round(semscore, 5))
mlflow.log_metric(f"prompt_{prompt_index}_total_tokens", total_tokens)
mlflow.log_metric(f"prompt_{prompt_index}_tokens/sec", total_tokens / pred_time)
mlflow.log_metric(f"prompt_{prompt_index}_bleu_score", round(bleu, 5))
mlflow.log_metric(f"prompt_{prompt_index}_meteor_score", round(meteor, 5))
mlflow.log_metric(f"prompt_{prompt_index}_semscore", round(semscore, 5))
return EvalResult(predictions, prompt, bleu, meteor, semscore)


Expand Down
Loading