[Bugfix / Core] Prefix Caching Guards (merged with main) (#4846)
Co-authored-by: rsnm2 <rshaw@neuralmagic.com> Co-authored-by: Robert Shaw <114415538+robertgshaw2-neuralmagic@users.noreply.github.com>
This commit is contained in:
co-authored by
rsnm2
Robert Shaw
parent
f17a1a8f96
commit
1102bef219
@@ -0,0 +1,44 @@
|
||||
"""Compare the with and without prefix caching.
|
||||
|
||||
Run `pytest tests/prefix_caching/test_prefix_caching.py`.
|
||||
"""
|
||||
import pytest
|
||||
|
||||
from tests.conftest import cleanup
|
||||
from vllm import LLM
|
||||
|
||||
MODEL_LEN_LEN = [
|
||||
# Example models with sliding window.
|
||||
("bigcode/starcoder2-3b", 4096, 16384),
|
||||
# ("mistralai/Mistral-7B-v0.1", 4096, 32768), << OOM in CI
|
||||
|
||||
# Confirm model with sliding window works.
|
||||
# config has "use_sliding_window": false
|
||||
("Qwen/Qwen1.5-0.5B-Chat", 32768, 32768),
|
||||
# config has no sliding window attribute.
|
||||
("TinyLlama/TinyLlama-1.1B-Chat-v1.0", 2048, 2048),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("model_len_len", MODEL_LEN_LEN)
|
||||
def test_disable_sliding_window(model_len_len, ):
|
||||
model, sliding_len, full_len = model_len_len
|
||||
vllm_disabled_model = LLM(model, disable_sliding_window=True)
|
||||
vllm_disabled_model.generate("Hi my name is")
|
||||
model_config = vllm_disabled_model.llm_engine.model_config
|
||||
assert model_config.max_model_len == sliding_len, (
|
||||
"Max len expected to equal sliding_len of %s, but got %s", sliding_len,
|
||||
model_config.max_model_len)
|
||||
|
||||
del vllm_disabled_model
|
||||
cleanup()
|
||||
|
||||
vllm_enabled_model = LLM(model, disable_sliding_window=False)
|
||||
vllm_enabled_model.generate("Hi my name is")
|
||||
model_config = vllm_enabled_model.llm_engine.model_config
|
||||
assert model_config.max_model_len == full_len, (
|
||||
"Max len expected to equal full_len of %s, but got %s", full_len,
|
||||
model_config.max_model_len)
|
||||
|
||||
del vllm_enabled_model
|
||||
cleanup()
|
||||
@@ -1,5 +1,29 @@
|
||||
import pytest
|
||||
|
||||
from vllm.config import ModelConfig
|
||||
|
||||
MODEL_IDS_EXPECTED = [
|
||||
("Qwen/Qwen1.5-7B", 32768),
|
||||
("mistralai/Mistral-7B-v0.1", 4096),
|
||||
("mistralai/Mistral-7B-Instruct-v0.2", 32768),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("model_id_expected", MODEL_IDS_EXPECTED)
|
||||
def test_disable_sliding_window(model_id_expected):
|
||||
model_id, expected = model_id_expected
|
||||
model_config = ModelConfig(
|
||||
model_id,
|
||||
model_id,
|
||||
tokenizer_mode="auto",
|
||||
trust_remote_code=False,
|
||||
seed=0,
|
||||
dtype="float16",
|
||||
revision=None,
|
||||
disable_sliding_window=True,
|
||||
)
|
||||
assert model_config.max_model_len == expected
|
||||
|
||||
|
||||
def test_get_sliding_window():
|
||||
TEST_SLIDING_WINDOW = 4096
|
||||
|
||||
Reference in New Issue
Block a user