A symbol scan over every tracked file found 123 top-level definitions in vllm/ with zero references, including references inside strings. All of them came from features this fork deleted earlier. - Delete dead attention helpers: MLADCPManager, split_prefill_chunks, the reshape helpers, compute_varlen_chunk_metadata, the LINEAR backend's unused BailingLinearAttentionBackend, and the sparse flash-attn entry points. - Delete the CPU and AMX op wrappers from _custom_ops.py: cpu_mla_decode, cpu_mla_extend, cpu_mla_get_scheduler_metadata, gather_mla_context_cache_cpu. - Delete dead quantization helpers: awq_pack, gptq_pack, gptq_quantize_weights, get_and_maybe_dequant_weights, marlin_quant_fp8_torch, the rand_marlin_weight_*_like pair, ocp_mx_weight_dtype_and_rows, get_fp8_block_weight_scale, input_to_float8. - Delete dead model helpers: resolve_visual_encoder_outputs, run_dp_sharded_vision_model, fast_topk, get_layer_index, is_pp_missing_parameter, skip_spec_layers, KimiK3MergedQKVGateLinear, selective_scan_fn, causal_conv1d_update_torch. - Delete dead utils: format_kib, format_mib, chunk_list, prev_power_of_2, split_host_port, join_host_port, make_zmq_path, make_async_with_semaphore, is_meta_module, is_non_overlapping_and_dense, supports_xpu_graph, create_kv_caches_with_random*, and the unused has_* capability probes. - Delete the unreachable deep-gemm mega-MoE warmup path, which imported vllm.models.deepseek_v4.nvidia.model and vllm.models.kimi_k3.nvidia.model, neither of which exists anymore. - Drop the imports and the two now-empty guards left behind. Verified statically: every changed file compiles, no unused import remains, and no deleted name is referenced in vllm, tests or csrc. The runtime gates still need the Python environment rebuilt. Co-authored-by: Hinata <hinata@idihore.id> Signed-off-by: MOVZX <movzx@yahoo.com>
100 lines
2.7 KiB
Python
100 lines
2.7 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
|
|
|
from collections.abc import Iterable, Sequence
|
|
|
|
from openai.types.responses import ResponseFunctionToolCall
|
|
|
|
from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionRequest
|
|
from vllm.entrypoints.openai.responses.protocol import (
|
|
ResponseInputOutputItem,
|
|
ResponsesRequest,
|
|
)
|
|
from vllm.renderers.chat_utils import ChatCompletionMessageParam
|
|
|
|
|
|
def count_tool_calls(tool_calls: object) -> int:
|
|
if tool_calls is None:
|
|
return 0
|
|
if isinstance(tool_calls, (str, bytes, dict)):
|
|
return 1
|
|
if isinstance(tool_calls, Iterable):
|
|
return sum(1 for _ in tool_calls)
|
|
return 1
|
|
|
|
|
|
def count_chat_history_tool_calls(
|
|
messages: Sequence[ChatCompletionMessageParam],
|
|
) -> int:
|
|
return sum(
|
|
count_tool_calls(msg.get("tool_calls"))
|
|
for msg in messages
|
|
if isinstance(msg, dict) and msg.get("role") == "assistant"
|
|
)
|
|
|
|
|
|
def count_response_history_tool_calls(
|
|
response_items: Sequence[ResponseInputOutputItem],
|
|
) -> int:
|
|
count = 0
|
|
for item in response_items:
|
|
if isinstance(item, ResponseFunctionToolCall):
|
|
count += 1
|
|
continue
|
|
|
|
if isinstance(item, dict):
|
|
item_type = item.get("type")
|
|
if item_type == "function_call":
|
|
count += 1
|
|
elif item.get("role") == "assistant":
|
|
count += count_tool_calls(item.get("tool_calls"))
|
|
|
|
return count
|
|
|
|
|
|
def count_history_tool_calls(
|
|
request: ChatCompletionRequest | ResponsesRequest,
|
|
) -> int:
|
|
if isinstance(request, ChatCompletionRequest):
|
|
return count_chat_history_tool_calls(request.messages)
|
|
|
|
request_input = request.input
|
|
if isinstance(request_input, str):
|
|
return 0
|
|
|
|
return count_response_history_tool_calls(request_input)
|
|
|
|
|
|
_JSON_WS = " \t\r\n"
|
|
|
|
|
|
def scan_json_object_end(raw: str, start: int) -> int | None:
|
|
"""Return the end index (exclusive) of the JSON object starting at
|
|
``raw[start]`` (which must be ``{``), or ``None`` when it is still
|
|
unterminated. String- and escape-aware so braces inside strings do not
|
|
mislead the depth count."""
|
|
depth = 0
|
|
in_string = False
|
|
escape = False
|
|
for i in range(start, len(raw)):
|
|
ch = raw[i]
|
|
if escape:
|
|
escape = False
|
|
continue
|
|
if in_string:
|
|
if ch == "\\":
|
|
escape = True
|
|
elif ch == '"':
|
|
in_string = False
|
|
continue
|
|
if ch == '"':
|
|
in_string = True
|
|
elif ch == "{":
|
|
depth += 1
|
|
elif ch == "}":
|
|
depth -= 1
|
|
if depth == 0:
|
|
return i + 1
|
|
return None
|
|
|