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
+3 -4
View File
@@ -4,7 +4,6 @@
import random
from copy import deepcopy
from dataclasses import dataclass
from typing import Optional
from unittest.mock import patch
import pytest
@@ -106,7 +105,7 @@ def skip_cuda_with_stage_false(request):
def get_random_id_to_index(
num_loras: int, num_slots: int, log: bool = True
) -> list[Optional[int]]:
) -> list[int | None]:
"""Creates a random lora_id_to_index mapping.
Args:
@@ -122,7 +121,7 @@ def get_random_id_to_index(
"num_loras must be less than or equal to num_slots."
)
slots: list[Optional[int]] = [None] * num_slots
slots: list[int | None] = [None] * num_slots
random_slot_selections = (torch.randperm(num_slots)[:num_loras]).tolist()
for lora_id, slot_idx in enumerate(random_slot_selections, start=1):
slots[slot_idx] = lora_id
@@ -134,7 +133,7 @@ def get_random_id_to_index(
def populate_loras(
id_to_index: list[Optional[int]],
id_to_index: list[int | None],
layer: BaseLayerWithLoRA,
layer_weights: torch.Tensor,
generate_embeddings_tensor: int = 0,
+2 -5
View File
@@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import subprocess
import sys
from typing import Union
import vllm
from vllm import LLM
@@ -27,7 +26,7 @@ def do_sample(
llm: vllm.LLM,
lora_path: str,
lora_id: int,
tensorizer_config_dict: Union[dict, None] = None,
tensorizer_config_dict: dict | None = None,
) -> list[str]:
prompts = [
"[user] Write a SQL query to answer the question based on the table schema.\n\n context: CREATE TABLE table_name_74 (icao VARCHAR, airport VARCHAR)\n\n question: Name the ICAO for lilongwe international airport [/user] [assistant]", # noqa: E501
@@ -73,9 +72,7 @@ def do_sample(
return generated_texts
def generate_and_test(
llm, sql_lora_files, tensorizer_config_dict: Union[dict, None] = None
):
def generate_and_test(llm, sql_lora_files, tensorizer_config_dict: dict | None = None):
print("lora adapter created")
print("lora 1")
assert (
+3 -4
View File
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from dataclasses import dataclass
from typing import Optional
import pytest
@@ -20,7 +19,7 @@ class TestConfig:
max_loras: int = 2
max_lora_rank: int = 16
max_model_len: int = 4096
mm_processor_kwargs: Optional[dict[str, int]] = None
mm_processor_kwargs: dict[str, int] | None = None
def __post_init__(self):
if self.mm_processor_kwargs is None:
@@ -61,7 +60,7 @@ class Qwen2VLTester:
self,
images: list[ImageAsset],
expected_outputs: list[str],
lora_id: Optional[int] = None,
lora_id: int | None = None,
temperature: float = 0,
max_tokens: int = 5,
):
@@ -92,7 +91,7 @@ class Qwen2VLTester:
self,
images: list[ImageAsset],
expected_outputs: list[list[str]],
lora_id: Optional[int] = None,
lora_id: int | None = None,
temperature: float = 0,
beam_width: int = 2,
max_tokens: int = 5,
+1 -2
View File
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from typing import Optional
import pytest
@@ -14,7 +13,7 @@ class DummyLoRAResolver(LoRAResolver):
async def resolve_lora(
self, base_model_name: str, lora_name: str
) -> Optional[LoRARequest]:
) -> LoRARequest | None:
if lora_name == "test_lora":
return LoRARequest(
lora_name=lora_name,
+2 -2
View File
@@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from collections import OrderedDict
from typing import NamedTuple, Optional
from typing import NamedTuple
from unittest.mock import patch
import pytest
@@ -21,7 +21,7 @@ class LoRANameParserTestConfig(NamedTuple):
name: str
module_name: str
is_lora_a: bool
weights_mapper: Optional[WeightsMapper] = None
weights_mapper: WeightsMapper | None = None
def test_parse_fine_tuned_lora_name_valid():
+2 -3
View File
@@ -4,7 +4,6 @@
import json
import os
from dataclasses import dataclass
from typing import Optional, Union
import torch
from safetensors.torch import save_file
@@ -81,7 +80,7 @@ class DummyLoRAManager:
module_name: str,
input_dim: int,
output_dims: list[int],
noop_lora_index: Optional[list[int]] = None,
noop_lora_index: list[int] | None = None,
rank: int = 8,
):
base_loras: list[LoRALayerWeights] = []
@@ -113,7 +112,7 @@ def assert_close(a, b):
@dataclass
class PunicaTensors:
inputs_tensor: torch.Tensor
lora_weights: Union[torch.Tensor, list[torch.Tensor]]
lora_weights: torch.Tensor | list[torch.Tensor]
our_out_tensor: torch.Tensor
ref_out_tensor: torch.Tensor
b_seq_start_loc: torch.Tensor