Update Optional[x] -> x | None and Union[x, y] to x | y (#26633)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
Harry Mellor
2025-10-12 09:51:31 -07:00
committed by GitHub
parent 9bb38130cb
commit 8fcaaf6a16
944 changed files with 9490 additions and 10121 deletions
@@ -1,6 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from typing import Optional
import pytest
import torch
@@ -138,7 +137,7 @@ def test_models(
example_prompts, max_tokens, num_logprobs
)
prompt_embeds: Optional[list[torch.Tensor]] = [] if use_prompt_embeds else None
prompt_embeds: list[torch.Tensor] | None = [] if use_prompt_embeds else None
prompt_token_ids = []
for prompt in example_prompts:
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from typing import Callable
from collections.abc import Callable
import pytest
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
# Adapted from https://huggingface.co/docs/transformers/perplexity
from typing import Optional, cast
from typing import cast
import pytest
import torch
@@ -85,7 +85,7 @@ def wikitext_ppl_test(
n_tokens = 0
for output in outputs:
output = cast(TokensTextLogprobsPromptLogprobs, output)
token_datas = cast(list[Optional[dict[int, Logprob]]], output[3])
token_datas = cast(list[dict[int, Logprob] | None], output[3])
assert token_datas[0] is None
token_log_probs = []
+1 -2
View File
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from collections.abc import Sequence
from typing import Optional
import pytest
@@ -13,7 +12,7 @@ def run_embedding_correctness_test(
hf_model: "HfRunner",
inputs: list[str],
vllm_outputs: Sequence[list[float]],
dimensions: Optional[int] = None,
dimensions: int | None = None,
):
hf_outputs = hf_model.encode(inputs)
if dimensions:
@@ -1,6 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from typing import Optional
import pytest
@@ -66,7 +65,7 @@ def test_models(
pooling_type="MEAN", normalize=False
)
max_model_len: Optional[int] = 512
max_model_len: int | None = 512
if model in [
"sentence-transformers/all-MiniLM-L12-v2",
"sentence-transformers/stsb-roberta-base-v2",
@@ -1,7 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from __future__ import annotations
import numpy as np
import openai
import pytest
@@ -3,7 +3,6 @@
import tempfile
from collections.abc import Sequence
from typing import Optional
import mteb
import numpy as np
@@ -51,7 +50,7 @@ class VllmMtebEncoder(mteb.Encoder):
def predict(
self,
sentences: list[tuple[str, str, Optional[str]]], # query, corpus, prompt
sentences: list[tuple[str, str, str | None]], # query, corpus, prompt
*args,
**kwargs,
) -> np.ndarray:
@@ -100,7 +99,7 @@ class ScoreClientMtebEncoder(mteb.Encoder):
def predict(
self,
sentences: list[tuple[str, str, Optional[str]]], # query, corpus, prompt
sentences: list[tuple[str, str, str | None]], # query, corpus, prompt
*args,
**kwargs,
) -> np.ndarray:
@@ -294,7 +293,7 @@ def mteb_test_rerank_models_hf(
original_predict = hf_model.predict
def _predict(
sentences: list[tuple[str, str, Optional[str]]], # query, corpus, prompt
sentences: list[tuple[str, str, str | None]], # query, corpus, prompt
*args,
**kwargs,
):
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from typing import Any, Optional
from typing import Any
import numpy as np
import pytest
@@ -111,7 +111,7 @@ class GemmaMtebEncoder(VllmMtebEncoder):
def predict(
self,
sentences: list[tuple[str, str, Optional[str]]], # query, corpus, prompt
sentences: list[tuple[str, str, str | None]], # query, corpus, prompt
*args,
**kwargs,
) -> np.ndarray: