Skip to content

Commit 17f3a91

Browse files
committed
[misc] Address review: CI registration, generation-level contracts, quality trade-off docs
1 parent d0bd3ba commit 17f3a91

4 files changed

Lines changed: 189 additions & 2 deletions

File tree

.github/workflows/ci-macos-mlx.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ jobs:
8686
fastvideo/tests/mlx/test_mlx_minimax_h3_vsa.py \
8787
fastvideo/tests/mlx/test_mlx_minimax_h3_vsa_regressions.py \
8888
fastvideo/tests/mlx/test_mlx_minimax_h3_fast_mode.py \
89+
fastvideo/tests/mlx/test_mlx_minimax_h3_fast_spatial.py \
8990
fastvideo/tests/mlx/test_mlx_fastwan_benchmark.py \
9091
fastvideo/tests/mlx/test_taehv_decode.py \
9192
fastvideo/tests/mlx/test_frame_upsample.py \
@@ -149,6 +150,7 @@ jobs:
149150
fastvideo/tests/mlx/test_mlx_minimax_h3_vsa.py \
150151
fastvideo/tests/mlx/test_mlx_minimax_h3_vsa_regressions.py \
151152
fastvideo/tests/mlx/test_mlx_minimax_h3_fast_mode.py \
153+
fastvideo/tests/mlx/test_mlx_minimax_h3_fast_spatial.py \
152154
fastvideo/tests/mlx/test_mlx_fastwan_benchmark.py \
153155
fastvideo/tests/mlx/test_taehv_decode.py \
154156
fastvideo/tests/mlx/test_frame_upsample.py \

docs/getting_started/installation/mps.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ Add `--fast-spatial` for spatial fast mode, `--fast`'s spatial twin. It
196196
denoises and decodes on the smallest 32px-aligned canvas covering the
197197
requested size divided by `--fast-spatial-scale` (a 480x832 request runs on a
198198
256x416 canvas), then resamples the decoded frames up to the requested size
199-
in pixel space. It composes with `--fast`:
199+
in pixel space. It composes with `--fast`. This is a speed/quality trade-off
200+
and stays off by default: the output carries the reduced canvas's detail
201+
budget, so it reads softer than a native-resolution render, with the unsharp
202+
pass countering some but not all of the difference:
200203

