Compare commits

...
Author SHA1 Message Date
david6666666 2aac8bd15a [Bugfix][MiniMax-H3] Isolate keyframe VAE encoding from tile collectives
Signed-off-by: david6666666 <530634352@qq.com>
2026-09-17 08:23:37 +00:00
david6666666 7a2a16f8af [Bugfix][MiniMax-H3] Keep keyframe VAE encoding rank-local
Signed-off-by: david6666666 <530634352@qq.com>
2026-09-17 01:56:36 +00:00
2 changed files with 23 additions and 4 deletions

No files matched your search

@@ -2811,6 +2811,17 @@ def test_keyframe_encode_enters_backend_context(monkeypatch, fail_encode):
finally:
events.append("exit")
@contextmanager
def track_rank_local():
assert video_vae.model.parallel_tiling
video_vae.model.parallel_tiling = False
events.append("rank-local-enter")
try:
yield
finally:
video_vae.model.parallel_tiling = True
events.append("rank-local-exit")
class FakeModel(torch.nn.Module):
def __init__(self):
super().__init__()
@@ -2818,9 +2829,10 @@ def test_keyframe_encode_enters_backend_context(monkeypatch, fail_encode):
self.parallel_tiling = True
def encode_images(self, image, *, use_fp16_latent):
assert events == ["enter"]
assert events == ["rank-local-enter", "enter"]
assert image is input_image
assert use_fp16_latent
assert not self.parallel_tiling
events.append("encode")
if fail_encode:
raise RuntimeError("encode failed")
@@ -2834,6 +2846,8 @@ def test_keyframe_encode_enters_backend_context(monkeypatch, fail_encode):
"latents_mean": [0.0],
"latents_std": [1.0],
}
video_vae.parallel_size = 4
monkeypatch.setattr(video_vae, "_rank_local_tiling", track_rank_local)
monkeypatch.setattr(vae_module, "_minimax_h3_keyframe_encode_context", track_context)
if fail_encode:
@@ -2843,7 +2857,7 @@ def test_keyframe_encode_enters_backend_context(monkeypatch, fail_encode):
rows = video_vae.encode_image(input_image)
torch.testing.assert_close(rows, torch.ones(1, 4))
assert events == ["enter", "encode", "exit"]
assert events == ["rank-local-enter", "enter", "encode", "exit", "rank-local-exit"]
assert video_vae.model.parallel_tiling
+7 -2
View File
@@ -602,8 +602,13 @@ class MiniMaxH3VideoVAE(nn.Module, DistributedVaeMixin):
if getattr(self, "decode_only", False):
raise RuntimeError("MiniMax H3 decode-only video VAE cannot encode images")
previous_parallel = self.model.parallel_tiling
if int(getattr(self, "parallel_size", 1)) <= 1:
parallel_size = int(getattr(self, "parallel_size", 1))
if parallel_size <= 1:
self.model.parallel_tiling = False
# A keyframe is a single-image conditioning input. Do not let it use
# the multi-rank tiled-VAE collective, whose reduction order depends
# on the physical GPU topology; video references keep tile parallelism.
tiling_context = self._rank_local_tiling() if parallel_size > 1 else nullcontext()
parameter = next(self.parameters())
previous_dtype = parameter.dtype
if previous_dtype != torch.float32:
@@ -611,7 +616,7 @@ class MiniMaxH3VideoVAE(nn.Module, DistributedVaeMixin):
devices = [parameter.device] if parameter.device.type != "cpu" else []
try:
with (
self._encoder_tiling_context(image.height, image.width),
tiling_context,
torch.random.fork_rng(
devices=devices,
device_type=parameter.device.type,