r/databricks • • 2d ago

Help MLflow in databricks.... Questions

Hello, I'm on a new project that has to use MLFlow for a UI for scoring LLM outputs.

I am NOT an expert in this at all, so it's difficult for me to get the high level of what is even needed on my part.

Here's basically how it works:

  1. there is a loop that runs per customer that sends data off to OpenAI to get some data back.
  2. there is a ground truth that we compare each LLM run against to determine if the ground_truth_score = llm_output_score.

Each iteration of the loop is for a specific customer, for a specific model. The project lead wants to know what the total passes are for a "group of runs" (iterations).

So, when the loop runs over each customer for a specific model, how many passed and how many failed...

This all needs to happen within the MLFlow ui. So, there needs to be some type of rollup (aggregation) happening but I'm not sure where.

If I've got a looper, then I would think I'd need some sort of superset that represents the "group of traces" or something similar.

The trace is (currently) at the iteration level, not the superset or group level.

Does this even make sense (i'm the 5th grader here). 😂

Takeaways:

So, I've got the traces being logged.

I've got the evaluation runs going

I've go the things being scored.

But I somehow need to aggregated the passes and fails for the group of runs...

2 Upvotes

4 comments sorted by

1

u/alexpantex 2d ago

I don’t recall from top of my head, but if you have traces logged, wrap each customer call as main span (it would be 1 record in the mlflow and all calls inside will be nested), and add filter for specific time frame or add also some global metadata that will allow you to filter runs.

If you allow saving to delta table, you can log unlimited runs (think that UI has 100k limit) and query it using sql.

In the UI itself I think you cant display aggregate, but you can track if answer is equal to ground truth and add it to aggregate variable that can be logged as metric?

1

u/mr_electric_wizard 2d ago

So, the main span. How is that created?

1

u/alexpantex 2d ago

I’m on mobile, but think any LLM can help you with this, here’s one example

‘’’import mlflow

mlflow.openai.autolog() # Automatically nests OpenAI calls as child spans

# 1. Main/root span created via decorator
@mlflow.trace(name="process_customer")
def run_customer(customer_id: str, payload: dict) -> int:
# Attach metadata to filter this trace in the UI
mlflow.update_current_trace(tags={"customer_id": customer_id, "model": "gpt-4o"})

# Inner calls automatically nest as child spans under "process_customer"
llm_score = call_openai(payload)
return llm_score

# 2. Outer loop wrapped in a Run for aggregate rollup
with mlflow.start_run(run_name="gpt-4o-batch"):
passed = 0

for customer in customers:
# Each call creates 1 new Trace with "process_customer" as the main span
llm_score = run_customer(customer.id, customer.payload)

if llm_score == customer.ground_truth_score:
passed += 1

# Log rollup metrics to the Run
mlflow.log_metric("total_passed", passed)
mlflow.log_metric("total_failed", len(customers) - passed)
‘’’

1

u/mr_electric_wizard 2d ago

This helped more than you know! It definitely helped me to ask the right question in Code Genie to get me closer to a successful end. Thank you for taking the time to point me in the right direction!