[Misc] FlattenLogprobs -> FlatLogprobs (#28335)
This commit is contained in:
+20
-20
@@ -5,7 +5,7 @@
|
||||
import pytest
|
||||
|
||||
from vllm.logprobs import (
|
||||
FlattenLogprobs,
|
||||
FlatLogprobs,
|
||||
Logprob,
|
||||
LogprobsOnePosition,
|
||||
append_logprobs_for_next_position,
|
||||
@@ -14,8 +14,8 @@ from vllm.logprobs import (
|
||||
)
|
||||
|
||||
|
||||
def test_create_logprobs_non_flatten(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("VLLM_FLATTEN_LOGPROBS", "0")
|
||||
def test_create_logprobs_non_flat(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("VLLM_FLAT_LOGPROBS", "0")
|
||||
|
||||
prompt_logprobs = create_prompt_logprobs()
|
||||
assert isinstance(prompt_logprobs, list)
|
||||
@@ -28,11 +28,11 @@ def test_create_logprobs_non_flatten(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
assert len(sample_logprobs) == 0
|
||||
|
||||
|
||||
def test_create_logprobs_flatten(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("VLLM_FLATTEN_LOGPROBS", "1")
|
||||
def test_create_logprobs_flat(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("VLLM_FLAT_LOGPROBS", "1")
|
||||
|
||||
prompt_logprobs = create_prompt_logprobs()
|
||||
assert isinstance(prompt_logprobs, FlattenLogprobs)
|
||||
assert isinstance(prompt_logprobs, FlatLogprobs)
|
||||
assert prompt_logprobs.start_indices == [0]
|
||||
assert prompt_logprobs.end_indices == [0]
|
||||
assert len(prompt_logprobs.token_ids) == 0
|
||||
@@ -44,7 +44,7 @@ def test_create_logprobs_flatten(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
assert prompt_logprobs[0] == dict()
|
||||
|
||||
sample_logprobs = create_sample_logprobs()
|
||||
assert isinstance(sample_logprobs, FlattenLogprobs)
|
||||
assert isinstance(sample_logprobs, FlatLogprobs)
|
||||
assert len(sample_logprobs.start_indices) == 0
|
||||
assert len(sample_logprobs.end_indices) == 0
|
||||
assert len(sample_logprobs.token_ids) == 0
|
||||
@@ -54,10 +54,10 @@ def test_create_logprobs_flatten(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
assert len(sample_logprobs) == 0
|
||||
|
||||
|
||||
def test_append_logprobs_for_next_position_none_flatten(
|
||||
def test_append_logprobs_for_next_position_none_flat(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setenv("VLLM_FLATTEN_LOGPROBS", "0")
|
||||
monkeypatch.setenv("VLLM_FLAT_LOGPROBS", "0")
|
||||
logprobs = create_sample_logprobs()
|
||||
append_logprobs_for_next_position(
|
||||
logprobs,
|
||||
@@ -85,10 +85,10 @@ def test_append_logprobs_for_next_position_none_flatten(
|
||||
]
|
||||
|
||||
|
||||
def test_append_logprobs_for_next_position_flatten(
|
||||
def test_append_logprobs_for_next_position_flat(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setenv("VLLM_FLATTEN_LOGPROBS", "1")
|
||||
monkeypatch.setenv("VLLM_FLAT_LOGPROBS", "1")
|
||||
logprobs = create_sample_logprobs()
|
||||
append_logprobs_for_next_position(
|
||||
logprobs,
|
||||
@@ -106,7 +106,7 @@ def test_append_logprobs_for_next_position_flatten(
|
||||
rank=11,
|
||||
num_logprobs=-1,
|
||||
)
|
||||
assert isinstance(logprobs, FlattenLogprobs)
|
||||
assert isinstance(logprobs, FlatLogprobs)
|
||||
assert logprobs.start_indices == [0, 1]
|
||||
assert logprobs.end_indices == [1, 3]
|
||||
assert logprobs.token_ids == [1, 2, 3]
|
||||
@@ -129,8 +129,8 @@ LOGPROBS_ONE_POSITION_2: LogprobsOnePosition = {
|
||||
}
|
||||
|
||||
|
||||
def test_flatten_logprobs_append() -> None:
|
||||
logprobs = FlattenLogprobs()
|
||||
def test_flat_logprobs_append() -> None:
|
||||
logprobs = FlatLogprobs()
|
||||
logprobs.append(LOGPROBS_ONE_POSITION_0)
|
||||
logprobs.append(LOGPROBS_ONE_POSITION_1)
|
||||
assert logprobs.start_indices == [0, 1]
|
||||
@@ -149,8 +149,8 @@ def test_flatten_logprobs_append() -> None:
|
||||
assert logprobs.decoded_tokens == ["10", "20", "30", "40", "50", "60"]
|
||||
|
||||
|
||||
def test_flatten_logprobs_extend() -> None:
|
||||
logprobs = FlattenLogprobs()
|
||||
def test_flat_logprobs_extend() -> None:
|
||||
logprobs = FlatLogprobs()
|
||||
# Extend with list[LogprobsOnePosition]
|
||||
logprobs.extend([LOGPROBS_ONE_POSITION_2, LOGPROBS_ONE_POSITION_0])
|
||||
assert logprobs.start_indices == [0, 3]
|
||||
@@ -160,9 +160,9 @@ def test_flatten_logprobs_extend() -> None:
|
||||
assert logprobs.ranks == [40, 50, 60, 10]
|
||||
assert logprobs.decoded_tokens == ["40", "50", "60", "10"]
|
||||
|
||||
other_logprobs = FlattenLogprobs()
|
||||
other_logprobs = FlatLogprobs()
|
||||
other_logprobs.extend([LOGPROBS_ONE_POSITION_1, LOGPROBS_ONE_POSITION_0])
|
||||
# Extend with another FlattenLogprobs
|
||||
# Extend with another FlatLogprobs
|
||||
logprobs.extend(other_logprobs)
|
||||
assert logprobs.start_indices == [0, 3, 4, 6]
|
||||
assert logprobs.end_indices == [3, 4, 6, 7]
|
||||
@@ -172,8 +172,8 @@ def test_flatten_logprobs_extend() -> None:
|
||||
assert logprobs.decoded_tokens == ["40", "50", "60", "10", "20", "30", "10"]
|
||||
|
||||
|
||||
def test_flatten_logprobs_access() -> None:
|
||||
logprobs = FlattenLogprobs()
|
||||
def test_flat_logprobs_access() -> None:
|
||||
logprobs = FlatLogprobs()
|
||||
logprobs.extend(
|
||||
[LOGPROBS_ONE_POSITION_1, LOGPROBS_ONE_POSITION_2, LOGPROBS_ONE_POSITION_0]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user