Skip to content

Commit

Permalink
feat: Use default file name if one isn't provided when uploading eval…
Browse files Browse the repository at this point in the history
…uation results to GCS.

PiperOrigin-RevId: 725319500
  • Loading branch information
vertex-sdk-bot authored and copybara-github committed Feb 11, 2025
1 parent 1ab4344 commit 44416dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions tests/unit/vertexai/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2176,3 +2176,18 @@ def test_upload_results(self, mock_storage_blob_from_string):
},
mock.ANY,
)

def test_upload_results_with_default_file_name(self, mock_storage_blob_from_string):
with mock.patch(
"google.cloud.aiplatform.aiplatform.utils.timestamped_unique_name"
) as mock_timestamped_unique_name:
mock_timestamped_unique_name.return_value = "2025-02-10-12-00-00-12345"
evaluation.utils.upload_evaluation_results(
MOCK_EVAL_RESULT,
_TEST_BUCKET,
)

mock_storage_blob_from_string.assert_any_call(
uri="gs://test-bucket/eval_results_2025-02-10-12-00-00-12345/eval_results_2025-02-10-12-00-00-12345.csv",
client=mock.ANY,
)
6 changes: 4 additions & 2 deletions vertexai/evaluation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def _upload_file_to_gcs(upload_gcs_path: str, filename: str) -> None:
def upload_evaluation_results(
eval_result: eval_base.EvalResult,
destination_uri_prefix: str,
file_name: str,
file_name: Optional[str] = None,
candidate_model_name: Optional[str] = None,
baseline_model_name: Optional[str] = None,
dataset_uri: Optional[str] = None,
Expand All @@ -347,7 +347,7 @@ def upload_evaluation_results(
Args:
eval_result: Eval results to upload.
destination_uri_prefix: GCS folder to store the data.
file_name: File name to store the metrics table.
file_name: Optional. File name to store the metrics table.
candidate_model_name: Optional. Candidate model name.
baseline_model_name: Optional. Baseline model name.
dataset_uri: Optional. URI pointing to the dataset.
Expand All @@ -359,6 +359,8 @@ def upload_evaluation_results(
if eval_result.metrics_table is None:
return
if destination_uri_prefix.startswith(_GCS_PREFIX):
if not file_name:
file_name = f"eval_results_{utils.timestamped_unique_name()}.csv"
base_name, extension = os.path.splitext(file_name)
file_type = extension.lower()[1:]
output_folder = destination_uri_prefix + "/" + base_name
Expand Down

0 comments on commit 44416dd

Please sign in to comment.