-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0ce48e
commit 192fef3
Showing
4 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
import pytest | ||
from decode_tests_utils import * | ||
|
||
|
||
# All tests in this file are for jetstream | ||
pytestmark = pytest.mark.jetstream | ||
|
||
@pytest.mark.filterwarnings("ignore:.*:UserWarning") | ||
def test_decode_single_jetstream_pytorch(): | ||
params = DecodeTestParams( | ||
model_id="Qwen/Qwen2.5-0.5B", | ||
sequence_length=256, | ||
expected_text=" Winston Smith, his chin nuzzled into his breast, stretched, and looked out across the city", | ||
max_new_tokens=1, | ||
) | ||
|
||
|
||
model_path = prepare_model(params.model_id, params.sequence_length) | ||
input_text = "It was a bright cold day in April, and the clocks were striking thirteen." | ||
max_new_tokens = params.max_new_tokens | ||
|
||
generator = AutoGenerator.from_pretrained( | ||
model_path, revision="", max_batch_size=1, max_sequence_length=params.sequence_length | ||
) | ||
request = create_request( | ||
id=0, | ||
inputs=input_text, | ||
max_new_tokens=max_new_tokens, | ||
do_sample=params.do_sample, | ||
top_k=params.top_k, | ||
seed=1234, | ||
repetition_penalty=params.repetition_penalty, | ||
) | ||
batch = Batch(id=0, requests=[request], size=1, max_tokens=params.sequence_length) | ||
generations, next_batch = generator.prefill(batch) | ||
print(f"generations prefill: {generations}") | ||
# We already generated one token: call decode max_new_tokens - 1 times | ||
for _ in tqdm(range(max_new_tokens - 1)): | ||
assert next_batch.size == 1 | ||
assert next_batch.max_tokens == params.sequence_length | ||
assert len(generations) == 1 | ||
assert len(generations[0].tokens.ids) == 1 | ||
generations, next_batch = generator.decode([next_batch]) | ||
# Destroy generator: this will properly stop threads and prevent them from getting stuck if one of the following | ||
# assertions fails. | ||
del generator | ||
assert next_batch is None | ||
assert len(generations) == 1 | ||
output = generations[0].generated_text | ||
assert output.generated_tokens == max_new_tokens | ||
assert output.finish_reason == 0 | ||
# print(f"generations: {generations}") | ||
print(f"Generated text: {output.text}") | ||
if params.do_sample: | ||
if output.text == params.expected_text: | ||
print("❌: Expected text is equal to generated text") | ||
return | ||
else: | ||
if output.text != params.expected_text: | ||
print("❌: Expected text is not equal to generated text") | ||
return | ||
print("✅: Test passed") |