-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #320 from Maggione/main
mmspeech merge
- Loading branch information
Showing
16 changed files
with
1,056 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
import math | ||
import torch.nn.functional as F | ||
|
||
|
||
def pad_to_multiple(x, multiple, dim=-1, value=0): | ||
# Inspired from https://github.com/lucidrains/local-attention/blob/master/local_attention/local_attention.py#L41 | ||
if x is None: | ||
return None, 0 | ||
tsz = x.size(dim) | ||
m = tsz / multiple | ||
remainder = math.ceil(m) * multiple - tsz | ||
if m.is_integer(): | ||
return x, 0 | ||
pad_offset = (0,) * (-1 - dim) * 2 | ||
|
||
return F.pad(x, (*pad_offset, 0, remainder), value=value), remainder |
Oops, something went wrong.