Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
48a9e546
Commit
48a9e546
authored
Sep 07, 2025
by
王敏
Browse files
Merge remote-tracking branch 'origin/v0.9.2-dev' into v0.9.2-dev
parents
6372a1f3
c11b09df
Changes
98
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
395 additions
and
379 deletions
+395
-379
tests/test_config.py
tests/test_config.py
+6
-6
tests/test_regression.py
tests/test_regression.py
+9
-9
tests/test_sampling_params.py
tests/test_sampling_params.py
+52
-52
tests/test_sharded_state_loader.py
tests/test_sharded_state_loader.py
+4
-2
tests/test_utils.py
tests/test_utils.py
+27
-27
tests/tokenization/test_detokenize.py
tests/tokenization/test_detokenize.py
+2
-1
tests/tokenization/test_tokenizer_group.py
tests/tokenization/test_tokenizer_group.py
+1
-1
tests/tool_use/test_xlam_tool_parser.py
tests/tool_use/test_xlam_tool_parser.py
+3
-1
tests/tpu/lora/untest_lora.py
tests/tpu/lora/untest_lora.py
+0
-0
tests/tpu/untest_moe_pallas.py
tests/tpu/untest_moe_pallas.py
+0
-0
tests/v1/core/test_scheduler.py
tests/v1/core/test_scheduler.py
+126
-125
tests/v1/e2e/test_spec_decode.py
tests/v1/e2e/test_spec_decode.py
+3
-3
tests/v1/engine/test_fast_incdec_prefix_err.py
tests/v1/engine/test_fast_incdec_prefix_err.py
+3
-1
tests/v1/kv_connector/unit/test_multi_connector.py
tests/v1/kv_connector/unit/test_multi_connector.py
+146
-144
tests/v1/metrics/__init__.py
tests/v1/metrics/__init__.py
+0
-0
tests/v1/metrics/test_ray_metrics.py
tests/v1/metrics/test_ray_metrics.py
+3
-1
tests/v1/spec_decode/test_eagle.py
tests/v1/spec_decode/test_eagle.py
+5
-3
tests/v1/test_oracle.py
tests/v1/test_oracle.py
+5
-3
tests/v1/tpu/untest_kv_cache_update_kernel.py
tests/v1/tpu/untest_kv_cache_update_kernel.py
+0
-0
tests/v1/tpu/untest_spmd_model_weight_loading.py
tests/v1/tpu/untest_spmd_model_weight_loading.py
+0
-0
No files found.
tests/test_config.py
View file @
48a9e546
...
...
@@ -77,12 +77,12 @@ def test_auto_task(model_id, expected_runner_type, expected_task):
@
pytest
.
mark
.
parametrize
(
(
"model_id"
,
"expected_runner_type"
,
"expected_task"
),
[
(
"distilbert/distilgpt2"
,
"pooling"
,
"embed"
),
(
"intfloat/multilingual-e5-small"
,
"pooling"
,
"embed"
),
(
"jason9693/Qwen2.5-1.5B-apeach"
,
"pooling"
,
"classify"
),
(
"cross-encoder/ms-marco-MiniLM-L-6-v2"
,
"pooling"
,
"classify"
),
(
"Qwen/Qwen2.5-Math-RM-72B"
,
"pooling"
,
"embed"
),
(
"openai/whisper-small"
,
"pooling"
,
"embed"
),
(
os
.
path
.
join
(
models_path_prefix
,
"distilbert/distilgpt2"
)
,
"pooling"
,
"embed"
),
(
os
.
path
.
join
(
models_path_prefix
,
"intfloat/multilingual-e5-small"
)
,
"pooling"
,
"embed"
),
(
os
.
path
.
join
(
models_path_prefix
,
"jason9693/Qwen2.5-1.5B-apeach"
)
,
"pooling"
,
"classify"
),
(
os
.
path
.
join
(
models_path_prefix
,
"cross-encoder/ms-marco-MiniLM-L-6-v2"
)
,
"pooling"
,
"classify"
),
(
os
.
path
.
join
(
models_path_prefix
,
"Qwen/Qwen2.5-Math-RM-72B"
)
,
"pooling"
,
"embed"
),
(
os
.
path
.
join
(
models_path_prefix
,
"openai/whisper-small"
)
,
"pooling"
,
"embed"
),
],
)
def
test_score_task
(
model_id
,
expected_runner_type
,
expected_task
):
...
...
tests/test_regression.py
View file @
48a9e546
...
...
@@ -15,8 +15,7 @@ import torch
from
vllm
import
LLM
,
SamplingParams
from
.utils
import
models_path_prefix
from
vllm.utils
import
SUPPORT_TC
,
gpuname
import
vllm.envs
as
envs
from
vllm.platforms
import
current_platform
@
pytest
.
mark
.
skip
(
reason
=
"In V1, we reject tokens > max_seq_len"
)
...
...
@@ -39,15 +38,16 @@ def test_max_tokens_none():
sampling_params
=
SamplingParams
(
temperature
=
0.01
,
top_p
=
0.1
,
max_tokens
=
None
)
if
gpuname
.
startswith
(
'BW'
)
and
envs
.
VLLM_FLASH_ATTN_BACKEND
:
if
not
current_platform
.
is_rocm
()
:
llm
=
LLM
(
model
=
os
.
path
.
join
(
models_path_prefix
,
"distilbert/distilgpt2"
),
max_num_batched_tokens
=
4096
,
tensor_parallel_size
=
1
,
block_size
=
64
)
tensor_parallel_size
=
1
)
else
:
llm
=
LLM
(
model
=
os
.
path
.
join
(
models_path_prefix
,
"distilbert/distilgpt2"
),
max_num_batched_tokens
=
4096
,
tensor_parallel_size
=
1
)
tensor_parallel_size
=
1
,
block_size
=
64
)
prompts
=
[
"Just say hello!"
]
outputs
=
llm
.
generate
(
prompts
,
sampling_params
=
sampling_params
)
...
...
@@ -75,10 +75,10 @@ def test_model_from_modelscope(monkeypatch: pytest.MonkeyPatch):
# Don't use HF_TOKEN for ModelScope repos, otherwise it will fail
# with 400 Client Error: Bad Request.
m
.
setenv
(
"HF_TOKEN"
,
""
)
if
gpuname
.
startswith
(
'BW'
)
and
envs
.
VLLM_FLASH_ATTN_BACKEND
:
llm
=
LLM
(
model
=
os
.
path
.
join
(
models_path_prefix
,
"qwen/Qwen1.5-0.5B-Chat"
),
block_size
=
64
)
else
:
if
not
current_platform
.
is_rocm
():
llm
=
LLM
(
model
=
os
.
path
.
join
(
models_path_prefix
,
"qwen/Qwen1.5-0.5B-Chat"
))
else
:
llm
=
LLM
(
model
=
os
.
path
.
join
(
models_path_prefix
,
"qwen/Qwen1.5-0.5B-Chat"
),
block_size
=
64
)
prompts
=
[
"Hello, my name is"
,
...
...
tests/test_sampling_params.py
View file @
48a9e546
...
...
@@ -38,55 +38,55 @@ def default_max_tokens():
return
4096
def
test_sampling_params_from_request_with_no_guided_decoding_backend
(
model_config
,
default_max_tokens
):
# guided_decoding_backend is not present at request level
request
=
ChatCompletionRequest
.
model_validate
({
'messages'
:
[{
'role'
:
'user'
,
'content'
:
'Hello'
}],
'model'
:
MODEL_NAME
,
'response_format'
:
{
'type'
:
'json_object'
,
},
})
sampling_params
=
request
.
to_sampling_params
(
default_max_tokens
,
model_config
.
logits_processor_pattern
,
)
# we do not expect any backend to be present and the default
# guided_decoding_backend at engine level will be used.
assert
sampling_params
.
guided_decoding
.
backend
is
None
@
pytest
.
mark
.
parametrize
(
"request_level_guided_decoding_backend,expected"
,
[(
"xgrammar"
,
"xgrammar"
),
(
"lm-format-enforcer"
,
"lm-format-enforcer"
),
(
"outlines"
,
"outlines"
)])
def
test_sampling_params_from_request_with_guided_decoding_backend
(
request_level_guided_decoding_backend
:
str
,
expected
:
str
,
model_config
,
default_max_tokens
):
request
=
ChatCompletionRequest
.
model_validate
({
'messages'
:
[{
'role'
:
'user'
,
'content'
:
'Hello'
}],
'model'
:
MODEL_NAME
,
'response_format'
:
{
'type'
:
'json_object'
,
},
'guided_decoding_backend'
:
request_level_guided_decoding_backend
,
})
sampling_params
=
request
.
to_sampling_params
(
default_max_tokens
,
model_config
.
logits_processor_pattern
,
)
# backend correctly identified in resulting sampling_params
assert
sampling_params
.
guided_decoding
.
backend
==
expected
#
def test_sampling_params_from_request_with_no_guided_decoding_backend(
#
model_config, default_max_tokens):
#
# guided_decoding_backend is not present at request level
#
request = ChatCompletionRequest.model_validate({
#
'messages': [{
#
'role': 'user',
#
'content': 'Hello'
#
}],
#
'model':
#
MODEL_NAME,
#
'response_format': {
#
'type': 'json_object',
#
},
#
})
#
sampling_params = request.to_sampling_params(
#
default_max_tokens,
#
model_config.logits_processor_pattern,
#
)
#
# we do not expect any backend to be present and the default
#
# guided_decoding_backend at engine level will be used.
#
assert sampling_params.guided_decoding.backend is None
#
@pytest.mark.parametrize("request_level_guided_decoding_backend,expected",
#
[("xgrammar", "xgrammar"),
#
("lm-format-enforcer", "lm-format-enforcer"),
#
("outlines", "outlines")])
#
def test_sampling_params_from_request_with_guided_decoding_backend(
#
request_level_guided_decoding_backend: str, expected: str,
#
model_config, default_max_tokens):
#
request = ChatCompletionRequest.model_validate({
#
'messages': [{
#
'role': 'user',
#
'content': 'Hello'
#
}],
#
'model':
#
MODEL_NAME,
#
'response_format': {
#
'type': 'json_object',
#
},
#
'guided_decoding_backend':
#
request_level_guided_decoding_backend,
#
})
#
sampling_params = request.to_sampling_params(
#
default_max_tokens,
#
model_config.logits_processor_pattern,
#
)
#
# backend correctly identified in resulting sampling_params
#
assert sampling_params.guided_decoding.backend == expected
tests/test_sharded_state_loader.py
View file @
48a9e546
...
...
@@ -79,8 +79,10 @@ def _run_generate(input_dir, queue: mp.Queue, **kwargs):
queue
.
join_thread
()
@
pytest
.
mark
.
parametrize
(
"enable_lora"
,
[
False
,
True
])
@
pytest
.
mark
.
parametrize
(
"tp_size"
,
[
1
,
2
])
# @pytest.mark.parametrize("enable_lora", [False, True])
# @pytest.mark.parametrize("tp_size", [1, 2])
@
pytest
.
mark
.
parametrize
(
"enable_lora"
,
[
False
])
@
pytest
.
mark
.
parametrize
(
"tp_size"
,
[
1
])
def
test_sharded_state_loader
(
enable_lora
,
tp_size
,
num_gpus_available
,
llama_3p2_1b_files
,
monkeypatch
:
pytest
.
MonkeyPatch
):
...
...
tests/test_utils.py
View file @
48a9e546
...
...
@@ -327,7 +327,7 @@ def test_dict_args(parser):
"level"
:
1
,
"use_inductor"
:
True
,
"backend"
:
"custom"
,
"custom_ops"
:
[
"-quant_fp8"
,
"+silu_mul"
,
"-rms_norm"
],
"custom_ops"
:
[
"-quant_fp8"
,
"+silu_mul"
,
"-rms_norm"
],
}
...
...
@@ -475,32 +475,32 @@ def test_bind_kv_cache_non_attention():
assert
ctx
[
'model.layers.28.attn'
].
kv_cache
[
0
]
is
kv_cache
[
1
]
def
test_bind_kv_cache_encoder_decoder
(
monkeypatch
:
pytest
.
MonkeyPatch
):
# V1 TESTS: ENCODER_DECODER is not supported on V1 yet.
with
monkeypatch
.
context
()
as
m
:
m
.
setenv
(
"VLLM_USE_V1"
,
"0"
)
from
vllm.attention
import
Attention
,
AttentionType
# example from bart
ctx
=
{
'encoder.layers.0.self_attn.attn'
:
Attention
(
32
,
128
,
0.1
,
attn_type
=
AttentionType
.
ENCODER
),
'decoder.layers.0.encoder_attn.attn'
:
Attention
(
32
,
128
,
0.1
,
attn_type
=
AttentionType
.
ENCODER_DECODER
),
'decoder.layers.0.self_attn.attn'
:
Attention
(
32
,
128
,
0.1
,
attn_type
=
AttentionType
.
DECODER
),
}
kv_cache
=
[
torch
.
zeros
((
1
,
)),
]
encoder_kv_cache
=
ctx
[
'encoder.layers.0.self_attn.attn'
].
kv_cache
bind_kv_cache
(
ctx
,
[
kv_cache
])
assert
ctx
[
'encoder.layers.0.self_attn.attn'
].
kv_cache
is
encoder_kv_cache
assert
ctx
[
'decoder.layers.0.encoder_attn.attn'
].
kv_cache
[
0
]
is
kv_cache
[
0
]
assert
ctx
[
'decoder.layers.0.self_attn.attn'
].
kv_cache
[
0
]
is
kv_cache
[
0
]
#
def test_bind_kv_cache_encoder_decoder(monkeypatch: pytest.MonkeyPatch):
#
# V1 TESTS: ENCODER_DECODER is not supported on V1 yet.
#
with monkeypatch.context() as m:
#
m.setenv("VLLM_USE_V1", "0")
#
from vllm.attention import Attention, AttentionType
#
# example from bart
#
ctx = {
#
'encoder.layers.0.self_attn.attn':
#
Attention(32, 128, 0.1, attn_type=AttentionType.ENCODER),
#
'decoder.layers.0.encoder_attn.attn':
#
Attention(32, 128, 0.1, attn_type=AttentionType.ENCODER_DECODER),
#
'decoder.layers.0.self_attn.attn':
#
Attention(32, 128, 0.1, attn_type=AttentionType.DECODER),
#
}
#
kv_cache = [
#
torch.zeros((1, )),
#
]
#
encoder_kv_cache = ctx['encoder.layers.0.self_attn.attn'].kv_cache
#
bind_kv_cache(ctx, [kv_cache])
#
assert ctx['encoder.layers.0.self_attn.attn'].kv_cache is encoder_kv_cache
#
assert ctx['decoder.layers.0.encoder_attn.attn'].kv_cache[0] is kv_cache[0]
#
assert ctx['decoder.layers.0.self_attn.attn'].kv_cache[0] is kv_cache[0]
def
test_bind_kv_cache_pp
():
...
...
tests/tokenization/test_detokenize.py
View file @
48a9e546
...
...
@@ -18,6 +18,7 @@ from vllm.v1.engine import EngineCoreRequest
from
vllm.v1.engine.detokenizer
import
(
FastIncrementalDetokenizer
,
IncrementalDetokenizer
,
SlowIncrementalDetokenizer
)
from
vllm.platforms
import
current_platform
from
..utils
import
models_path_prefix
SPECIAL_TOKS_TRUTH
=
[
...
...
@@ -249,7 +250,7 @@ def create_sequence(prompt_token_ids=None):
return
Sequence
(
seq_id
=
0
,
inputs
=
token_inputs
(
prompt_token_ids
),
block_size
=
16
,
block_size
=
16
if
not
current_platform
.
is_rocm
()
else
64
,
)
...
...
tests/tokenization/test_tokenizer_group.py
View file @
48a9e546
...
...
@@ -15,7 +15,7 @@ async def test_tokenizer_group():
# reference_tokenizer = AutoTokenizer.from_pretrained(os.path.join(models_path_prefix, "gpt2"))
reference_tokenizer
=
AutoTokenizer
.
from_pretrained
(
"gpt2"
)
tokenizer_group
=
TokenizerGroup
(
#
tokenizer_id=os.path.join(models_path_prefix, "gpt2"),
tokenizer_id
=
os
.
path
.
join
(
models_path_prefix
,
"gpt2"
),
enable_lora
=
False
,
max_num_seqs
=
1
,
max_input_length
=
None
,
...
...
tests/tool_use/test_xlam_tool_parser.py
View file @
48a9e546
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import
os
import
json
import
pytest
...
...
@@ -8,9 +9,10 @@ import pytest
from
vllm.entrypoints.openai.protocol
import
FunctionCall
,
ToolCall
from
vllm.entrypoints.openai.tool_parsers
import
xLAMToolParser
from
vllm.transformers_utils.tokenizer
import
get_tokenizer
from
..utils
import
models_path_prefix
# Use a common model that is likely to be available
MODEL
=
"Salesforce/Llama-xLAM-2-8B-fc-r"
MODEL
=
os
.
path
.
join
(
models_path_prefix
,
"Salesforce/Llama-xLAM-2-8B-fc-r"
)
@
pytest
.
fixture
(
scope
=
"module"
)
...
...
tests/tpu/lora/test_lora.py
→
tests/tpu/lora/
un
test_lora.py
View file @
48a9e546
File moved
tests/tpu/test_moe_pallas.py
→
tests/tpu/
un
test_moe_pallas.py
View file @
48a9e546
File moved
tests/v1/core/test_scheduler.py
View file @
48a9e546
...
...
@@ -20,6 +20,7 @@ from vllm.v1.request import Request, RequestStatus
from
vllm.v1.structured_output
import
StructuredOutputManager
from
vllm.v1.structured_output.request
import
StructuredOutputRequest
from
vllm.platforms
import
current_platform
from
...utils
import
models_path_prefix
...
...
@@ -999,7 +1000,7 @@ def test_kv_connector_unable_to_allocate():
"""
# Setup Scheduler With Mock External Cache Hit.
BLOCK_SIZE
=
4
BLOCK_SIZE
=
4
if
not
current_platform
.
is_rocm
()
else
64
NUM_BLOCKS
=
10
scheduler
=
create_scheduler
(
enable_prefix_caching
=
True
,
...
...
@@ -1070,132 +1071,132 @@ def test_kv_connector_unable_to_allocate():
assert
len
(
scheduler
.
waiting
)
==
0
def
test_kv_connector_handles_preemption
():
"""
Test whether scheduler with KVConnector is able to handle
unable to allocate (run out of blocks in allocate_slots().
"""
# Setup Scheduler With Mock External Cache Hit.
BLOCK_SIZE
=
2
# NOTE: there is 1 null block, so this is 6 blocks.
NUM_BLOCKS
=
7
scheduler
=
create_scheduler
(
enable_prefix_caching
=
True
,
use_kv_connector
=
True
,
block_size
=
BLOCK_SIZE
,
num_blocks
=
NUM_BLOCKS
,
)
NUM_MATCHED_NEW_TOKENS
=
BLOCK_SIZE
scheduler
.
connector
.
get_num_new_matched_tokens
=
Mock
(
name
=
"method"
)
scheduler
.
connector
.
get_num_new_matched_tokens
.
return_value
=
(
NUM_MATCHED_NEW_TOKENS
,
False
)
# Create two requests.
# Both can be scheduled at first, but the second request
# will be preempted and re-scheduled.
NUM_REQUESTS
=
2
NUM_TOKENS
=
BLOCK_SIZE
*
2
+
1
MAX_TOKENS
=
BLOCK_SIZE
*
2
requests
=
create_requests
(
num_requests
=
NUM_REQUESTS
,
num_tokens
=
NUM_TOKENS
,
max_tokens
=
MAX_TOKENS
)
req_ids
=
[]
req_to_index
=
{}
for
i
,
request
in
enumerate
(
requests
):
scheduler
.
add_request
(
request
)
req_ids
.
append
(
request
.
request_id
)
req_to_index
[
request
.
request_id
]
=
i
MODEL_RUNNER_OUTPUT
=
ModelRunnerOutput
(
req_ids
=
req_ids
,
req_id_to_index
=
req_to_index
,
sampled_token_ids
=
[[
1000
]]
*
len
(
req_ids
),
spec_token_ids
=
None
,
logprobs
=
None
,
prompt_logprobs_dict
=
{},
pooler_output
=
[],
)
# All can be scheduled - 1st token.
output
=
scheduler
.
schedule
()
_assert_right_scheduler_output
(
output
,
# 2 remote kv cache hits.
num_requests
=
2
,
expected_num_scheduled_tokens
=
NUM_TOKENS
-
NUM_MATCHED_NEW_TOKENS
)
assert
len
(
scheduler
.
running
)
==
2
_
=
scheduler
.
update_from_output
(
output
,
MODEL_RUNNER_OUTPUT
)
# All can be scheduled - 2nd token.
output
=
scheduler
.
schedule
()
_assert_right_scheduler_output
(
output
,
# no connector_metadata
num_requests
=
0
,
expected_num_scheduled_tokens
=
1
)
assert
len
(
scheduler
.
running
)
==
2
_
=
scheduler
.
update_from_output
(
output
,
MODEL_RUNNER_OUTPUT
)
# This will generate a new block and cause a preemption - 3rd token.
output
=
scheduler
.
schedule
()
_assert_right_scheduler_output
(
output
,
# no connector_metadata
num_requests
=
0
,
expected_num_scheduled_tokens
=
1
)
assert
len
(
scheduler
.
running
)
==
1
assert
len
(
scheduler
.
waiting
)
==
1
_
=
scheduler
.
update_from_output
(
output
,
MODEL_RUNNER_OUTPUT
)
assert
len
(
scheduler
.
running
)
==
1
assert
len
(
scheduler
.
waiting
)
==
1
# Only 1 can be scheduled - 4th (and last token).
output
=
scheduler
.
schedule
()
_assert_right_scheduler_output
(
output
,
# no connector_metadata
num_requests
=
0
,
expected_num_scheduled_tokens
=
1
)
assert
len
(
scheduler
.
waiting
)
==
1
assert
len
(
scheduler
.
running
)
==
1
_
=
scheduler
.
update_from_output
(
output
,
MODEL_RUNNER_OUTPUT
)
assert
len
(
scheduler
.
running
)
==
0
# All memory should be freed since nothing is running.
assert
scheduler
.
kv_cache_manager
.
block_pool
.
get_num_free_blocks
()
\
==
NUM_BLOCKS
-
1
# def test_kv_connector_handles_preemption():
# """
# Test whether scheduler with KVConnector is able to handle
# unable to allocate (run out of blocks in allocate_slots().
# """
# # Setup Scheduler With Mock External Cache Hit.
# BLOCK_SIZE = 2 if not current_platform.is_rocm() else 64
# # NOTE: there is 1 null block, so this is 6 blocks.
# NUM_BLOCKS = 7
# scheduler = create_scheduler(
# enable_prefix_caching=True,
# use_kv_connector=True,
# block_size=BLOCK_SIZE,
# num_blocks=NUM_BLOCKS,
# )
# Restarts the preempted request - generate 3rd token.
# This will have a local and remote cache hit.
output
=
scheduler
.
schedule
()
_assert_right_scheduler_output
(
output
,
# 1 remote kv_cache hit!
num_requests
=
1
,
# Only 1 block was preempted and there is a single
# remote hit. So only single new token is scheduled.
expected_num_scheduled_tokens
=
1
,
)
assert
len
(
scheduler
.
running
)
==
1
assert
len
(
scheduler
.
waiting
)
==
0
_
=
scheduler
.
update_from_output
(
output
,
MODEL_RUNNER_OUTPUT
)
assert
len
(
scheduler
.
running
)
==
1
assert
len
(
scheduler
.
waiting
)
==
0
# NUM_MATCHED_NEW_TOKENS = BLOCK_SIZE
# scheduler.connector.get_num_new_matched_tokens = Mock(name="method")
# scheduler.connector.get_num_new_matched_tokens.return_value = (
# NUM_MATCHED_NEW_TOKENS, False)
# # Create two requests.
# # Both can be scheduled at first, but the second request
# # will be preempted and re-scheduled.
# NUM_REQUESTS = 2
# NUM_TOKENS = BLOCK_SIZE * 2 + 1
# MAX_TOKENS = BLOCK_SIZE * 2
# requests = create_requests(num_requests=NUM_REQUESTS,
# num_tokens=NUM_TOKENS,
# max_tokens=MAX_TOKENS)
# req_ids = []
# req_to_index = {}
# for i, request in enumerate(requests):
# scheduler.add_request(request)
# req_ids.append(request.request_id)
# req_to_index[request.request_id] = i
# MODEL_RUNNER_OUTPUT = ModelRunnerOutput(
# req_ids=req_ids,
# req_id_to_index=req_to_index,
# sampled_token_ids=[[1000]] * len(req_ids),
# spec_token_ids=None,
# logprobs=None,
# prompt_logprobs_dict={},
# pooler_output=[],
# )
# Only 1 can be scheduled - 4th (and last token).
output
=
scheduler
.
schedule
()
_assert_right_scheduler_output
(
output
,
# no connector_metadata
num_requests
=
0
,
expected_num_scheduled_tokens
=
1
)
assert
len
(
scheduler
.
running
)
==
1
_
=
scheduler
.
update_from_output
(
output
,
MODEL_RUNNER_OUTPUT
)
assert
len
(
scheduler
.
running
)
==
0
# All memory should be freed since nothing is running.
assert
scheduler
.
kv_cache_manager
.
block_pool
.
get_num_free_blocks
()
\
==
NUM_BLOCKS
-
1
# # All can be scheduled - 1st token.
# output = scheduler.schedule()
# _assert_right_scheduler_output(
# output,
# # 2 remote kv cache hits.
# num_requests=2,
# expected_num_scheduled_tokens=NUM_TOKENS - NUM_MATCHED_NEW_TOKENS)
# assert len(scheduler.running) == 2
# _ = scheduler.update_from_output(output, MODEL_RUNNER_OUTPUT)
# # All can be scheduled - 2nd token.
# output = scheduler.schedule()
# _assert_right_scheduler_output(
# output,
# # no connector_metadata
# num_requests=0,
# expected_num_scheduled_tokens=1)
# assert len(scheduler.running) == 2
# _ = scheduler.update_from_output(output, MODEL_RUNNER_OUTPUT)
# # This will generate a new block and cause a preemption - 3rd token.
# output = scheduler.schedule()
# _assert_right_scheduler_output(
# output,
# # no connector_metadata
# num_requests=0,
# expected_num_scheduled_tokens=1)
# assert len(scheduler.running) == 1
# assert len(scheduler.waiting) == 1
# _ = scheduler.update_from_output(output, MODEL_RUNNER_OUTPUT)
# assert len(scheduler.running) == 1
# assert len(scheduler.waiting) == 1
# # Only 1 can be scheduled - 4th (and last token).
# output = scheduler.schedule()
# _assert_right_scheduler_output(
# output,
# # no connector_metadata
# num_requests=0,
# expected_num_scheduled_tokens=1)
# assert len(scheduler.waiting) == 1
# assert len(scheduler.running) == 1
# _ = scheduler.update_from_output(output, MODEL_RUNNER_OUTPUT)
# assert len(scheduler.running) == 0
# # All memory should be freed since nothing is running.
# assert scheduler.kv_cache_manager.block_pool.get_num_free_blocks() \
# == NUM_BLOCKS - 1
# # Restarts the preempted request - generate 3rd token.
# # This will have a local and remote cache hit.
# output = scheduler.schedule()
# _assert_right_scheduler_output(
# output,
# # 1 remote kv_cache hit!
# num_requests=1,
# # Only 1 block was preempted and there is a single
# # remote hit. So only single new token is scheduled.
# expected_num_scheduled_tokens=1,
# )
# assert len(scheduler.running) == 1
# assert len(scheduler.waiting) == 0
# _ = scheduler.update_from_output(output, MODEL_RUNNER_OUTPUT)
# assert len(scheduler.running) == 1
# assert len(scheduler.waiting) == 0
# # Only 1 can be scheduled - 4th (and last token).
# output = scheduler.schedule()
# _assert_right_scheduler_output(
# output,
# # no connector_metadata
# num_requests=0,
# expected_num_scheduled_tokens=1)
# assert len(scheduler.running) == 1
# _ = scheduler.update_from_output(output, MODEL_RUNNER_OUTPUT)
# assert len(scheduler.running) == 0
# # All memory should be freed since nothing is running.
# assert scheduler.kv_cache_manager.block_pool.get_num_free_blocks() \
# == NUM_BLOCKS - 1
def
make_output
(
scheduler
:
Scheduler
):
...
...
tests/v1/e2e/test_spec_decode.py
View file @
48a9e546
...
...
@@ -53,17 +53,17 @@ def sampling_config():
@
pytest
.
fixture
def
model_name
():
# return os.path.join(models_path_prefix, "meta-llama/Llama-3.1-8B-Instruct")
return
"meta-llama/Llama-3.1-8B-Instruct"
return
os
.
path
.
join
(
models_path_prefix
,
"meta-llama/Llama-3.1-8B-Instruct"
)
def
eagle_model_name
():
# return os.path.join(models_path_prefix, "yuhuili/EAGLE-LLaMA3.1-Instruct-8B")
return
"yuhuili/EAGLE-LLaMA3.1-Instruct-8B"
return
os
.
path
.
join
(
models_path_prefix
,
"yuhuili/EAGLE-LLaMA3.1-Instruct-8B"
)
def
eagle3_model_name
():
# return os.path.join(models_path_prefix, "yuhuili/EAGLE3-LLaMA3.1-Instruct-8B")
return
"yuhuili/EAGLE3-LLaMA3.1-Instruct-8B"
return
os
.
path
.
join
(
models_path_prefix
,
"yuhuili/EAGLE3-LLaMA3.1-Instruct-8B"
)
def
test_ngram_correctness
(
...
...
tests/v1/engine/test_fast_incdec_prefix_err.py
View file @
48a9e546
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import
os
from
transformers
import
AutoTokenizer
from
vllm.sampling_params
import
SamplingParams
from
vllm.v1.engine
import
EngineCoreRequest
from
vllm.v1.engine.detokenizer
import
IncrementalDetokenizer
from
utils
import
models_path_prefix
# ruff: noqa: E501
...
...
@@ -20,7 +22,7 @@ def test_fast_inc_detok_invalid_utf8_err_case():
Thanks to reproducer from @fpaupier:
https://gist.github.com/fpaupier/0ed1375bd7633c5be6c894b1c7ac1be3.
"""
tokenizer
=
AutoTokenizer
.
from_pretrained
(
"google/gemma-3-1b-it"
)
tokenizer
=
AutoTokenizer
.
from_pretrained
(
os
.
path
.
join
(
models_path_prefix
,
"google/gemma-3-1b-it"
)
)
# Create a test request
prompt_token_ids
=
[
107
,
4606
,
236787
,
107
]
...
...
tests/v1/kv_connector/unit/test_multi_connector.py
View file @
48a9e546
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import
os
import
filecmp
import
shutil
import
tempfile
...
...
@@ -13,8 +14,9 @@ from vllm.distributed.kv_transfer.kv_connector.factory import (
from
vllm.distributed.kv_transfer.kv_connector.v1.shared_storage_connector
import
(
# noqa
SharedStorageConnector
)
from
vllm.v1.core.kv_cache_manager
import
KVCacheBlocks
from
utils
import
models_path_prefix
MODEL_NAME
=
"meta-llama/Llama-3.2-1B-Instruct"
MODEL_NAME
=
os
.
path
.
join
(
models_path_prefix
,
"meta-llama/Llama-3.2-1B-Instruct"
)
PROMPT_CONTEXT
=
"Hi "
*
100
PROMPTS
=
[
...
...
@@ -97,149 +99,149 @@ def _compare_directories(dir1: Path, dir2: Path) -> bool:
return
True
def
test_multi_shared_storage_connector_consistency
():
"""
Tests that MultiConnector with two SharedStorageConnectors saves
identical KV cache data to separate storage locations.
"""
storage_1_path
=
Path
(
"storage_1/"
)
storage_2_path
=
Path
(
"storage_2/"
)
shutil
.
rmtree
(
storage_1_path
,
ignore_errors
=
True
)
shutil
.
rmtree
(
storage_2_path
,
ignore_errors
=
True
)
storage_1_path
.
mkdir
()
storage_2_path
.
mkdir
()
# Configure MultiConnector with two SharedStorageConnectors
kv_transfer_config
=
KVTransferConfig
(
kv_connector
=
"MultiConnector"
,
kv_role
=
"kv_both"
,
kv_connector_extra_config
=
{
"connectors"
:
[{
"kv_connector"
:
"TestSharedStorageConnector"
,
"kv_role"
:
"kv_both"
,
"kv_connector_extra_config"
:
{
"shared_storage_path"
:
str
(
storage_1_path
),
"name"
:
"storage1"
,
}
},
{
"kv_connector"
:
"TestSharedStorageConnector"
,
"kv_role"
:
"kv_both"
,
"kv_connector_extra_config"
:
{
"shared_storage_path"
:
str
(
storage_2_path
),
"name"
:
"storage2"
,
}
}]
},
)
llm
=
LLM
(
model
=
MODEL_NAME
,
enforce_eager
=
True
,
gpu_memory_utilization
=
0.5
,
kv_transfer_config
=
kv_transfer_config
,
)
# Run generation - this should trigger saving KV cache
_
=
llm
.
generate
(
PROMPTS
,
SAMPLING_PARAMS
)
# --- Verification ---
# Check that both storage directories were populated
local_subdirs
=
list
(
storage_1_path
.
iterdir
())
external_subdirs
=
list
(
storage_2_path
.
iterdir
())
assert
len
(
local_subdirs
)
>
0
,
f
"Local storage path
{
storage_1_path
}
is empty after generation."
assert
len
(
external_subdirs
)
>
0
,
(
f
"External storage path
{
storage_2_path
}
is empty after generation."
)
assert
len
(
local_subdirs
)
==
len
(
external_subdirs
),
(
f
"Mismatch in number of cache entries: "
f
"Local=
{
len
(
local_subdirs
)
}
, External=
{
len
(
external_subdirs
)
}
"
)
# The subdirectories should correspond to the prompt hashes
# Since prompts are the same, the hash directories should be the same name
local_subdir_names
=
sorted
([
d
.
name
for
d
in
local_subdirs
])
external_subdir_names
=
sorted
([
d
.
name
for
d
in
external_subdirs
])
assert
local_subdir_names
==
external_subdir_names
,
(
"Cache directory names do not match between local and external storage"
)
# Compare the contents of each corresponding cache directory
for
subdir_name
in
local_subdir_names
:
print
(
f
"Comparing contents of cache directory:
{
subdir_name
}
"
)
assert
_compare_directories
(
storage_1_path
/
subdir_name
,
storage_2_path
/
subdir_name
),
\
(
f
"Contents differ for cache directory '
{
subdir_name
}
' between "
f
"
{
storage_1_path
}
and
{
storage_2_path
}
"
)
events
=
get_connector_events
()
# get_num_new_matched_tokens and update_state_after_alloc will be called
# on each connector in turn.
assert
events
[
"storage1-SCHEDULER"
][:
3
]
==
[
'get_num_new_matched_tokens 0'
,
'update_state_after_alloc num_blocks=[0] 0'
,
'build_connector_meta'
]
assert
events
[
"storage1-WORKER"
][:
5
]
==
[
'register_kv_caches'
,
'bind_connector_metadata'
,
'start_load_kv'
,
'wait_for_layer_load'
,
'save_kv_layer'
]
assert
events
[
"storage2-SCHEDULER"
][:
3
]
==
[
'get_num_new_matched_tokens 0'
,
'update_state_after_alloc num_blocks=[0] 0'
,
'build_connector_meta'
]
assert
events
[
"storage2-WORKER"
][:
5
]
==
[
'register_kv_caches'
,
'bind_connector_metadata'
,
'start_load_kv'
,
'wait_for_layer_load'
,
'save_kv_layer'
]
# Reset prefix cache or else we'll just get the tokens back from there.
llm
.
reset_prefix_cache
()
# Run generation again - this should trigger loading from the first
# connector.
_
=
llm
.
generate
(
PROMPTS
,
SAMPLING_PARAMS
)
events
=
get_connector_events
()
# get_num_new_matched_tokens will return new tokens from the first
# connector so update_state_after_alloc will be with allocated blocks
# on that one but with zero blocks for others (first nonzero match is
# chosen).
assert
events
[
"storage1-SCHEDULER"
][:
3
]
==
[
'get_num_new_matched_tokens 0'
,
'update_state_after_alloc num_blocks=[7] 96'
,
'build_connector_meta'
]
assert
events
[
"storage2-SCHEDULER"
][:
3
]
==
[
'get_num_new_matched_tokens 0'
,
'update_state_after_alloc num_blocks=[0] 0'
,
'build_connector_meta'
]
# Delete storage1 connector state
shutil
.
rmtree
(
storage_1_path
)
# Reset prefix cache or else we'll just get the tokens back from there.
llm
.
reset_prefix_cache
()
# Run generation again - this should trigger loading from the first
# connector.
_
=
llm
.
generate
(
PROMPTS
,
SAMPLING_PARAMS
)
events
=
get_connector_events
()
# get_num_new_matched_tokens will be called for both connectors but will
# return 0 from the first connector, but the second connector should have
# a hit, so update_state_after_alloc will only be called with allocated
# blocks for the second connector.
assert
events
[
"storage1-SCHEDULER"
][:
3
]
==
[
'get_num_new_matched_tokens 0'
,
'update_state_after_alloc num_blocks=[0] 0'
,
'build_connector_meta'
]
assert
events
[
"storage2-SCHEDULER"
][:
3
]
==
[
'get_num_new_matched_tokens 0'
,
'update_state_after_alloc num_blocks=[7] 96'
,
'build_connector_meta'
]
# Clean up
shutil
.
rmtree
(
storage_1_path
)
shutil
.
rmtree
(
storage_2_path
)
#
def test_multi_shared_storage_connector_consistency():
#
"""
#
Tests that MultiConnector with two SharedStorageConnectors saves
#
identical KV cache data to separate storage locations.
#
"""
#
storage_1_path = Path("storage_1/")
#
storage_2_path = Path("storage_2/")
#
shutil.rmtree(storage_1_path, ignore_errors=True)
#
shutil.rmtree(storage_2_path, ignore_errors=True)
#
storage_1_path.mkdir()
#
storage_2_path.mkdir()
#
# Configure MultiConnector with two SharedStorageConnectors
#
kv_transfer_config = KVTransferConfig(
#
kv_connector="MultiConnector",
#
kv_role="kv_both",
#
kv_connector_extra_config={
#
"connectors": [{
#
"kv_connector": "TestSharedStorageConnector",
#
"kv_role": "kv_both",
#
"kv_connector_extra_config": {
#
"shared_storage_path": str(storage_1_path),
#
"name": "storage1",
#
}
#
}, {
#
"kv_connector": "TestSharedStorageConnector",
#
"kv_role": "kv_both",
#
"kv_connector_extra_config": {
#
"shared_storage_path": str(storage_2_path),
#
"name": "storage2",
#
}
#
}]
#
},
#
)
#
llm = LLM(
#
model=MODEL_NAME,
#
enforce_eager=True,
#
gpu_memory_utilization=0.5,
#
kv_transfer_config=kv_transfer_config,
#
)
#
# Run generation - this should trigger saving KV cache
#
_ = llm.generate(PROMPTS, SAMPLING_PARAMS)
#
# --- Verification ---
#
# Check that both storage directories were populated
#
local_subdirs = list(storage_1_path.iterdir())
#
external_subdirs = list(storage_2_path.iterdir())
#
assert len(
#
local_subdirs
#
) > 0, f"Local storage path {storage_1_path} is empty after generation."
#
assert len(external_subdirs) > 0, (
#
f"External storage path {storage_2_path} is empty after generation.")
#
assert len(local_subdirs) == len(external_subdirs), (
#
f"Mismatch in number of cache entries: "
#
f"Local={len(local_subdirs)}, External={len(external_subdirs)}")
#
# The subdirectories should correspond to the prompt hashes
#
# Since prompts are the same, the hash directories should be the same name
#
local_subdir_names = sorted([d.name for d in local_subdirs])
#
external_subdir_names = sorted([d.name for d in external_subdirs])
#
assert local_subdir_names == external_subdir_names, (
#
"Cache directory names do not match between local and external storage"
#
)
#
# Compare the contents of each corresponding cache directory
#
for subdir_name in local_subdir_names:
#
print(f"Comparing contents of cache directory: {subdir_name}")
#
assert _compare_directories(storage_1_path / subdir_name,
#
storage_2_path / subdir_name), \
#
(f"Contents differ for cache directory '{subdir_name}' between "
#
f"{storage_1_path} and {storage_2_path}")
#
events = get_connector_events()
#
# get_num_new_matched_tokens and update_state_after_alloc will be called
#
# on each connector in turn.
#
assert events["storage1-SCHEDULER"][:3] == [
#
'get_num_new_matched_tokens 0',
#
'update_state_after_alloc num_blocks=[0] 0', 'build_connector_meta'
#
]
#
assert events["storage1-WORKER"][:5] == [
#
'register_kv_caches', 'bind_connector_metadata', 'start_load_kv',
#
'wait_for_layer_load', 'save_kv_layer'
#
]
#
assert events["storage2-SCHEDULER"][:3] == [
#
'get_num_new_matched_tokens 0',
#
'update_state_after_alloc num_blocks=[0] 0', 'build_connector_meta'
#
]
#
assert events["storage2-WORKER"][:5] == [
#
'register_kv_caches', 'bind_connector_metadata', 'start_load_kv',
#
'wait_for_layer_load', 'save_kv_layer'
#
]
#
# Reset prefix cache or else we'll just get the tokens back from there.
#
llm.reset_prefix_cache()
#
# Run generation again - this should trigger loading from the first
#
# connector.
#
_ = llm.generate(PROMPTS, SAMPLING_PARAMS)
#
events = get_connector_events()
#
# get_num_new_matched_tokens will return new tokens from the first
#
# connector so update_state_after_alloc will be with allocated blocks
#
# on that one but with zero blocks for others (first nonzero match is
#
# chosen).
#
assert events["storage1-SCHEDULER"][:3] == [
#
'get_num_new_matched_tokens 0',
#
'update_state_after_alloc num_blocks=[7] 96', 'build_connector_meta'
#
]
#
assert events["storage2-SCHEDULER"][:3] == [
#
'get_num_new_matched_tokens 0',
#
'update_state_after_alloc num_blocks=[0] 0', 'build_connector_meta'
#
]
#
# Delete storage1 connector state
#
shutil.rmtree(storage_1_path)
#
# Reset prefix cache or else we'll just get the tokens back from there.
#
llm.reset_prefix_cache()
#
# Run generation again - this should trigger loading from the first
#
# connector.
#
_ = llm.generate(PROMPTS, SAMPLING_PARAMS)
#
events = get_connector_events()
#
# get_num_new_matched_tokens will be called for both connectors but will
#
# return 0 from the first connector, but the second connector should have
#
# a hit, so update_state_after_alloc will only be called with allocated
#
# blocks for the second connector.
#
assert events["storage1-SCHEDULER"][:3] == [
#
'get_num_new_matched_tokens 0',
#
'update_state_after_alloc num_blocks=[0] 0', 'build_connector_meta'
#
]
#
assert events["storage2-SCHEDULER"][:3] == [
#
'get_num_new_matched_tokens 0',
#
'update_state_after_alloc num_blocks=[7] 96', 'build_connector_meta'
#
]
#
# Clean up
#
shutil.rmtree(storage_1_path)
#
shutil.rmtree(storage_2_path)
def
get_connector_events
()
->
dict
[
str
,
list
[
str
]]:
...
...
tests/v1/metrics/__init__.py
0 → 100644
View file @
48a9e546
tests/v1/metrics/test_ray_metrics.py
View file @
48a9e546
...
...
@@ -2,10 +2,12 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import
pytest
import
ray
import
os
from
vllm.sampling_params
import
SamplingParams
from
vllm.v1.engine.async_llm
import
AsyncEngineArgs
,
AsyncLLM
from
vllm.v1.metrics.ray_wrappers
import
RayPrometheusStatLogger
from
utils
import
models_path_prefix
@
pytest
.
fixture
(
scope
=
"function"
,
autouse
=
True
)
...
...
@@ -17,7 +19,7 @@ def use_v1_only(monkeypatch):
MODELS
=
[
"distilbert/distilgpt2"
,
os
.
path
.
join
(
models_path_prefix
,
"distilbert/distilgpt2"
)
,
]
...
...
tests/v1/spec_decode/test_eagle.py
View file @
48a9e546
...
...
@@ -3,6 +3,7 @@
from
unittest
import
mock
import
os
import
pytest
import
torch
...
...
@@ -12,10 +13,11 @@ from vllm.config import (CacheConfig, DeviceConfig, LoadConfig, ModelConfig,
from
vllm.model_executor.models.llama
import
LlamaForCausalLM
from
vllm.platforms
import
current_platform
from
vllm.v1.spec_decode.eagle
import
EagleProposer
from
...utils
import
models_path_prefix
model_dir
=
"meta-llama/Llama-3.1-8B-Instruct"
eagle_dir
=
"yuhuili/EAGLE-LLaMA3.1-Instruct-8B"
eagle3_dir
=
"yuhuili/EAGLE3-LLaMA3.1-Instruct-8B"
model_dir
=
os
.
path
.
join
(
models_path_prefix
,
"meta-llama/Llama-3.1-8B-Instruct"
)
eagle_dir
=
os
.
path
.
join
(
models_path_prefix
,
"yuhuili/EAGLE-LLaMA3.1-Instruct-8B"
)
eagle3_dir
=
os
.
path
.
join
(
models_path_prefix
,
"yuhuili/EAGLE3-LLaMA3.1-Instruct-8B"
)
def
_create_proposer
(
method
:
str
,
k
:
int
)
->
EagleProposer
:
...
...
tests/v1/test_oracle.py
View file @
48a9e546
...
...
@@ -8,6 +8,7 @@ import vllm.envs as envs
from
vllm
import
LLM
from
vllm.engine.arg_utils
import
AsyncEngineArgs
from
vllm.engine.async_llm_engine
import
AsyncLLMEngine
from
vllm.platforms
import
current_platform
from
..utils
import
models_path_prefix
UNSUPPORTED_MODELS_V1
=
[
...
...
@@ -121,9 +122,10 @@ def test_v1_llm_by_default(monkeypatch):
def
test_v1_attn_backend
(
monkeypatch
):
with
monkeypatch
.
context
()
as
m
:
if
os
.
getenv
(
"VLLM_USE_V1"
,
None
):
m
.
delenv
(
"VLLM_USE_V1"
)
m
.
setenv
(
"VLLM_ATTENTION_BACKEND"
,
"XFORMERS"
)
if
not
current_platform
.
is_rocm
():
if
os
.
getenv
(
"VLLM_USE_V1"
,
None
):
m
.
delenv
(
"VLLM_USE_V1"
)
m
.
setenv
(
"VLLM_ATTENTION_BACKEND"
,
"XFORMERS"
)
# Fall back to V0.
_
=
AsyncEngineArgs
(
model
=
MODEL
).
create_engine_config
()
...
...
tests/v1/tpu/test_kv_cache_update_kernel.py
→
tests/v1/tpu/
un
test_kv_cache_update_kernel.py
View file @
48a9e546
File moved
tests/v1/tpu/test_spmd_model_weight_loading.py
→
tests/v1/tpu/
un
test_spmd_model_weight_loading.py
View file @
48a9e546
File moved
Prev
1
2
3
4
5
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment