[MyPy][3/N] Fix MyPy errors in test groups (part 3) (#55939)
Signed-off-by: Taimys <ffy2281693949@gmail.com> Signed-off-by: Luyi Xiao <81631911+luyixiao95@users.noreply.github.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Codex <noreply@openai.com> Co-authored-by: Luyi Xiao <81631911+luyixiao95@users.noreply.github.com> Co-authored-by: Taimys <ffy2281693949@gmail.com> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Codex
Luyi Xiao
Taimys
Harry Mellor
Claude Opus 5.5
parent
c4fa6f36a7
commit
5225f1bacb
@@ -53,12 +53,10 @@ def test_video_media_io_kwargs(monkeypatch: pytest.MonkeyPatch):
|
||||
imageio = ImageMediaIO()
|
||||
|
||||
# Verify that different args pass/fail assertions as expected.
|
||||
videoio = VideoMediaIO(imageio, **{"num_frames": 10, "fps": 1.0})
|
||||
videoio = VideoMediaIO(imageio, num_frames=10, fps=1.0)
|
||||
_ = videoio.load_bytes(b"test")
|
||||
|
||||
videoio = VideoMediaIO(
|
||||
imageio, **{"num_frames": 10, "fps": 1.0, "not_used": "not_used"}
|
||||
)
|
||||
videoio = VideoMediaIO(imageio, num_frames=10, fps=1.0, not_used="not_used")
|
||||
_ = videoio.load_bytes(b"test")
|
||||
|
||||
with pytest.raises(AssertionError, match="bad num_frames"):
|
||||
@@ -66,11 +64,11 @@ def test_video_media_io_kwargs(monkeypatch: pytest.MonkeyPatch):
|
||||
_ = videoio.load_bytes(b"test")
|
||||
|
||||
with pytest.raises(AssertionError, match="bad num_frames"):
|
||||
videoio = VideoMediaIO(imageio, **{"num_frames": 9, "fps": 1.0})
|
||||
videoio = VideoMediaIO(imageio, num_frames=9, fps=1.0)
|
||||
_ = videoio.load_bytes(b"test")
|
||||
|
||||
with pytest.raises(AssertionError, match="bad fps"):
|
||||
videoio = VideoMediaIO(imageio, **{"num_frames": 10, "fps": 2.0})
|
||||
videoio = VideoMediaIO(imageio, num_frames=10, fps=2.0)
|
||||
_ = videoio.load_bytes(b"test")
|
||||
|
||||
|
||||
@@ -86,14 +84,14 @@ def test_opencv_video_io_colorspace(tmp_path, is_color: bool, fourcc: str, ext:
|
||||
image = Image.open(image_path)
|
||||
|
||||
if not is_color:
|
||||
image_path = f"{tmp_path}/test_grayscale_image.png"
|
||||
image_path = Path(tmp_path) / "test_grayscale_image.png"
|
||||
image = image.convert("L")
|
||||
image.save(image_path)
|
||||
# Convert to gray RGB for comparison
|
||||
image = image.convert("RGB")
|
||||
video_path = f"{tmp_path}/test_RGB_video.{ext}"
|
||||
create_video_from_image(
|
||||
image_path,
|
||||
str(image_path),
|
||||
video_path,
|
||||
num_frames=2,
|
||||
is_color=is_color,
|
||||
@@ -385,7 +383,9 @@ def test_pynvvideocodec_unrelated_error_propagates(
|
||||
|
||||
with pytest.raises(RuntimeError) as exc_info:
|
||||
PyNvVideoCodecVideoBackendMixin.decode_frames_pynvvideocodec(
|
||||
None, b"video", None
|
||||
None,
|
||||
b"video",
|
||||
None, # type: ignore[arg-type] # Fails before target metadata is used.
|
||||
)
|
||||
|
||||
assert exc_info.value is original_error
|
||||
|
||||
@@ -179,7 +179,7 @@ def test_audio_resampler_invalid_method(dummy_audio):
|
||||
# Validated eagerly so a bad method fails at construction, not on the
|
||||
# first audio request.
|
||||
with pytest.raises(ValueError, match="Invalid resampling method"):
|
||||
AudioResampler(target_sr=22050, method="invalid")
|
||||
AudioResampler(target_sr=22050, method="invalid") # type: ignore[arg-type]
|
||||
|
||||
|
||||
def test_audio_resampler_no_target_sr(dummy_audio):
|
||||
@@ -378,6 +378,7 @@ class TestMultiModalDataParserChannelNormalization:
|
||||
result = parser._parse_audio_data((stereo_audio, 16000))
|
||||
|
||||
# Check that result is mono (1D)
|
||||
assert result is not None
|
||||
audio_item = result.get(0)
|
||||
assert audio_item.ndim == 1, f"Expected 1D mono audio, got {audio_item.ndim}D"
|
||||
assert audio_item.shape == (3,), f"Expected shape (3,), got {audio_item.shape}"
|
||||
@@ -404,6 +405,7 @@ class TestMultiModalDataParserChannelNormalization:
|
||||
result = parser._parse_audio_data((stereo_audio, 16000))
|
||||
|
||||
# Check that result preserves original shape (after resampling)
|
||||
assert result is not None
|
||||
audio_item = result.get(0)
|
||||
# When target_channels=None, stereo audio should be preserved
|
||||
assert audio_item.ndim == 2, f"Expected 2D stereo audio, got {audio_item.ndim}D"
|
||||
@@ -425,6 +427,7 @@ class TestMultiModalDataParserChannelNormalization:
|
||||
result = parser._parse_audio_data((mono_audio, 16000))
|
||||
|
||||
# Check that result is still mono (1D)
|
||||
assert result is not None
|
||||
audio_item = result.get(0)
|
||||
assert audio_item.ndim == 1
|
||||
assert audio_item.shape == (16000,)
|
||||
@@ -446,6 +449,7 @@ class TestMultiModalDataParserChannelNormalization:
|
||||
result = parser._parse_audio_data((surround_audio, 16000))
|
||||
|
||||
# Check that result is stereo (2 channels)
|
||||
assert result is not None
|
||||
audio_item = result.get(0)
|
||||
assert audio_item.ndim == 2
|
||||
assert audio_item.shape[0] == 2 # 2 channels
|
||||
@@ -483,6 +487,7 @@ class TestAudioPipelineE2E:
|
||||
|
||||
# Process audio through the parser
|
||||
result = parser._parse_audio_data((stereo_torchaudio, 16000))
|
||||
assert result is not None
|
||||
audio_output = result.get(0)
|
||||
|
||||
# Verify output is mono 1D
|
||||
@@ -512,6 +517,7 @@ class TestAudioPipelineE2E:
|
||||
|
||||
# Process audio through the parser
|
||||
result = parser._parse_audio_data((stereo_soundfile, 16000))
|
||||
assert result is not None
|
||||
audio_output = result.get(0)
|
||||
|
||||
# Verify output is mono 1D
|
||||
@@ -537,6 +543,7 @@ class TestAudioPipelineE2E:
|
||||
|
||||
# Process audio through the parser
|
||||
result = parser._parse_audio_data((mono_pyav, 16000))
|
||||
assert result is not None
|
||||
audio_output = result.get(0)
|
||||
|
||||
# Verify output is still mono 1D
|
||||
@@ -572,6 +579,7 @@ class TestAudioPipelineE2E:
|
||||
|
||||
# Process audio through the parser
|
||||
result = parser._parse_audio_data((surround_audio, 16000))
|
||||
assert result is not None
|
||||
audio_output = result.get(0)
|
||||
|
||||
# Verify output is mono 1D
|
||||
@@ -603,6 +611,7 @@ class TestAudioPipelineE2E:
|
||||
# Process audio through the parser
|
||||
# Note: Parser expects numpy, so we convert first (simulating real usage)
|
||||
result = parser._parse_audio_data((stereo_torch.numpy(), 16000))
|
||||
assert result is not None
|
||||
audio_output = result.get(0)
|
||||
|
||||
# Verify output is mono 1D numpy array
|
||||
@@ -630,6 +639,7 @@ class TestAudioPipelineE2E:
|
||||
|
||||
# Process audio through the parser
|
||||
result = parser._parse_audio_data((stereo_audio, 16000))
|
||||
assert result is not None
|
||||
audio_output = result.get(0)
|
||||
|
||||
# Verify output preserves stereo (2D)
|
||||
@@ -654,6 +664,7 @@ class TestAudioPipelineE2E:
|
||||
|
||||
# Process audio through the parser
|
||||
result = parser._parse_audio_data((stereo_48k, 48000))
|
||||
assert result is not None
|
||||
audio_output = result.get(0)
|
||||
|
||||
# Verify output is mono 1D at target sample rate
|
||||
@@ -677,6 +688,7 @@ class TestAudioPipelineE2E:
|
||||
)
|
||||
|
||||
result = parser._parse_audio_data((short_stereo, 16000))
|
||||
assert result is not None
|
||||
audio_output = result.get(0)
|
||||
|
||||
# Should still produce mono output
|
||||
|
||||
@@ -11,7 +11,6 @@ import torch
|
||||
from vllm.config import ModelConfig, ParallelConfig, VllmConfig
|
||||
from vllm.config.multimodal import MultiModalConfig
|
||||
from vllm.multimodal.cache import (
|
||||
BaseMultiModalProcessorCache,
|
||||
BaseMultiModalReceiverCache,
|
||||
LruKeyReplicatedReceiverCache,
|
||||
LruKeyReplicatedSenderCache,
|
||||
@@ -145,6 +144,8 @@ def _compare_caches(
|
||||
cache_1_p0 = processor_cache_from_config(config_1)
|
||||
cache_1_p1 = engine_receiver_cache_from_config(config_1)
|
||||
|
||||
assert config_0.model_config.multimodal_config is not None
|
||||
assert config_1.model_config.multimodal_config is not None
|
||||
cache_size_gb = max(
|
||||
config_0.model_config.multimodal_config.mm_processor_cache_gb,
|
||||
config_1.model_config.multimodal_config.mm_processor_cache_gb,
|
||||
@@ -280,6 +281,7 @@ def test_oversized_item_is_served_uncached():
|
||||
|
||||
p0 = LruKeyReplicatedSenderCache(model_config) # type: ignore[arg-type]
|
||||
p1 = LruKeyReplicatedReceiverCache(model_config) # type: ignore[arg-type]
|
||||
assert item is not None
|
||||
assert p0.get_and_update_item((item, []), "big")[0] is item
|
||||
assert not p0.is_cached_item("big")
|
||||
assert p1.get_and_update_item(item, "big") is item
|
||||
@@ -318,6 +320,7 @@ def test_mm_cache_miss_raises_and_recovers():
|
||||
assert p0.is_cached_item(mm_hash)
|
||||
# On the next request P0 short-circuits to data=None -- the drift bug when
|
||||
# P1 lacks the item.
|
||||
assert item is not None
|
||||
hit = p0.get_and_update_item((item, []), mm_hash)
|
||||
assert hit[0] is None
|
||||
|
||||
@@ -326,6 +329,7 @@ def test_mm_cache_miss_raises_and_recovers():
|
||||
p0.invalidate(mm_hash)
|
||||
assert not p0.is_cached_item(mm_hash)
|
||||
|
||||
assert item is not None
|
||||
resent = p0.get_and_update_item((item, []), mm_hash)
|
||||
assert resent[0] is item # MISS again -> data is resent
|
||||
assert p1.get_and_update_item(item, mm_hash) == item # P1 now caches it
|
||||
@@ -459,6 +463,7 @@ def test_shm_receiver_handles_prefix_covered_items(monkeypatch):
|
||||
address_item, _ = p0.get_and_update_item((item, []), mm_hash)
|
||||
first = _feature(mm_hash, address_item)
|
||||
p1.get_and_update_features([first])
|
||||
assert first.data is not None
|
||||
assert torch.equal(first.data["dummy"].data, item["dummy"].data)
|
||||
|
||||
# Request 2 (identical, fully prefix-covered): the sender hit takes
|
||||
@@ -476,6 +481,7 @@ def test_shm_receiver_handles_prefix_covered_items(monkeypatch):
|
||||
|
||||
assert covered_uncached.data is None
|
||||
# The address item is resolved to the cached payload.
|
||||
assert covered_cached.data is not None
|
||||
assert torch.equal(covered_cached.data["dummy"].data, item["dummy"].data)
|
||||
|
||||
# The hit's writer references were acknowledged by the worker, so the
|
||||
@@ -488,7 +494,7 @@ def test_shm_receiver_handles_prefix_covered_items(monkeypatch):
|
||||
|
||||
|
||||
def _run_test_cache_eviction_lru(
|
||||
p0_cache: BaseMultiModalProcessorCache,
|
||||
p0_cache: LruKeyReplicatedSenderCache,
|
||||
p1_cache: BaseMultiModalReceiverCache,
|
||||
base_item_size: int,
|
||||
):
|
||||
@@ -603,7 +609,7 @@ def test_cache_eviction_lru_cache():
|
||||
# image_B is protected from eviction then image_i cannot be added.
|
||||
# This proving normal eviction and reuse behavior.
|
||||
def _run_test_cache_eviction_shm(
|
||||
p0_cache: BaseMultiModalProcessorCache,
|
||||
p0_cache: ShmObjectStoreSenderCache,
|
||||
p1_cache: BaseMultiModalReceiverCache,
|
||||
base_item_size: int,
|
||||
):
|
||||
@@ -860,9 +866,9 @@ async def test_release_kv_cache_resends_mm_payload(use_async, release_error):
|
||||
|
||||
async def call_release():
|
||||
if use_async:
|
||||
await AsyncLLM.release_kv_cache_memory(engine)
|
||||
await AsyncLLM.release_kv_cache_memory(engine) # type: ignore[arg-type]
|
||||
else:
|
||||
LLMEngine.release_kv_cache_memory(engine)
|
||||
LLMEngine.release_kv_cache_memory(engine) # type: ignore[arg-type]
|
||||
|
||||
if release_error:
|
||||
with pytest.raises(RuntimeError, match=release_error):
|
||||
@@ -894,9 +900,10 @@ def test_sleep_wake_preserves_mm_cache_consistency():
|
||||
"""Regression for vllm-project/vllm#42995."""
|
||||
from vllm import LLM, SamplingParams
|
||||
from vllm.assets.image import ImageAsset
|
||||
from vllm.inputs import TextPrompt
|
||||
|
||||
image = ImageAsset("stop_sign").pil_image
|
||||
prompt = {
|
||||
prompt: TextPrompt = {
|
||||
"prompt": _SLEEP_VISION_PROMPT,
|
||||
"multi_modal_data": {"image": image},
|
||||
}
|
||||
|
||||
@@ -131,6 +131,7 @@ def test_hash_collision_video_num_frames():
|
||||
}
|
||||
video = MediaWithBytes((frames, metadata), source)
|
||||
items = MultiModalDataParser()._parse_video_data([video])
|
||||
assert items is not None
|
||||
return items.get_all_items_for_hash()[0]
|
||||
|
||||
hasher = MultiModalHasher
|
||||
@@ -155,6 +156,7 @@ def test_hash_video_tensor_frames():
|
||||
}
|
||||
video = MediaWithBytes((frames, metadata), source)
|
||||
items = MultiModalDataParser()._parse_video_data([video])
|
||||
assert items is not None
|
||||
return items.get_all_items_for_hash()[0]
|
||||
|
||||
np_frames = np.zeros((2, 8, 8, 3), dtype=np.uint8)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import time
|
||||
from collections.abc import Sequence
|
||||
from contextlib import nullcontext
|
||||
from copy import deepcopy
|
||||
from types import SimpleNamespace
|
||||
@@ -868,7 +869,7 @@ def test_limit_mm_per_prompt_apply(model_id, num_images, limit, is_valid):
|
||||
],
|
||||
)
|
||||
def test_budget_caps_prevent_dummy_input_validation_failure(
|
||||
model_id, user_limit, supported_limit
|
||||
model_id, user_limit, supported_limit, monkeypatch
|
||||
):
|
||||
limit_mm_per_prompt = {"image": user_limit}
|
||||
|
||||
@@ -878,7 +879,9 @@ def test_budget_caps_prevent_dummy_input_validation_failure(
|
||||
)
|
||||
|
||||
processor = MULTIMODAL_REGISTRY.create_processor(model_config)
|
||||
processor.info.get_supported_mm_limits = lambda: {"image": supported_limit}
|
||||
monkeypatch.setattr(
|
||||
processor.info, "get_supported_mm_limits", lambda: {"image": supported_limit}
|
||||
)
|
||||
|
||||
# This is what budget.py uses to derive mm_counts
|
||||
allowed = processor.info.allowed_mm_limits
|
||||
@@ -936,7 +939,7 @@ def test_hf_processor_init_kwargs(
|
||||
)
|
||||
|
||||
processor = ctx.get_hf_processor(
|
||||
DummyProcessor, # type: ignore[arg-type]
|
||||
DummyProcessor,
|
||||
**inference_kwargs,
|
||||
)
|
||||
assert processor.a == expected_kwargs["a"]
|
||||
@@ -967,7 +970,7 @@ def test_hf_processor_call_kwargs(
|
||||
tokenizer=None,
|
||||
)
|
||||
|
||||
processor = ctx.get_hf_processor(DummyProcessor) # type: ignore[arg-type]
|
||||
processor = ctx.get_hf_processor(DummyProcessor)
|
||||
|
||||
result = ctx.call_hf_processor(processor, {}, inference_kwargs)
|
||||
assert result == expected_kwargs
|
||||
@@ -1278,7 +1281,7 @@ def test_get_supported_mm_processor_kwargs_uses_supported_modalities(
|
||||
processor: SimpleNamespace,
|
||||
expected: dict[str, set[str]],
|
||||
) -> None:
|
||||
info = BaseProcessingInfo(SimpleNamespace())
|
||||
info = BaseProcessingInfo(SimpleNamespace()) # type: ignore[arg-type]
|
||||
info.__dict__["supported_mm_limits"] = supported_mm_limits
|
||||
monkeypatch.setattr(info, "get_hf_processor", lambda **_: processor)
|
||||
|
||||
@@ -1288,7 +1291,7 @@ def test_get_supported_mm_processor_kwargs_uses_supported_modalities(
|
||||
def test_supported_mm_processor_kwargs_is_cached(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
info = BaseProcessingInfo(SimpleNamespace())
|
||||
info = BaseProcessingInfo(SimpleNamespace()) # type: ignore[arg-type]
|
||||
expected = {"images_kwargs": {"size"}}
|
||||
calls = 0
|
||||
|
||||
@@ -1541,7 +1544,10 @@ def test_processor_inputs_hashes_scope_kwargs_by_modality():
|
||||
"video": [np.zeros((2, 8, 8, 3), dtype=np.uint8)],
|
||||
}
|
||||
)
|
||||
mm_uuid_items = {"image": ["image-uuid"], "video": ["video-uuid"]}
|
||||
mm_uuid_items: dict[str, Sequence[str | None]] = {
|
||||
"image": ["image-uuid"],
|
||||
"video": ["video-uuid"],
|
||||
}
|
||||
|
||||
def get_hashes(video_frames: int, image_size: int, video_size: int):
|
||||
return ProcessorInputs(
|
||||
@@ -1621,7 +1627,7 @@ def test_processor_inputs_hashes_distinguish_kwargs_shapes(left, right):
|
||||
[(None, 491520, 491520), (True, 491520, 8192), (True, 128, 128), (False, 128, 128)],
|
||||
)
|
||||
def test_dummy_inputs_scheduler_budget(
|
||||
chunked_prefill, max_model_len, expected_seq_len
|
||||
chunked_prefill, max_model_len, expected_seq_len, monkeypatch
|
||||
):
|
||||
ctx = build_model_context(
|
||||
"llava-hf/llava-v1.6-mistral-7b-hf",
|
||||
@@ -1634,11 +1640,9 @@ def test_dummy_inputs_scheduler_budget(
|
||||
ctx.model_config,
|
||||
tokenizer=ctx.tokenizer,
|
||||
)
|
||||
processor.apply = lambda *args, **kwargs: {"prompt_token_ids": [7]}
|
||||
|
||||
kwargs = {}
|
||||
scheduler_config = None
|
||||
if chunked_prefill is not None:
|
||||
kwargs["scheduler_config"] = SchedulerConfig(
|
||||
scheduler_config = SchedulerConfig(
|
||||
max_model_len=max_model_len,
|
||||
is_encoder_decoder=False,
|
||||
max_num_batched_tokens=8192,
|
||||
@@ -1646,5 +1650,10 @@ def test_dummy_inputs_scheduler_budget(
|
||||
enable_chunked_prefill=chunked_prefill,
|
||||
)
|
||||
|
||||
result = processor.get_dummy_mm_inputs({"image": 1}, **kwargs)
|
||||
monkeypatch.setattr(
|
||||
processor, "apply", lambda *args, **kwargs: {"prompt_token_ids": [7]}
|
||||
)
|
||||
result = processor.get_dummy_mm_inputs(
|
||||
{"image": 1}, scheduler_config=scheduler_config
|
||||
)
|
||||
assert len(result["prompt_token_ids"]) == expected_seq_len
|
||||
|
||||
@@ -24,4 +24,4 @@ def test_create_processor_error_uses_served_model_name():
|
||||
ValueError,
|
||||
match="friendly-model-name is not a multimodal model",
|
||||
):
|
||||
MULTIMODAL_REGISTRY.create_processor(model_config)
|
||||
MULTIMODAL_REGISTRY.create_processor(model_config) # type: ignore[arg-type]
|
||||
|
||||
@@ -7,6 +7,7 @@ import sys
|
||||
import threading
|
||||
from contextlib import ExitStack, contextmanager
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
@@ -83,24 +84,28 @@ def _fresh_decoder_pool():
|
||||
@VIDEO_LOADER_REGISTRY.register("test_video_loader_1")
|
||||
class TestVideoLoader1(VideoLoader):
|
||||
@classmethod
|
||||
def load_bytes(cls, data: bytes, num_frames: int = -1) -> npt.NDArray:
|
||||
return FAKE_OUTPUT_1
|
||||
def load_bytes(
|
||||
cls, data: bytes, num_frames: int = -1, **kwargs
|
||||
) -> tuple[npt.NDArray, dict[str, Any]]:
|
||||
return FAKE_OUTPUT_1, {}
|
||||
|
||||
|
||||
@VIDEO_LOADER_REGISTRY.register("test_video_loader_2")
|
||||
class TestVideoLoader2(VideoLoader):
|
||||
@classmethod
|
||||
def load_bytes(cls, data: bytes, num_frames: int = -1) -> npt.NDArray:
|
||||
return FAKE_OUTPUT_2
|
||||
def load_bytes(
|
||||
cls, data: bytes, num_frames: int = -1, **kwargs
|
||||
) -> tuple[npt.NDArray, dict[str, Any]]:
|
||||
return FAKE_OUTPUT_2, {}
|
||||
|
||||
|
||||
def test_video_loader_registry():
|
||||
custom_loader_1 = VIDEO_LOADER_REGISTRY.load("test_video_loader_1")
|
||||
output_1 = custom_loader_1.load_bytes(b"test")
|
||||
output_1, _ = custom_loader_1.load_bytes(b"test")
|
||||
np.testing.assert_array_equal(output_1, FAKE_OUTPUT_1)
|
||||
|
||||
custom_loader_2 = VIDEO_LOADER_REGISTRY.load("test_video_loader_2")
|
||||
output_2 = custom_loader_2.load_bytes(b"test")
|
||||
output_2, _ = custom_loader_2.load_bytes(b"test")
|
||||
np.testing.assert_array_equal(output_2, FAKE_OUTPUT_2)
|
||||
|
||||
|
||||
@@ -488,7 +493,7 @@ def test_pynvvideocodec_failed_rebuild_invalidates_decoder_slot():
|
||||
|
||||
old_decoder = FakeDecoder()
|
||||
slot = PyNvVideoCodecDecoderSlot(FakeStream())
|
||||
slot.decoder = old_decoder
|
||||
slot.decoder = old_decoder # type: ignore[assignment] # Fake retained GPU decoder.
|
||||
slot.source_path = "valid.mp4"
|
||||
|
||||
class FakeNvc:
|
||||
@@ -596,7 +601,9 @@ def test_pynvvideocodec_h200_recovers_after_unsupported_8k():
|
||||
_pynv_decoder_pool.max_slots = old_max
|
||||
|
||||
|
||||
def test_pynvvideocodec_cross_subclass_shares_single_pool():
|
||||
def test_pynvvideocodec_cross_subclass_shares_single_pool(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
):
|
||||
"""Regression test for GHSA-j682-9xp5-rrf3.
|
||||
|
||||
Multiple subclasses of PyNvVideoCodecVideoBackendMixin must share the
|
||||
@@ -623,11 +630,12 @@ def test_pynvvideocodec_cross_subclass_shares_single_pool():
|
||||
with _fresh_decoder_pool() as pool:
|
||||
pool.max_slots = 2
|
||||
|
||||
orig_create = PyNvVideoCodecVideoBackendMixin._create_decoder_slot
|
||||
PyNvVideoCodecVideoBackendMixin._create_decoder_slot = classmethod(
|
||||
fake_create_slot
|
||||
)
|
||||
try:
|
||||
with monkeypatch.context() as m:
|
||||
m.setattr(
|
||||
PyNvVideoCodecVideoBackendMixin,
|
||||
"_create_decoder_slot",
|
||||
classmethod(fake_create_slot),
|
||||
)
|
||||
with ExitStack() as stack:
|
||||
stack.enter_context(MixinSubclassA._borrow_decoder_slot())
|
||||
stack.enter_context(MixinSubclassB._borrow_decoder_slot())
|
||||
@@ -652,8 +660,6 @@ def test_pynvvideocodec_cross_subclass_shares_single_pool():
|
||||
|
||||
assert create_count == 2
|
||||
assert len(pool.slots) == 2
|
||||
finally:
|
||||
PyNvVideoCodecVideoBackendMixin._create_decoder_slot = orig_create
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hw_decoders", [0, -1, 1.5, True, "2"])
|
||||
@@ -662,7 +668,7 @@ def test_pynvvideocodec_rejects_invalid_hw_decoders(hw_decoders: object):
|
||||
VideoBackend.load_bytes(
|
||||
b"fake video",
|
||||
backend=PYNVVIDEOCODEC_VIDEO_BACKEND,
|
||||
hw_decoders=hw_decoders, # type: ignore[arg-type]
|
||||
hw_decoders=hw_decoders,
|
||||
)
|
||||
|
||||
|
||||
@@ -799,6 +805,7 @@ def test_video_processor_from_model_repo(
|
||||
)
|
||||
|
||||
backend = get_video_loader_backend_for_processor(video_processor)
|
||||
assert backend is not None
|
||||
loader = VIDEO_LOADER_REGISTRY.load(backend)
|
||||
assert isinstance(loader, expected_loader_cls), (
|
||||
f"{model_repo!r}: backend={backend!r} loaded "
|
||||
@@ -1693,7 +1700,9 @@ def test_glm5next_backend_codec_parity(tmp_path, backend):
|
||||
path = _write_gray_video(tmp_path, total_frames, fps)
|
||||
# Dense default sampling (gap 5) and a sparse max_frames cap (gap 20).
|
||||
for max_frames in (None, 6):
|
||||
kwargs = {} if max_frames is None else {"max_frames": max_frames}
|
||||
kwargs: dict[str, Any] = (
|
||||
{} if max_frames is None else {"max_frames": max_frames}
|
||||
)
|
||||
expected = glm_sample_frame_indices(
|
||||
total_frames, float(fps), 12.0, max_frame_count=max_frames
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user