201204
```bash
202205
python examples/inference/basic/mlx_fasth3.py \

examples/inference/basic/mlx_fasth3.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
denoises and decodes on the smallest 32px-aligned canvas covering
2424
height/width divided by ``--fast-spatial-scale``, then resamples the decoded
2525
frames up to the requested size in pixel space. The two modes compose.
26+
This trades fine detail for speed: the output carries the reduced canvas's
27+
detail budget and reads softer than a native-resolution render, so it stays
28+
off by default.
2629
2730
This entrypoint currently supports text-to-video-with-audio only. It does not
2831
yet wire FL2VA, Ref2VA, or two-pass refinement.
@@ -81,7 +84,8 @@ def parse_args() -> argparse.Namespace:
8184
action=argparse.BooleanOptionalAction,
8285
default=False,
8386
help="denoise and decode at height/width // fast-spatial-scale on H3's 32px grid, "
84-
"then resample the decoded frames up to the requested size; composes with --fast",
87+
"then resample the decoded frames up to the requested size; composes with --fast. "
88+
"Trades fine detail for speed",
8589
)
8690
parser.add_argument("--fast-spatial-scale", type=int, default=2,
8791
help="spatial reduction factor for --fast-spatial (default: 2)")

fastvideo/tests/mlx/test_mlx_minimax_h3_fast_spatial.py

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33

44
from __future__ import annotations
55

6+
from pathlib import Path
7+
68
import numpy as np
79
import pytest
810

911
pytest.importorskip("mlx.core", reason="MLX is required for MiniMax H3 fast-spatial tests")
1012

13+
from fastvideo.mlx_runtime import rife_interp # noqa: E402
1114
from fastvideo.mlx_runtime.frame_upsample import upsample_frames # noqa: E402
15+
from fastvideo.mlx_runtime.minimax_h3 import ( # noqa: E402
16+
build_packed_layout,
17+
video_latent_num_frames,
18+
)
1219
from fastvideo.mlx_runtime.minimax_h3_pipeline import ( # noqa: E402
20+
DEFAULT_FAST_SPATIAL_SHARPEN,
21+
MiniMaxH3MLXPipeline,
1322
_center_crop_frames,
1423
_preflight_media_dependencies,
1524
plan_fast_spatial,
@@ -71,3 +80,172 @@ def test_spatial_crop_then_upsample_restores_exact_target_size() -> None:
7180
upsampled = upsample_frames(cropped, width=plan.target_width, height=plan.target_height,
7281
mode="bilinear", sharpen=0.0)
7382
assert np.stack(upsampled).shape == (2, 480, 832, 3)
83+
84+
85+
# -- generation-level orchestration contracts (heavyweight phases mocked) ----
86+
87+
88+
def _generate_with_mocked_phases(monkeypatch, tmp_path, **generate_kwargs):
89+
"""Run real ``generate()`` orchestration with condition/denoise/decode/mux stubbed."""
90+
events: list[str] = []
91+
calls: dict = {}
92+
93+
pipeline = MiniMaxH3MLXPipeline.__new__(MiniMaxH3MLXPipeline)
94+
pipeline.dit_checkpoint = tmp_path
95+
96+
monkeypatch.setattr("fastvideo.mlx_runtime.minimax_h3_pipeline._validate_checkpoint_step_ladder",
97+
lambda _checkpoint, _steps: None)
98+
monkeypatch.setattr("fastvideo.mlx_runtime.minimax_h3_pipeline._preflight_media_dependencies",
99+
lambda **_kwargs: None)
100+
monkeypatch.setattr("fastvideo.mlx_runtime.minimax_h3_pipeline.mlx_h3_checkpoint_vsa_capable",
101+
lambda _checkpoint: False)
102+
103+
def fake_encode_prompt(_prompt):
104+
return np.zeros((8, 8), dtype=np.float32), np.zeros(8, dtype=np.int64)
105+
106+
def fake_denoise(_text_rows, _token_tags, **kwargs):
107+
events.append("denoise")
108+
calls["denoise"] = kwargs
109+
return np.zeros((4, 4), dtype=np.float32), np.zeros((4, 4), dtype=np.float32)
110+
111+
def fake_decode_video(_rows, *, height, width, num_frames, tiled):
112+
events.append("decode_video")
113+
calls["decode_video"] = {"height": height, "width": width, "num_frames": num_frames}
114+
return np.zeros((num_frames, height, width, 3), dtype=np.uint8)
115+
116+
def fake_decode_audio(_rows, *, num_frames):
117+
events.append("decode_audio")
118+
calls["decode_audio"] = {"num_frames": num_frames}
119+
return np.zeros((2, 64), dtype=np.float32)
120+
121+
pipeline.encode_prompt = fake_encode_prompt
122+
pipeline.denoise = fake_denoise
123+
pipeline.decode_video = fake_decode_video
124+
pipeline.decode_audio = fake_decode_audio
125+
pipeline.mux = lambda _frames, _waveform, output_path: Path(output_path)
126+
127+
def fake_interpolate(frames, target, *, model):
128+
events.append("rife")
129+
calls["rife"] = {"target": target}
130+
return [np.array(frames[0]) for _ in range(target)]
131+
132+
def fake_load_model(weights_dir=None):
133+
return object()
134+
135+
fake_load_model.cache_clear = lambda: None
136+
monkeypatch.setattr(rife_interp, "interpolate_to_frame_count", fake_interpolate)
137+
monkeypatch.setattr(rife_interp, "load_model", fake_load_model)
138+
139+
def fake_sharpen(frames, amount):
140+
events.append("sharpen")
141+
calls.setdefault("sharpen", []).append(amount)
142+
return list(frames)
143+
144+
def fake_upsample(frames, *, width, height, mode, sharpen):
145+
events.append("upsample")
146+
calls["upsample"] = {"width": width, "height": height, "mode": mode, "sharpen": sharpen}
147+
return [np.zeros((height, width, 3), dtype=np.uint8) for _ in frames]
148+
149+
monkeypatch.setattr("fastvideo.mlx_runtime.minimax_h3_pipeline._sharpen_frames", fake_sharpen)
150+
monkeypatch.setattr("fastvideo.mlx_runtime.minimax_h3_pipeline.upsample_frames", fake_upsample)
151+
152+
result = pipeline.generate(
153+
"(S1) test prompt",
154+
output_path=tmp_path / "out.mp4",
155+
height=480,
156+
width=832,
157+
num_frames=124,
158+
save_frames=True,
159+
**generate_kwargs,
160+
)
161+
return events, calls, result
162+
163+
164+
def test_generate_spatial_only_denoises_reduced_canvas_with_full_audio(
165+
monkeypatch: pytest.MonkeyPatch, tmp_path) -> None:
166+
events, calls, result = _generate_with_mocked_phases(monkeypatch, tmp_path, fast_spatial=True)
167+
168+
assert calls["denoise"]["height"] == 256
169+
assert calls["denoise"]["width"] == 416
170+
assert calls["denoise"]["num_frames"] == 124
171+
assert calls["denoise"]["audio_num_frames"] is None
172+
assert calls["denoise"]["video_temporal_scale"] == 1.0
173+
assert calls["decode_video"] == {"height": 256, "width": 416, "num_frames": 124}
174+
assert calls["decode_audio"] == {"num_frames": 124}
175+
assert calls["upsample"] == {
176+
"width": 832, "height": 480, "mode": "lanczos",
177+
"sharpen": pytest.approx(DEFAULT_FAST_SPATIAL_SHARPEN),
178+
}
179+
assert "rife" not in events
180+
assert "sharpen" not in events
181+
assert result.frames.shape == (124, 480, 832, 3)
182+
assert "spatial_upsample_s" in result.timings
183+
184+
185+
def test_generate_temporal_only_control_keeps_full_canvas(monkeypatch: pytest.MonkeyPatch, tmp_path) -> None:
186+
events, calls, result = _generate_with_mocked_phases(monkeypatch, tmp_path, fast=True)
187+
188+
assert calls["denoise"]["height"] == 480
189+
assert calls["denoise"]["width"] == 832
190+
assert calls["denoise"]["num_frames"] == 73
191+
assert calls["denoise"]["audio_num_frames"] == 124
192+
assert calls["denoise"]["video_temporal_scale"] > 1.0
193+
assert calls["decode_video"] == {"height": 480, "width": 832, "num_frames": 73}
194+
assert calls["rife"] == {"target": 124}
195+
assert calls["decode_audio"] == {"num_frames": 124}
196+
assert calls["sharpen"] == [pytest.approx(0.6)]
197+
assert "upsample" not in events
198+
assert result.frames.shape == (124, 480, 832, 3)
199+
200+
201+
def test_generate_stacked_runs_rife_before_upsample_with_one_sharpen(
202+
monkeypatch: pytest.MonkeyPatch, tmp_path) -> None:
203+
events, calls, result = _generate_with_mocked_phases(monkeypatch, tmp_path, fast=True, fast_spatial=True)
204+
205+
assert calls["denoise"]["height"] == 256
206+
assert calls["denoise"]["width"] == 416
207+
assert calls["denoise"]["num_frames"] == 73
208+
assert calls["denoise"]["audio_num_frames"] == 124
209+
assert calls["decode_video"] == {"height": 256, "width": 416, "num_frames": 73}
210+
assert calls["rife"] == {"target": 124}
211+
assert events.index("rife") < events.index("upsample")
212+
assert "sharpen" not in events
213+
assert calls["upsample"]["sharpen"] == pytest.approx(0.6)
214+
assert calls["decode_audio"] == {"num_frames": 124}
215+
assert result.frames.shape == (124, 480, 832, 3)
216+
217+
218+
# -- reduced VSA layout contracts --------------------------------------------
219+
220+
221+
def test_reduced_layout_has_8x13_video_grid_and_unchanged_audio_prefix() -> None:
222+
reduced = build_packed_layout(8, 37, 16, 26, 207)
223+
full = build_packed_layout(8, 37, 30, 52, 207)
224+
225+
assert reduced.video_indices.shape[0] == 37 * 8 * 13
226+
assert full.video_indices.shape[0] == 37 * 15 * 26
227+
np.testing.assert_array_equal(reduced.audio_indices, full.audio_indices)
228+
# A/V sync rides on the audio rows' temporal positions (column 0), which
229+
# must not move with the canvas. Column 2 is excluded on purpose: audio
230+
# rows borrow the video width grid's edge coordinates for their spatial
231+
# tag, so it tracks the canvas the same way any native resolution change
232+
# does.
233+
np.testing.assert_array_equal(
234+
reduced.position_ids[reduced.audio_indices, 0],
235+
full.position_ids[full.audio_indices, 0],
236+
)
237+
np.testing.assert_array_equal(reduced.position_ids[reduced.audio_indices, 1],
238+
np.zeros(reduced.audio_indices.shape[0]))
239+
240+
241+
def test_reduced_layout_stacked_uses_22_latent_frames() -> None:
242+
assert video_latent_num_frames(73) == 22
243+
stacked = build_packed_layout(8, 22, 16, 26, 207, video_temporal_scale=1.7)
244+
baseline = build_packed_layout(8, 22, 16, 26, 207)
245+
246+
assert stacked.video_indices.shape[0] == 22 * 8 * 13
247+
np.testing.assert_array_equal(stacked.audio_indices, baseline.audio_indices)
248+
np.testing.assert_array_equal(
249+
stacked.position_ids[stacked.audio_indices],
250+
baseline.position_ids[baseline.audio_indices],
251+
)

0 commit comments

Comments
 (0)