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

Format token utils and test #51

Merged
merged 2 commits into from
Apr 24, 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
2 changes: 1 addition & 1 deletion jetstream/engine/token_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def tokenize_and_pad(
as prefill is typically used when beginning sequences.
prefill_lengths: Buckets to pad the sequence to for static compilation.
max_prefill_length: Maximum bucket to use.
jax_padding: convert to JAX padded tokens if True.
jax_padding: convert to JAX padded tokens if True.

Returns:
tokens: Tokenized into integers.
Expand Down
15 changes: 8 additions & 7 deletions jetstream/tests/engine/test_token_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ def test_sp_vs_seqio(self):
def test_underscore_in_output(self):
self.setup()
n = 21326
mix_output = token_utils.mix_decode(
vocab=self.jt_tokenizer.vocab, tok_id=n)
mix_output = token_utils.mix_decode(vocab=self.jt_tokenizer.vocab, tok_id=n)
decode_output = self.sp_tokenizer.decode([n])
self.assertEqual(mix_output, " `__")
self.assertEqual(mix_output.lstrip(), decode_output)
Expand All @@ -118,8 +117,9 @@ def test_tokenize_and_pad_jax(self):
vocab=vocab,
max_prefill_length=max_prefill_length,
)
expected_padded_tokens = jnp.array([1, 306, 4658, 278, 6593, 310, 2834, 338,
0, 0, 0, 0, 0, 0, 0, 0])
expected_padded_tokens = jnp.array(
[1, 306, 4658, 278, 6593, 310, 2834, 338, 0, 0, 0, 0, 0, 0, 0, 0]
)
expected_true_length = 8
self.assertTrue(
jnp.allclose(padded_tokens, expected_padded_tokens, atol=1e-7)
Expand All @@ -135,10 +135,11 @@ def test_tokenize_and_pad_np(self):
s=s,
vocab=vocab,
max_prefill_length=max_prefill_length,
jax_padding=False
jax_padding=False,
)
expected_padded_tokens = np.array(
[1, 306, 4658, 278, 6593, 310, 2834, 338, 0, 0, 0, 0, 0, 0, 0, 0]
)
expected_padded_tokens = np.array([1, 306, 4658, 278, 6593, 310, 2834, 338,
0, 0, 0, 0, 0, 0, 0, 0])
expected_true_length = 8
self.assertTrue(
np.allclose(padded_tokens, expected_padded_tokens, atol=1e-7)
Expand Down
Loading