Repository navigation
[bugfix] Fix MPS worker handoff and named Studio image downloads #1847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leo2ultimate
wants to merge
11
commits into
hao-ai-lab:main
Choose a base branch
from
leo2ultimate:fix/mps-worker-result-serialization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+566
−36
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a42bacb
[bugfix] Serialize MPS worker results through CPU storage
leo2ultimate 1df47ac
[refactor] Branch explicitly for MPS response transport
leo2ultimate 08b4dea
[refactor] Simplify MPS response copying
leo2ultimate 3e41e83
[test] Trim overlapping MPS transport cases
leo2ultimate f29239d
[misc]: Address Greptile P2 comment nit
aryan5v 2995f99
[bugfix] Use generated output paths for named Studio jobs
leo2ultimate 304e043
[bugfix] Keep Studio image names in PNG format
leo2ultimate 754dbf9
[bugfix] Preserve generated media formats throughout Studio
leo2ultimate cd81d35
[bugfix] Fix WebP MIME lookup and isolate transport tests
leo2ultimate cfc0740
[test] Cover CUDA worker pipe round trips
leo2ultimate 8737f1b
[test] Close Studio fixture managers after each test
leo2ultimate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Studio records and serves the artifact actually saved by the generator.""" | ||
|
|
||
| import io | ||
| import mimetypes | ||
| from pathlib import Path | ||
| from types import SimpleNamespace | ||
| import uuid | ||
|
|
||
| from fastapi.testclient import TestClient | ||
| from PIL import Image | ||
| import pytest | ||
|
|
||
| from fastvideo.entrypoints.video_generator import VideoGenerator | ||
| from fastvideo_studio import server | ||
| from fastvideo_studio.database import Database | ||
| from fastvideo_studio.job_runner import JobRunner, JobStatus | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def builtin_mime_types_only(monkeypatch): | ||
| mime_types = mimetypes.MimeTypes(filenames=()) | ||
| monkeypatch.setattr(mimetypes, "guess_type", mime_types.guess_type) | ||
| monkeypatch.setattr("starlette.responses.guess_type", mime_types.guess_type) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def runner(tmp_path): | ||
| instance = JobRunner( | ||
| output_dir=str(tmp_path / "outputs"), | ||
| log_dir=str(tmp_path / "logs"), | ||
| database=Database(tmp_path / "studio.db"), | ||
| ) | ||
| try: | ||
| yield instance | ||
| finally: | ||
| instance._shutdown() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("workload, name, output_name, media_type", [ | ||
| ("t2i", "MPS handoff test", "MPS handoff test.png", "image/png"), | ||
| ("t2i", "portrait.jpg", "portrait.jpg", "image/jpeg"), | ||
| ("t2i", "portrait.jpeg", "portrait.jpeg", "image/jpeg"), | ||
| ("t2i", "portrait.webp", "portrait.webp", "image/webp"), | ||
| ("t2v", "MPS handoff test", "MPS handoff test.mp4", "video/mp4"), | ||
| ]) | ||
| def test_named_job_serves_generated_artifact(runner, monkeypatch, workload, name, output_name, media_type): | ||
| job = runner.create_job( | ||
| job_id=str(uuid.uuid4()), | ||
| model_id="test/model", | ||
| name=name, | ||
| prompt="a red dinosaur", | ||
| workload_type=workload, | ||
| ) | ||
| output_dir = Path(runner.output_dir) / job.id | ||
| output_dir.mkdir() | ||
| # Old artifacts and directories with media suffixes must not win discovery. | ||
| (output_dir / "000-old.mp4").mkdir() | ||
| (output_dir / "001-old.mp4").write_bytes(b"old video") | ||
| path_context = SimpleNamespace( | ||
| _is_image_workload=lambda: workload == "t2i", | ||
| _is_audio_workload=lambda: False, | ||
| ) | ||
|
|
||
| def generate_video(**kwargs): | ||
| # Use the real filename/extension selection, replacing only model work. | ||
| output = Path(VideoGenerator._prepare_output_path( | ||
| path_context, | ||
| kwargs["output_path"], | ||
| kwargs["prompt"], | ||
| output_video_name=kwargs.get("output_video_name"), | ||
| )) | ||
| if workload == "t2i": | ||
| Image.new("RGB", (8, 8), "red").save(output) | ||
| else: | ||
| output.write_bytes(b"generated video fixture") | ||
| return {"video_path": str(output)} | ||
|
|
||
| monkeypatch.setattr(runner, "_get_or_create_generator", | ||
| lambda *args, **kwargs: SimpleNamespace(generate_video=generate_video)) | ||
| runner._run_inference_job(job) | ||
|
|
||
| expected = output_dir / output_name | ||
| assert job.status == JobStatus.COMPLETED, job.error | ||
| assert job.output_path == str(expected) | ||
| assert expected.is_file() | ||
| assert runner._db.get_job(job.id)["output_path"] == str(expected) | ||
| monkeypatch.setattr(server, "job_runner", runner, raising=False) | ||
| with TestClient(server.app) as client: | ||
| response = client.get(f"/api/jobs/{job.id}/video") | ||
| assert response.status_code == 200 | ||
| assert response.headers["content-type"] == media_type | ||
| assert response.content == expected.read_bytes() | ||
| if workload == "t2i": | ||
| with Image.open(io.BytesIO(response.content)) as image: | ||
| image.load() | ||
| assert Image.MIME[image.format] == media_type | ||
| assert image.size == (8, 8) | ||
|
|
||
|
|
||
| def test_directory_returned_as_output_fails_job(runner, monkeypatch): | ||
| job = runner.create_job(job_id=str(uuid.uuid4()), model_id="test/model", prompt="test") | ||
| directory = Path(runner.output_dir) / job.id / "not-a-video.mp4" | ||
| directory.mkdir(parents=True) | ||
| generator = SimpleNamespace(generate_video=lambda **kwargs: {"video_path": str(directory)}) | ||
| monkeypatch.setattr(runner, "_get_or_create_generator", lambda *args, **kwargs: generator) | ||
|
|
||
| runner._run_inference_job(job) | ||
|
|
||
| assert job.status == JobStatus.FAILED | ||
| assert job.output_path is None | ||
| assert job.error | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.