test_disable_sliding_window.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. """Compare the with and without prefix caching.
  2. Run `pytest tests/prefix_caching/test_prefix_caching.py`.
  3. """
  4. import pytest
  5. from aphrodite import LLM
  6. from tests.conftest import cleanup
  7. MODEL_LEN_LEN = [
  8. # Example models with sliding window.
  9. ("bigcode/starcoder2-3b", 4096, 16384),
  10. # ("mistralai/Mistral-7B-v0.1", 4096, 32768), << OOM in CI
  11. # Confirm model with sliding window works.
  12. # config has "use_sliding_window": false
  13. ("Qwen/Qwen1.5-0.5B-Chat", 32768, 32768),
  14. # config has no sliding window attribute.
  15. ("TinyLlama/TinyLlama-1.1B-Chat-v1.0", 2048, 2048),
  16. ]
  17. @pytest.mark.parametrize("model_len_len", MODEL_LEN_LEN)
  18. def test_disable_sliding_window(model_len_len, ):
  19. model, sliding_len, full_len = model_len_len
  20. aphrodite_disabled_model = LLM(model, disable_sliding_window=True)
  21. aphrodite_disabled_model.generate("Hi my name is")
  22. model_config = aphrodite_disabled_model.llm_engine.model_config
  23. assert model_config.max_model_len == sliding_len, (
  24. f"Max len expected to equal sliding_len of {sliding_len}, "
  25. f"but got {model_config.max_model_len}"
  26. )
  27. del aphrodite_disabled_model
  28. cleanup()
  29. aphrodite_enabled_model = LLM(model, disable_sliding_window=False)
  30. aphrodite_enabled_model.generate("Hi my name is")
  31. model_config = aphrodite_enabled_model.llm_engine.model_config
  32. assert model_config.max_model_len == full_len, (
  33. f"Max len expected to equal full_len of {full_len}, "
  34. f"but got {model_config.max_model_len}"
  35. )
  36. del aphrodite_enabled_model
  37. cleanup()