[Bugfix][MiniMax-H3] Stabilize keyframe VAE encoding (#7191)
Signed-off-by: david6666666 <530634352@qq.com> Signed-off-by: David Chen <530634352@qq.com>
This commit is contained in:
1 parent
4b96c57730
commit
30d6a0b4e6
2 files changed
+118
-4
No files matched your search
@@ -38,6 +38,27 @@ MINIMAX_H3_AUDIO_CHANNELS = 2
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def _minimax_h3_keyframe_encode_context(
|
||||
device: torch.device,
|
||||
) -> Iterator[None]:
|
||||
if device.type != "cuda":
|
||||
yield
|
||||
return
|
||||
|
||||
# The official keyframe latent uses cuDNN's TF32 convolution path. The
|
||||
# default non-deterministic algorithm can select numerically different
|
||||
# reductions on H100s, and the difference is amplified by the denoiser.
|
||||
# Pin both the algorithm and math mode for this sensitive encode only.
|
||||
with torch.backends.cudnn.flags(
|
||||
enabled=True,
|
||||
benchmark=False,
|
||||
deterministic=True,
|
||||
allow_tf32=True,
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
def _load_component_config(component_path: str) -> dict[str, Any]:
|
||||
config_path = Path(component_path) / "config.json"
|
||||
config = json.loads(config_path.read_text(encoding="utf-8"))
|
||||
@@ -280,10 +301,11 @@ class MiniMaxH3VideoVAE(nn.Module, DistributedVaeMixin):
|
||||
for device in devices:
|
||||
with self.device_module.device(device):
|
||||
self.device_module.manual_seed(MINIMAX_H3_KEYFRAME_ENCODE_SEED)
|
||||
latent = self.model.encode_images(
|
||||
image,
|
||||
use_fp16_latent=True,
|
||||
)[0]
|
||||
with _minimax_h3_keyframe_encode_context(parameter.device):
|
||||
latent = self.model.encode_images(
|
||||
image,
|
||||
use_fp16_latent=True,
|
||||
)[0]
|
||||
finally:
|
||||
self.model.parallel_tiling = previous_parallel
|
||||
if previous_dtype != torch.float32:
|
||||
|
||||
Reference in new issue
Block a user