Update deprecated Python 3.8 typing (#13971)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import itertools
|
||||
from typing import List, Tuple
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
@@ -46,8 +45,8 @@ def hf_model(hf_runner):
|
||||
|
||||
def _repeat_logprob_config(
|
||||
test_prompts,
|
||||
logprob_prompt_logprob_list: List[Tuple],
|
||||
) -> List[Tuple]:
|
||||
logprob_prompt_logprob_list: list[tuple],
|
||||
) -> list[tuple]:
|
||||
"""Ensure each test prompt has a logprob config.
|
||||
|
||||
A logprob config specifies the optional (i.e.
|
||||
@@ -74,7 +73,7 @@ def _repeat_logprob_config(
|
||||
tuples
|
||||
|
||||
Returns:
|
||||
List of
|
||||
list of
|
||||
(optional num sample logprob,optional num prompt logprob)
|
||||
tuples which is either identical to
|
||||
`logprob_prompt_logprob_list`, or else repeats
|
||||
@@ -177,7 +176,7 @@ def _test_case_get_logprobs_and_prompt_logprobs(
|
||||
for r in range(1, num_top_logprobs + 1))
|
||||
|
||||
output_text = vllm_result.outputs[0].text
|
||||
output_string_from_most_likely_tokens_lst: List[str] = []
|
||||
output_string_from_most_likely_tokens_lst: list[str] = []
|
||||
for top_logprobs in vllm_result.outputs[0].logprobs:
|
||||
top_logprob = next(iter(top_logprobs.values()))
|
||||
output_string_from_most_likely_tokens_lst.append(
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
from typing import List
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
@@ -13,7 +12,7 @@ def sampler():
|
||||
return RejectionSampler()
|
||||
|
||||
|
||||
def create_logits_tensor(token_ids: List[int],
|
||||
def create_logits_tensor(token_ids: list[int],
|
||||
vocab_size: int = 100) -> torch.Tensor:
|
||||
"""Helper function to create logits tensor that
|
||||
will produce desired token ids on argmax"""
|
||||
@@ -23,7 +22,7 @@ def create_logits_tensor(token_ids: List[int],
|
||||
return logits
|
||||
|
||||
|
||||
def create_sampling_metadata(spec_tokens: List[List[int]]) -> SamplingMetadata:
|
||||
def create_sampling_metadata(spec_tokens: list[list[int]]) -> SamplingMetadata:
|
||||
batch_size = len(spec_tokens)
|
||||
return SamplingMetadata(
|
||||
temperature=torch.tensor([]),
|
||||
@@ -106,7 +105,7 @@ def test_single_token_sequence(sampler):
|
||||
|
||||
def test_empty_sequence(sampler):
|
||||
"""Test handling empty sequence of speculated tokens"""
|
||||
spec_tokens: List[List[int]] = [[]]
|
||||
spec_tokens: list[list[int]] = [[]]
|
||||
output_tokens = [5] # Just the bonus token
|
||||
|
||||
metadata = create_sampling_metadata(spec_tokens)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
from typing import Dict, List, Optional, Set, Tuple
|
||||
from typing import Optional
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
@@ -32,7 +32,7 @@ def _create_penalty_tensor(batch_size: int, penalty_value: float,
|
||||
|
||||
|
||||
def _create_prompt_tokens_tensor(
|
||||
prompt_token_ids: List[List[int]],
|
||||
prompt_token_ids: list[list[int]],
|
||||
vocab_size: int,
|
||||
device: torch.device,
|
||||
) -> torch.Tensor:
|
||||
@@ -49,8 +49,8 @@ def _create_logit_bias(
|
||||
batch_size: int,
|
||||
vocab_size: int,
|
||||
bias_value: float,
|
||||
) -> List[Optional[Dict[int, float]]]:
|
||||
res: List[Optional[Dict[int, float]]] = []
|
||||
) -> list[Optional[dict[int, float]]]:
|
||||
res: list[Optional[dict[int, float]]] = []
|
||||
for i in range(batch_size):
|
||||
logit_bias = {min(i, vocab_size - 1): bias_value}
|
||||
res.append(logit_bias)
|
||||
@@ -83,8 +83,8 @@ def _create_default_sampling_metadata(
|
||||
vocab_size: int,
|
||||
device: torch.device,
|
||||
) -> SamplingMetadata:
|
||||
output_token_ids: List[List[int]] = []
|
||||
prompt_token_ids: List[List[int]] = []
|
||||
output_token_ids: list[list[int]] = []
|
||||
prompt_token_ids: list[list[int]] = []
|
||||
for _ in range(batch_size):
|
||||
output_token_ids.append(
|
||||
np.random.randint(0, vocab_size, size=num_output_tokens).tolist())
|
||||
@@ -118,8 +118,8 @@ def _create_default_sampling_metadata(
|
||||
|
||||
def _generate_min_token_penalties_and_stop_tokens(
|
||||
num_output_tokens: int, batch_size: int, vocab_size: int,
|
||||
batch_indices_for_min_token_penalty: List[int]
|
||||
) -> Dict[int, Tuple[int, Set[int]]]:
|
||||
batch_indices_for_min_token_penalty: list[int]
|
||||
) -> dict[int, tuple[int, set[int]]]:
|
||||
"""
|
||||
Generates and returns a dict of minimum token penalties and
|
||||
corresponding stop token IDs (`min_tokens`, `stop_token_ids`) for each
|
||||
@@ -130,7 +130,7 @@ def _generate_min_token_penalties_and_stop_tokens(
|
||||
and a random set of stop token IDs is created. Otherwise, a lower
|
||||
`min_tokens` value is assigned, and the stop token IDs set is empty.
|
||||
"""
|
||||
min_tokens: Dict[int, Tuple[int, Set[int]]] = {}
|
||||
min_tokens: dict[int, tuple[int, set[int]]] = {}
|
||||
for index in range(batch_size):
|
||||
if index in batch_indices_for_min_token_penalty:
|
||||
min_tokens[index] = (
|
||||
@@ -147,7 +147,7 @@ def _generate_min_token_penalties_and_stop_tokens(
|
||||
|
||||
def _create_weighted_output_token_list(
|
||||
batch_size: int,
|
||||
vocab_size: int) -> Tuple[List[List[int]], List[List[int]]]:
|
||||
vocab_size: int) -> tuple[list[list[int]], list[list[int]]]:
|
||||
"""
|
||||
Creates an output token list where each token occurs a distinct
|
||||
number of times.
|
||||
@@ -157,7 +157,7 @@ def _create_weighted_output_token_list(
|
||||
list, each with a different frequency.
|
||||
|
||||
Returns:
|
||||
Tuple[List[List[int]], List[List[int]]]:
|
||||
tuple[list[list[int]], list[list[int]]]:
|
||||
- The first element is the output token list, where each sublist
|
||||
corresponds to a batch and contains tokens with weighted
|
||||
frequencies.
|
||||
@@ -165,8 +165,8 @@ def _create_weighted_output_token_list(
|
||||
batch, ordered by their frequency in the corresponding output
|
||||
list.
|
||||
"""
|
||||
output_token_ids: List[List[int]] = []
|
||||
sorted_token_ids_in_output: List[List[int]] = []
|
||||
output_token_ids: list[list[int]] = []
|
||||
sorted_token_ids_in_output: list[list[int]] = []
|
||||
for _ in range(batch_size):
|
||||
distinct_token_ids = np.random.choice(vocab_size,
|
||||
size=np.random.randint(1, 10),
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import re
|
||||
from typing import List, Tuple
|
||||
|
||||
from vllm import CompletionOutput
|
||||
|
||||
|
||||
def get_test_batch(batch_logprobs_composition: str) -> List[Tuple]:
|
||||
def get_test_batch(batch_logprobs_composition: str) -> list[tuple]:
|
||||
"""Generate logprobs configs for a batch of requests
|
||||
|
||||
A given request's logprobs configuration is (1) num_sample_logprobs and (2)
|
||||
@@ -32,7 +31,7 @@ def get_test_batch(batch_logprobs_composition: str) -> List[Tuple]:
|
||||
|
||||
Returns:
|
||||
|
||||
List of (Optional[num_sample_logprobs], Optional[num_prompt_logprobs])
|
||||
list of (Optional[num_sample_logprobs], Optional[num_prompt_logprobs])
|
||||
tuples
|
||||
"""
|
||||
if batch_logprobs_composition == "NONE":
|
||||
|
||||
Reference in New Issue
Block a user