fix: guarantee length preservation in _ActivationWithGAFilter
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user