Skip to content

Commit

Permalink
Clearer error message for unknown example type (#1202)
Browse files Browse the repository at this point in the history
* error when example is a string

* make error message the same

* strings only

---------

Co-authored-by: Daniel King <[email protected]>
  • Loading branch information
milocress and dakinggg authored May 14, 2024
1 parent 0449b60 commit 8274c6c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion llmfoundry/data/finetuning/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _get_example_type(example: Example) -> ExampleType:
):
return 'prompt_response'
else:
raise UnknownExampleTypeError(example)
raise UnknownExampleTypeError(str(example.keys()))


def _is_empty_or_nonexistent(dirpath: str) -> bool:
Expand Down
8 changes: 4 additions & 4 deletions llmfoundry/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0

"""Custom exceptions for the LLMFoundry."""
from collections.abc import Mapping
from typing import Any, Dict, List

__all__ = [
Expand Down Expand Up @@ -79,13 +78,14 @@ def __init__(
class UnknownExampleTypeError(KeyError):
"""Error thrown when an unknown example type is used in a task."""

def __init__(self, example: Mapping) -> None:
self.example = example
def __init__(self, example_keys: str) -> None:
self.example = example_keys
message = (
f'Found keys {example.keys()} in dataset. Unknown example type. For prompt and response '
f'Found keys {example_keys} in dataset. Unknown example type. For prompt and response '
f'finetuning, the valid prompt keys are {ALLOWED_PROMPT_KEYS} and the valid response keys are '
f'{ALLOWED_RESPONSE_KEYS}. For chat finetuning, the allowed keys are {ALLOWED_MESSAGES_KEYS}'
)

super().__init__(message)


Expand Down

0 comments on commit 8274c6c

Please sign in to comment.