|
| 1 | +import pytest |
| 2 | + |
| 3 | +MODELS = ["ai21labs/Jamba-tiny-random"] |
| 4 | + |
| 5 | + |
| 6 | +@pytest.mark.parametrize("model", MODELS) |
| 7 | +@pytest.mark.parametrize("dtype", ["float"]) |
| 8 | +@pytest.mark.parametrize("max_tokens", [20]) |
| 9 | +def test_models( |
| 10 | + hf_runner, |
| 11 | + vllm_runner, |
| 12 | + example_prompts, |
| 13 | + model: str, |
| 14 | + dtype: str, |
| 15 | + max_tokens: int, |
| 16 | +) -> None: |
| 17 | + # To pass the small model tests, we need full precision. |
| 18 | + assert dtype == "float" |
| 19 | + |
| 20 | + with hf_runner(model, dtype=dtype) as hf_model: |
| 21 | + hf_outputs = hf_model.generate_greedy(example_prompts, max_tokens) |
| 22 | + |
| 23 | + with vllm_runner(model, dtype=dtype) as vllm_model: |
| 24 | + vllm_outputs = vllm_model.generate_greedy(example_prompts, max_tokens) |
| 25 | + |
| 26 | + for i in range(len(example_prompts)): |
| 27 | + hf_output_ids, hf_output_str = hf_outputs[i] |
| 28 | + vllm_output_ids, vllm_output_str = vllm_outputs[i] |
| 29 | + assert hf_output_str == vllm_output_str, ( |
| 30 | + f"Test{i}:\nHF: {hf_output_str!r}\nvLLM: {vllm_output_str!r}") |
| 31 | + assert hf_output_ids == vllm_output_ids, ( |
| 32 | + f"Test{i}:\nHF: {hf_output_ids}\nvLLM: {vllm_output_ids}") |
| 33 | + |
| 34 | + |
| 35 | +@pytest.mark.parametrize("model", MODELS) |
| 36 | +@pytest.mark.parametrize("dtype", ["float"]) |
| 37 | +def test_state_cleanup( |
| 38 | + vllm_runner, |
| 39 | + model: str, |
| 40 | + dtype: str, |
| 41 | + example_prompts, |
| 42 | +) -> None: |
| 43 | + # This test is for verifying that the Jamba state is cleaned up between |
| 44 | + # steps, If its not cleaned, an error would be expected. |
| 45 | + try: |
| 46 | + with vllm_runner(model, dtype=dtype) as vllm_model: |
| 47 | + for _ in range(10): |
| 48 | + vllm_model.generate_greedy([example_prompts[0]] * 100, 1) |
| 49 | + except ValueError: |
| 50 | + pytest.fail("Jamba inner state wasn't cleaned up between states, " |
| 51 | + "could be related to finished_requests_ids") |
| 52 | + |
| 53 | + |
| 54 | +@pytest.mark.parametrize("model", MODELS) |
| 55 | +@pytest.mark.parametrize("dtype", ["float"]) |
| 56 | +def test_model_print( |
| 57 | + vllm_runner, |
| 58 | + model: str, |
| 59 | + dtype: str, |
| 60 | +) -> None: |
| 61 | + with vllm_runner(model, dtype=dtype) as vllm_model: |
| 62 | + # This test is for verifying whether the model's extra_repr |
| 63 | + # can be printed correctly. |
| 64 | + print(vllm_model.model.llm_engine.model_executor.driver_worker. |
| 65 | + model_runner.model) |
0 commit comments