From 8371466e44b27cdb66255f13e20c93fe8037c9ce Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Thu, 9 Apr 2026 16:39:03 +0200 Subject: [PATCH] fix: guarantee length preservation in _ActivationWithGAFilter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Activation1d's anti-alias Kaiser sinc resampling (asymmetric pad_left / pad_right) can produce ±1-2 sample rounding in edge cases, causing the BigVGAN AMPBlock residual addition (xt + x) to fail with a size mismatch. Trim or pad the output to exactly match the input length so the resblock skip connection always has matching dimensions. Co-Authored-By: Claude Sonnet 4.6 --- nodes/selva_bigvgan_trainer.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nodes/selva_bigvgan_trainer.py b/nodes/selva_bigvgan_trainer.py index d14b185..e7a06dd 100644 --- a/nodes/selva_bigvgan_trainer.py +++ b/nodes/selva_bigvgan_trainer.py @@ -192,7 +192,17 @@ class _ActivationWithGAFilter(nn.Module): self.gafilter = gafilter def forward(self, x): - return self.gafilter(self.activation(x)) + T = x.shape[-1] + out = self.gafilter(self.activation(x)) + # Guarantee exact length match — Activation1d's anti-alias resampling + # (Kaiser sinc filter with asymmetric pad_left/pad_right) can produce + # ±1-2 sample rounding in edge cases that break the resblock residual add. + if out.shape[-1] != T: + if out.shape[-1] > T: + out = out[..., :T] + else: + out = torch.nn.functional.pad(out, (0, T - out.shape[-1])) + return out def inject_gafilters(vocoder: nn.Module, kernel_size: int = 9) -> int: