#12989·mlflow

[BUG] .evaluate() raises due to failure in computing dataset hash

Author: drooms-sandrusCreated Aug 21, 2024Updated Sep 30, 2026
Labelsbughas-closing-pr

Issues Policy acknowledgement

  • I have read and agree to submit bug reports in accordance with the issues policy

Where did you encounter this bug?

Local machine

Willingness to contribute

Yes. I can contribute a fix for this bug independently.

MLflow version

  • Client: 2.14.3
  • Tracking server: 2.14.3

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 22.04
  • Python version: 3.12
  • yarn version, if running the dev UI:

Describe the problem

We aim to evaluate a model with mlflow.evaluate() that requires a custom dataset structure with nested fields in some cells. Here's a minimal example of a row in said dataset (the actual structure is more complex, I've stripped information for the sake of simplicity):

jsonl
{ "id": "1", "expected_results": [ { "id": "1", "text": "The main idea of the document is to provide an overview of the project."}, { "id": "2", "text": "The expected outcomes of the project were to gain insights and develop a robust solution."} ] }

This dataset is then converted into a tabular format when it is loaded ((with targets="expected_results"):

id expected_results
1 [ { "id": "1", "text": "The main idea of the document is to provide an overview of the project."}, { "id": "2", "text": "The expected outcomes of the project were to gain insights and develop a robust solution."} ]
... ...

Lastly, mlflow.evaluate() fails while computing the hash for the expected_results column in this dataset, as can be seen from the stack trace.

I've had a look at the code of the latest mlflow version (2.15.1) to see whether this issue is fixed, and it seems to still be in the code.

The easiest and least intrusive solution to fix this issue is to wrap the line hashable = np.array(data.tolist()) in _hash_array_like_obj_as_bytes() into a try-except clause and return an empty byte string in the case of an exception (similarly to how it is done some lines above inside _hash_array_like_element_as_bytes()).

However, it's unexpected that .evaluate() functionality fails due to issues when computing a dataset hash - especially since it's not necessary for evaluation per-se. Further, there are other ways to track which dataset was used, if necessary.

Consequently, a proper solution is to wrap code inside _gen_md5_for_arraylike_obj in a try-except clause and issue a warning (along with an empty byte string being returned) if a dataset hash cannot be computed.

NOTE: The stacktrace and code example use .to_evaluation_dataset() instead of evaluate(), as the issue is easier to reproduce this way.

Tracking information

bash
REPLACE_ME

Code to reproduce issue

python
import mlflow
from datasets import Dataset, load_dataset
from mlflow.data.huggingface_dataset import HuggingFaceDataset, from_huggingface


def evaluate(ground_truth_path: str) -> None:
    dataset: Dataset = load_dataset(
        data_files=ground_truth_path, split="train", path="json"
    )

    mlflow_dataset: HuggingFaceDataset = from_huggingface(
        dataset, targets="expected_results"
    )
    mlflow_dataset.to_evaluation_dataset()


with mlflow.start_run():
    # the structure of the file located at "file.jsonl" is described above
    evaluate("./path/to/file.jsonl")

Stack trace

python
Traceback (most recent call last):
  File "/home/user/.../test.py", line 19, in <module>
    evaluate("tests/resources/data/test.jsonl")
  File "/home/user/.../test.py", line 14, in evaluate
    mlflow_dataset.to_evaluation_dataset()
  File "/home/user/miniconda3/envs/ar/lib/python3.12/site-packages/mlflow/data/huggingface_dataset.py", line 167, in to_evaluation_dataset
    return EvaluationDataset(
           ^^^^^^^^^^^^^^^^^^
  File "/home/user/miniconda3/envs/ar/lib/python3.12/site-packages/mlflow/models/evaluation/base.py", line 767, in __init__
    _gen_md5_for_arraylike_obj(md5_gen, self._labels_data)
  File "/home/user/miniconda3/envs/ar/lib/python3.12/site-packages/mlflow/models/evaluation/base.py", line 577, in _gen_md5_for_arraylike_obj
    md5_gen.update(_hash_array_like_obj_as_bytes(data))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/miniconda3/envs/ar/lib/python3.12/site-packages/mlflow/models/evaluation/base.py", line 557, in _hash_array_like_obj_as_bytes
    hashable = np.array(data.tolist())
               ^^^^^^^^^^^^^^^^^^^^^^^
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (5,) + inhomogeneous part.

Other info / logs

REPLACE_ME

What component(s) does this bug affect?

  • area/artifacts: Artifact stores and artifact logging
  • area/build: Build and test infrastructure for MLflow
  • area/deployments: MLflow Deployments client APIs, server, and third-party Deployments integrations
  • area/docs: MLflow documentation pages
  • area/examples: Example code
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/recipes: Recipes, Recipe APIs, Recipe configs, Recipe Templates
  • area/projects: MLproject format, project running backends
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/server-infra: MLflow Tracking server backend
  • area/tracking: Tracking Service, tracking client APIs, autologging

What interface(s) does this bug affect?

  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/docker: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
  • area/sqlalchemy: Use of SQLAlchemy in the Tracking Service or Model Registry
  • area/windows: Windows support

What language(s) does this bug affect?

  • language/r: R APIs and clients
  • language/java: Java APIs and clients
  • language/new: Proposals for new client languages

What integration(s) does this bug affect?

  • integrations/azure: Azure and Azure ML integrations
  • integrations/sagemaker: SageMaker integrations
  • integrations/databricks: Databricks integrations