[Refactor] Remove dead tests utils (#58803)
Signed-off-by: yewentao256 <zhyanwentao@126.com>
This commit is contained in:
-161
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import asyncio
|
||||
import atexit
|
||||
import contextlib
|
||||
import copy
|
||||
@@ -23,7 +22,6 @@ from contextlib import ExitStack, contextmanager
|
||||
from multiprocessing import Process, get_context
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, Literal, cast
|
||||
from unittest.mock import patch
|
||||
|
||||
import anthropic
|
||||
import cloudpickle
|
||||
@@ -33,12 +31,9 @@ import pytest
|
||||
import requests
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
from huggingface_hub.constants import HF_HUB_OFFLINE
|
||||
from openai.types.completion import Completion
|
||||
from typing_extensions import ParamSpec
|
||||
|
||||
import vllm.envs as envs
|
||||
from tests.models.utils import TextTextLogprobs
|
||||
from vllm.distributed import (
|
||||
ensure_model_parallel_initialized,
|
||||
init_distributed_environment,
|
||||
@@ -52,7 +47,6 @@ from vllm.model_executor.layers.quantization.utils.quant_utils import (
|
||||
from vllm.model_executor.model_loader import get_model_loader
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.tokenizers import get_tokenizer
|
||||
from vllm.transformers_utils.repo_utils import hf_api
|
||||
from vllm.utils.argparse_utils import FlexibleArgumentParser
|
||||
from vllm.utils.mem_constants import GB_bytes
|
||||
from vllm.utils.network_utils import get_open_port
|
||||
@@ -69,24 +63,6 @@ logger = init_logger(__name__)
|
||||
FP8_DTYPE = current_platform.fp8_dtype()
|
||||
|
||||
|
||||
def prewarm_hf_cache(assets: list[tuple[str, str]]) -> None:
|
||||
"""Pre-populate the HF cache for (repo_id, filename) pairs that upstream
|
||||
trust_remote_code modules would otherwise fetch from third-party CDNs
|
||||
(often unreachable from US-based CI)."""
|
||||
if HF_HUB_OFFLINE:
|
||||
return
|
||||
for repo_id, filename in assets:
|
||||
try:
|
||||
hf_api().hf_hub_download(repo_id=repo_id, filename=filename)
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
"Failed to prefetch %s/%s: %r. Tests depending on this asset may fail.",
|
||||
repo_id,
|
||||
filename,
|
||||
e,
|
||||
)
|
||||
|
||||
|
||||
if current_platform.is_cuda():
|
||||
from vllm.third_party.pynvml import (
|
||||
nvmlDeviceGetHandleByIndex,
|
||||
@@ -1556,17 +1532,6 @@ def assert_rocm_custom_allreduce_backend_state_on_worker(
|
||||
)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def error_on_warning(category: type[Warning] = Warning):
|
||||
"""Within the scope of this context manager, tests will fail if any warning
|
||||
of the given category is emitted.
|
||||
"""
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings("error", category=category)
|
||||
|
||||
yield
|
||||
|
||||
|
||||
def get_physical_device_indices(devices: list[int]):
|
||||
visible_devices = os.environ.get("CUDA_VISIBLE_DEVICES")
|
||||
if visible_devices is None:
|
||||
@@ -2157,88 +2122,6 @@ def multi_gpu_only(*, num_gpus: int = 2):
|
||||
return wrapper
|
||||
|
||||
|
||||
async def completions_with_server_args(
|
||||
prompts: list[str],
|
||||
model_name: str,
|
||||
server_cli_args: list[str],
|
||||
num_logprobs: int | None,
|
||||
max_wait_seconds: int = 240,
|
||||
max_tokens: int | list = 5,
|
||||
) -> list[Completion]:
|
||||
"""Construct a remote OpenAI server, obtain an async client to the
|
||||
server & invoke the completions API to obtain completions.
|
||||
|
||||
Args:
|
||||
prompts: test prompts
|
||||
model_name: model to spin up on the vLLM server
|
||||
server_cli_args: CLI args for starting the server
|
||||
num_logprobs: Number of logprobs to report (or `None`)
|
||||
max_wait_seconds: timeout interval for bringing up server.
|
||||
Default: 240sec
|
||||
max_tokens: max_tokens value for each of the given input prompts.
|
||||
if only one max_token value is given, the same value is used
|
||||
for all the prompts.
|
||||
|
||||
Returns:
|
||||
OpenAI Completion instance
|
||||
|
||||
"""
|
||||
if isinstance(max_tokens, int):
|
||||
max_tokens = [max_tokens] * len(prompts)
|
||||
|
||||
assert len(max_tokens) == len(prompts)
|
||||
|
||||
outputs = None
|
||||
with RemoteOpenAIServer(
|
||||
model_name, server_cli_args, max_wait_seconds=max_wait_seconds
|
||||
) as server:
|
||||
client = server.get_async_client()
|
||||
outputs = [
|
||||
client.completions.create(
|
||||
model=model_name,
|
||||
prompt=[p],
|
||||
temperature=0,
|
||||
stream=False,
|
||||
max_tokens=max_tok,
|
||||
logprobs=num_logprobs,
|
||||
)
|
||||
for p, max_tok in zip(prompts, max_tokens)
|
||||
]
|
||||
outputs = await asyncio.gather(*outputs)
|
||||
|
||||
assert outputs is not None, "Completion API call failed."
|
||||
|
||||
return outputs
|
||||
|
||||
|
||||
def get_client_text_generations(completions: list[Completion]) -> list[str]:
|
||||
"""Extract generated tokens from the output of a
|
||||
request made to an Open-AI-protocol completions endpoint.
|
||||
"""
|
||||
assert all([len(x.choices) == 1 for x in completions])
|
||||
return [x.choices[0].text for x in completions]
|
||||
|
||||
|
||||
def get_client_text_logprob_generations(
|
||||
completions: list[Completion],
|
||||
) -> list[TextTextLogprobs]:
|
||||
"""Operates on the output of a request made to an Open-AI-protocol
|
||||
completions endpoint; obtains top-rank logprobs for each token in
|
||||
each {class}`SequenceGroup`
|
||||
"""
|
||||
text_generations = get_client_text_generations(completions)
|
||||
text = "".join(text_generations)
|
||||
return [
|
||||
(
|
||||
text_generations,
|
||||
text,
|
||||
(None if x.logprobs is None else x.logprobs.top_logprobs),
|
||||
)
|
||||
for completion in completions
|
||||
for x in completion.choices
|
||||
]
|
||||
|
||||
|
||||
def has_module_attribute(module_name, attribute_name):
|
||||
"""Helper function to check if a module has a specific attribute."""
|
||||
try:
|
||||
@@ -2267,50 +2150,6 @@ def get_attn_backend_list_based_on_platform() -> list[str]:
|
||||
raise ValueError("Unsupported platform")
|
||||
|
||||
|
||||
@contextmanager
|
||||
def override_cutlass_fp8_supported(value: bool):
|
||||
with patch(
|
||||
"vllm.model_executor.layers.quantization.utils.w8a8_utils.cutlass_fp8_supported",
|
||||
return_value=value,
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
def disable_aiter_plain_rmsnorm(monkeypatch) -> None:
|
||||
"""Patch dispatch_rocm_rmsnorm_func so the plain (non-fused) rms_norm path
|
||||
always uses the native float32 kernel for the duration of a test.
|
||||
|
||||
The fused path (rms_norm2d_with_add, selected when with_fused_add=True) is
|
||||
left on AITER -- only the plain path is redirected to native.
|
||||
|
||||
AITER's plain rms_norm accumulates variance in bfloat16 (~1 ULP/call),
|
||||
which drifts the KV cache over many decode steps. This drift is irrelevant
|
||||
for a trained model (rank-1/rank-2 gap ~1-3 nats >> 1 ULP), but breaks
|
||||
logprob comparison tests with randomly-initialised models like
|
||||
TitanML/tiny-mixtral whose rank-1/rank-2 gap is only O(1/sqrt(V)) ~0.006
|
||||
nats -- smaller than the accumulated per-step error.
|
||||
"""
|
||||
import torch
|
||||
|
||||
import vllm.model_executor.layers.layernorm as _ln_mod
|
||||
from vllm.model_executor.layers.layernorm import rms_norm as _native
|
||||
|
||||
_orig = _ln_mod.dispatch_rocm_rmsnorm_func
|
||||
|
||||
def _native_plain(
|
||||
with_fused_add: bool, dtype: torch.dtype, use_aiter: bool = False
|
||||
):
|
||||
if (
|
||||
use_aiter
|
||||
and not with_fused_add
|
||||
and dtype in (torch.float16, torch.bfloat16)
|
||||
):
|
||||
return _native
|
||||
return _orig(with_fused_add, dtype, use_aiter)
|
||||
|
||||
monkeypatch.setattr(_ln_mod, "dispatch_rocm_rmsnorm_func", _native_plain)
|
||||
|
||||
|
||||
def prep_prompts(batch_size: int, ln_range: tuple[int, int] = (800, 1100)):
|
||||
"""Generate prompts which a bunch of assignments,
|
||||
then asking for the value of one of them.
|
||||
|
||||
Reference in New Issue
Block a user