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

Throw error when no EOS #922

Merged
merged 5 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
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
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
Loading