1
0

test_detokenization.py 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. import pytest
  2. from aphrodite.common.sampling_params import SamplingParams
  3. from aphrodite.endpoints.llm import LLM
  4. @pytest.mark.parametrize("model", ["facebook/opt-125m"])
  5. def test_computed_prefix_blocks(model: str):
  6. # This test checks if the engine generates completions both with and
  7. # without optional detokenization, that detokenization includes text
  8. # and no-detokenization doesn't, and that both completions have the same
  9. # token_ids.
  10. prompt = (
  11. "You are a helpful assistant. How do I build a car from cardboard and "
  12. "paper clips? Is there an easy to follow video tutorial available "
  13. "online for free?")
  14. llm = LLM(model=model)
  15. sampling_params = SamplingParams(max_tokens=10,
  16. temperature=0.0,
  17. detokenize=False)
  18. outputs_no_detokenization = llm.generate(prompt,
  19. sampling_params)[0].outputs[0]
  20. sampling_params.detokenize = True
  21. outputs_with_detokenization = llm.generate(prompt,
  22. sampling_params)[0].outputs[0]
  23. assert outputs_no_detokenization.text == ''
  24. assert outputs_with_detokenization.text != ''
  25. assert outputs_no_detokenization.token_ids == \
  26. outputs_with_detokenization.token_ids