Skip to content

Commit

Permalink
Fixing bug facebookresearch#374, issue in pad1d
Browse files Browse the repository at this point in the history
  • Loading branch information
adefossez committed Sep 29, 2022
1 parent ca8fd91 commit bd98f01
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion demucs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.

__version__ = "3.0.6a1"
__version__ = "3.0.6a2"
12 changes: 10 additions & 2 deletions demucs/hdemucs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@
def pad1d(x: torch.Tensor, paddings: tp.Tuple[int, int], mode: str = 'constant', value: float = 0.):
"""Tiny wrapper around F.pad, just to allow for reflect padding on small input.
If this is the case, we insert extra 0 padding to the right before the reflection happen."""
x0 = x
length = x.shape[-1]
padding_left, padding_right = paddings
if mode == 'reflect':
max_pad = max(padding_left, padding_right)
if length <= max_pad:
x = F.pad(x, (0, max_pad - length + 1))
return F.pad(x, paddings, mode, value)
extra_pad = max_pad - length + 1
extra_pad_right = min(padding_right, extra_pad)
extra_pad_left = extra_pad - extra_pad_right
paddings = (padding_left - extra_pad_left, padding_right - extra_pad_right)
x = F.pad(x, (extra_pad_left, extra_pad_right))
out = F.pad(x, paddings, mode, value)
assert out.shape[-1] == length + padding_left + padding_right
assert (out[..., padding_left: padding_left + length] == x0).all()
return out


class ScaledEmbedding(nn.Module):
Expand Down
6 changes: 6 additions & 0 deletions docs/release.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release notes for Demucs

## V3.0.6a, TBC

Option to customize output path of stems (@CarlGao4)

Fixed bug in pad1d leading to failure sometimes.

## V3.0.5, 17th of August 2022

Added `--segment` flag to customize the segment length and use less memory (thanks @CarlGao4).
Expand Down

0 comments on commit bd98f01

Please sign in to comment.