Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion components/src/dynamo/common/multimodal/audio_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import numpy as np

from dynamo.common.http import HttpStatusError, fetch_bytes
from dynamo.common.http.media_reference import max_media_bytes
from dynamo.common.http.url_validator import (
UrlValidationError,
UrlValidationPolicy,
Expand Down Expand Up @@ -128,7 +129,10 @@ async def _load_audio_with_vllm(self, audio_url: str) -> tuple[np.ndarray, float
# data: and file:// never touch the network, so vLLM can handle them.
if urlparse(normalized_url).scheme in ("http", "https"):
content = await fetch_bytes(
normalized_url, self._http_timeout, policy=self._url_policy
normalized_url,
self._http_timeout,
policy=self._url_policy,
max_bytes=max_media_bytes(),
Comment thread
host452b marked this conversation as resolved.
Resolved
)
return await asyncio.to_thread(media_io.load_bytes, content)

Expand Down
6 changes: 5 additions & 1 deletion components/src/dynamo/common/multimodal/image_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
HttpTimeoutError,
fetch_bytes,
)
from ..http.media_reference import max_media_bytes
from ..http.url_validator import (
UrlValidationError,
UrlValidationPolicy,
Expand Down Expand Up @@ -135,7 +136,10 @@ async def _fetch_and_process(self, image_url: str) -> Image.Image:
try:
with _nvtx.annotate("mm:img:http_fetch", color="lime"):
content = await fetch_bytes(
image_url, self._http_timeout, policy=self._url_policy
image_url,
self._http_timeout,
policy=self._url_policy,
max_bytes=max_media_bytes(),
Comment thread
host452b marked this conversation as resolved.
Resolved
)
if not content:
raise ValueError("Empty response content from image URL")
Expand Down
6 changes: 5 additions & 1 deletion components/src/dynamo/common/multimodal/video_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import numpy as np

from dynamo.common.http import HttpStatusError, fetch_bytes
from dynamo.common.http.media_reference import max_media_bytes
from dynamo.common.http.url_validator import (
UrlValidationError,
UrlValidationPolicy,
Expand Down Expand Up @@ -171,7 +172,10 @@ async def _load_video_with_vllm(
# data: and file:// never touch the network, so vLLM can handle them.
if urlparse(normalized_url).scheme in ("http", "https"):
content = await fetch_bytes(
normalized_url, self._http_timeout, policy=self._url_policy
normalized_url,
self._http_timeout,
policy=self._url_policy,
max_bytes=max_media_bytes(),
Comment thread
host452b marked this conversation as resolved.
Resolved
Comment thread
host452b marked this conversation as resolved.
Resolved
)
return await self._decode_video_bytes(content, media_io)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ async def test_load_audio_rejects_empty_waveform():
await loader.load_audio("https://example.com/empty.wav")


@pytest.mark.asyncio
async def test_http_fetch_honors_configured_media_limit(monkeypatch):
monkeypatch.setenv("DYN_MM_MAX_FILE_SIZE_MB", "1")
Comment thread
host452b marked this conversation as resolved.
Resolved
loader = AudioLoader(url_policy=_permissive_http_policy())
waveform = np.zeros(8, dtype=np.float32)

class _MediaIO:
def load_bytes(self, content):
return waveform, 16000.0

mock_fetch = AsyncMock(return_value=b"audio")
monkeypatch.setattr(audio_loader_module, "fetch_bytes", mock_fetch)
monkeypatch.setattr(loader, "_create_vllm_audio_io", lambda: _MediaIO())

await loader._load_audio_with_vllm("https://example.com/limited.wav")

assert mock_fetch.await_args.kwargs["max_bytes"] == 1024 * 1024


@pytest.mark.asyncio
async def test_load_audio_batch_uses_url_loader():
loader = AudioLoader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _mock_fetch_bytes(
side_effect: If set, the mock raises this exception instead of returning.
"""

async def _fetch(url, timeout, *, policy=None):
async def _fetch(url, timeout, *, policy=None, max_bytes=None):
if delay > 0:
await asyncio.sleep(delay)
if side_effect is not None:
Expand Down Expand Up @@ -207,6 +207,18 @@ async def test_http_timeout_raises_408(loader: ImageLoader) -> None:
assert "https://example.com/img.png" in exc_info.value.url


async def test_http_fetch_honors_configured_media_limit(
loader: ImageLoader, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv("DYN_MM_MAX_FILE_SIZE_MB", "1")
mock_fetch = _mock_fetch_bytes()

with patch(_FETCH_BYTES_PATH, mock_fetch):
await loader.load_image("https://example.com/limited.png")

assert mock_fetch.await_args.kwargs["max_bytes"] == 1024 * 1024


async def test_http_connection_error_raises_400(loader: ImageLoader) -> None:
"""An unreachable user-supplied URL is a client error, so the
frontend must surface 400 instead of an opaque 500."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ async def test_load_video_uses_vllm_media_connector():
assert loaded_metadata == metadata


@pytest.mark.asyncio
async def test_http_fetch_honors_configured_media_limit(monkeypatch):
monkeypatch.setenv("DYN_MM_MAX_FILE_SIZE_MB", "1")
loader = VideoLoader(
url_policy=UrlValidationPolicy(allow_http=True, allow_private_ips=True)
)
frames = np.zeros((1, 2, 2, 3), dtype=np.uint8)
metadata = {"fps": 1.0, "frames_indices": [0], "total_num_frames": 1}
mock_fetch = AsyncMock(return_value=b"video")
mock_decode = AsyncMock(return_value=(frames, metadata))
monkeypatch.setattr(video_loader_module, "fetch_bytes", mock_fetch)
monkeypatch.setattr(loader, "_create_vllm_video_io", lambda kwargs=None: object())
monkeypatch.setattr(loader, "_decode_video_bytes", mock_decode)

await loader._load_video_with_vllm("https://example.com/limited.mp4")

assert mock_fetch.await_args.kwargs["max_bytes"] == 1024 * 1024


@pytest.mark.asyncio
async def test_load_video_batch_uses_url_loader():
loader = VideoLoader()
Expand Down
Loading