Skip to content

Commit

Permalink
Throw error when no EOS (#922)
Browse files Browse the repository at this point in the history
  • Loading branch information
KuuCi committed Feb 1, 2024
1 parent 203edad commit 4b82876
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions llmfoundry/utils/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ def build_tokenizer(
int(1e30),
)

if not hasattr(tokenizer, 'eos_token') or tokenizer.eos_token is None:
raise ValueError(
f'The tokenizer {tokenizer_name} must have an eos_token.')

if dist.is_available() and dist.is_initialized(
) and dist.get_world_size() > 1:
if dist.get_local_rank() == 0:
Expand Down
7 changes: 7 additions & 0 deletions tests/utils/test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ def test_tokenizer_builder(tokenizer_name: str, tokenizer_kwargs: dict):
assert isinstance(tokenizer, PreTrainedTokenizerBase)


def test_tokenizer_no_EOS():
with pytest.raises(
ValueError,
match='The tokenizer bert-base-uncased must have an eos_token.'):
build_tokenizer('bert-base-uncased', {})


def test_build_callback_fails():
with pytest.raises(ValueError):
build_callback('nonexistent_callback', {}, {})
Expand Down

0 comments on commit 4b82876

Please sign in to comment.