mirror of
https://github.com/k2-fsa/icefall.git
synced 2025-12-11 06:55:27 +00:00
from local
This commit is contained in:
parent
8fab7905b8
commit
52ae2ba762
Binary file not shown.
17
egs/LJSpeech/ASR/pruned_transducer_stateless_d2v_v2/utils.py
Normal file
17
egs/LJSpeech/ASR/pruned_transducer_stateless_d2v_v2/utils.py
Normal file
@ -0,0 +1,17 @@
|
||||
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
|
||||
~
|
||||
Loading…
x
Reference in New Issue
Block a user