googleapis / googleapis/python-aiplatform

Batch prediction results are not guaranteed to be in the right order

Ouverte
#1,166 5 commentaires 1 réaction 1 personne assignée Assignée à @weichungw Voir sur GitHub
aiplatform api: vertex-ai type: feature request
Langage dominant
Python
Étoiles
905
Forks
465
Merge moyen
1 j 13 h
PR mergées (30 j)
44

Description

#### Environment details

- OS type and version: MacOS 12.3.1
- Python version: 3.9.10
- pip version: 22.0.3
- `google-cloud-aiplatform` version: 1.12.0

#### Steps to reproduce

1. run a batch `BatchPredictionJob` that outputs multiple `prediction-results-xxxxx-to-xxxxx` files.
2. the order of the predictions does not always match the order of the inputs.

#### Code example

This happens with official code examples such as [sdk-custom-image-classification-batch.ipynb](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/36455b8125802459f3a40752fbda0e4c9407c854/notebooks/official/custom/sdk-custom-image-classification-batch.ipynb). The relevant part of the code is this:

```python
# Get downloaded results in directory
results_files = []
for dirpath, subdirs, files in os.walk(latest_directory):
for file in files:
if file.startswith("prediction.results"):
results_files.append(os.path.join(dirpath, file))

# Consolidate all the results into a list
results = []
for results_file in results_files:
# Download each result
with open(results_file, "r") as file:
results.extend([json.loads(line) for line in file.readlines()])

```

Firstly, `os.walk()` does not guarantee the order. In practice, it seems to respect the order, but it's brittle to count on this.

Secondly, and more importantly, I've run into cases where the files were not in the same order as the inputs. I would get 7% accuracy on MNIST, then by just reversing the order of the prediction files, I would get 100%.

Thirdly, I haven't tested it but I suspect that the order would also be wrong if there's any error on any instance.

Lastly, the inputs may sometimes be large, and it's not efficient to include them in the predictions. I would much rather have an input identifier, such as its source file and its line index.

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.