Extract shared runner I/O utilities#384
Conversation
Add flashdreams.infra.runner_io for common prompt resolution, output paths, stats JSON, image/video loading, normalization, and MP4 writing with lazy cv2/mediapy imports. Migrate matching public runners to use the shared helpers while preserving model-specific download, crop, camera, and writer behavior. Add CPU tests for the new helper contracts.
Greptile SummaryThis PR extracts a new
Confidence Score: 5/5Safe to merge — the extraction is a straightforward refactor that removes duplicated I/O helpers without altering any model-specific logic, download, crop, or camera behaviour. All eight migrated runners preserve their original tensor layouts, interpolation modes, dtype placement, and file-naming conventions. The previous concerns about assert-based validation, missing .cpu() calls on CUDA tensors, and the untested thwc layout branch are all addressed in this PR. No regressions were found during cross-referencing of old and new code paths. No files require special attention. Important Files Changed
Reviews (5): Last reviewed commit: "Migrate remaining runners to shared runn..." | Re-trigger Greptile |
Make prompt validation explicit, move video tensors to CPU before NumPy conversion, reuse the shared runner install hint in OmniDreams, and add coverage for empty prompts and THWC video conversion.
Replace remaining assert-based runner I/O guards with explicit ValueError checks so invalid empty-video and multi-batch BCTHW inputs fail reliably under optimized Python. Add focused tests for both validation paths.
|
/ok to test 101de2c |
Use setattr when monkeypatching fake media and cv2 modules in the runner I/O tests so ty does not flag unresolved ModuleType attributes. Also apply Ruff formatting to the OmniDreams runner.
|
/ok to test 880d96d |
Add shared helpers for cached input-asset resolution and lazy video FPS probing, then migrate public runner call sites to use them directly. This removes duplicated local/URL path resolution from Wan, Causal Forcing, Cosmos Predict2, and FlashVSR, moves FlashVSR video loading and metadata probing onto shared runner I/O, and routes the remaining simple runner output path creation through the shared helpers.
|
/ok to test e7688b4 |
| """Write a ``[-1, 1]`` video tensor as an MP4 and return the path.""" | ||
| media = _import_mediapy("Writing videos", install_hint=install_hint) | ||
| path = Path(path) | ||
| media.write_video(str(path), video_tensor_to_uint8(video, layout=layout), fps=fps) |
There was a problem hiding this comment.
Not for this PR, but we should provide a stream_video_tensor_to_file function to avoid OOM for long video output by appending the tensor to the output during the rollout, rather than dumping in the end at once.
| resolve_prompt_value, | ||
| runner_artifact_path, | ||
| write_runner_stats, | ||
| write_video_tensor, |
There was a problem hiding this comment.
nit: instead of importing all the functions, maybe better organize them in a single class?
gtong-nv
left a comment
There was a problem hiding this comment.
LGTM.
Left a few comments but OK to address in the future.
|
Thanks for the comments. I have added them to my TODO list. |
Extract shared runner I/O utilities
Add flashdreams.infra.runner_io for common prompt resolution, output paths,
stats JSON, image/video loading, normalization, and MP4 writing with lazy
cv2/mediapy imports.
Migrate matching public runners to use the shared helpers while preserving
model-specific download, crop, camera, and writer behavior. Add CPU tests for
the new helper contracts.