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

Exception handling when reading the jsonl file. #3713

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Changes from all 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
39 changes: 35 additions & 4 deletions assets/training/distillation/src/validate_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pandas as pd
import json
from argparse import Namespace

from pathlib import Path
from azureml.acft.contrib.hf import VERSION, PROJECT_NAME
from azureml.acft.contrib.hf.nlp.constants.constants import (
LOGS_TO_BE_FILTERED_IN_APPINSIGHTS,
Expand Down Expand Up @@ -93,9 +93,40 @@ def __init__(self, args: Namespace) -> None:
self._validate_data_generation_inputs()

def _get_dataframe(self, file_path: str):
return pd.read_json(
file_path, lines=True, chunksize=self._args.request_batch_size
)
if not Path(file_path).is_file():
raise ACFTValidationException._with_error(
AzureMLError.create(
ACFTUserError,
pii_safe_message=(
f"File not found at {file_path}. Please provide a valid file path."
),
)
)
try:
return pd.read_json(
file_path, lines=True, chunksize=self._args.request_batch_size
)
except ValueError as e:
# If the file is not present pandas will read it as jsonl string
# raises a ValueError if it is not a valid jsonl string.
# also raises value error if it is not a valid jsonl file.
raise ACFTValidationException._with_error(
AzureMLError.create(
ACFTUserError,
pii_safe_message=(
f"Error while reading JSON file. Make sure the file is a valid jsonl file. Error: {e}"
),
)
)
except Exception as e:
raise ACFTValidationException._with_error(
AzureMLError.create(
ACFTUserError,
pii_safe_message=(
f"An unexpected error occurred while reading the file: {e}"
),
)
)

def _get_inference_request_headers(self) -> dict:
key = self._args.teacher_model_endpoint_key
Expand Down
Loading