Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Torchaudio
Commits
3aa0d573
Unverified
Commit
3aa0d573
authored
Oct 11, 2021
by
moto
Committed by
GitHub
Oct 11, 2021
Browse files
Avoid concatenation in loop (#1850)
parent
d93322e8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
15 deletions
+10
-15
torchaudio/models/tacotron2.py
torchaudio/models/tacotron2.py
+10
-15
No files found.
torchaudio/models/tacotron2.py
View file @
3aa0d573
...
...
@@ -925,12 +925,9 @@ class _Decoder(nn.Module):
[
memory
.
size
(
0
)],
dtype
=
torch
.
int32
,
device
=
memory
.
device
)
mel_specgrams
,
gate_outputs
,
alignments
=
(
torch
.
zeros
(
1
,
dtype
=
memory
.
dtype
),
torch
.
zeros
(
1
,
dtype
=
memory
.
dtype
),
torch
.
zeros
(
1
,
dtype
=
memory
.
dtype
),
)
first_iter
=
True
mel_specgrams
:
List
[
Tensor
]
=
[]
gate_outputs
:
List
[
Tensor
]
=
[]
alignments
:
List
[
Tensor
]
=
[]
while
True
:
decoder_input
=
self
.
prenet
(
decoder_input
)
(
...
...
@@ -957,15 +954,9 @@ class _Decoder(nn.Module):
mask
,
)
if
first_iter
:
mel_specgrams
=
mel_specgram
.
unsqueeze
(
0
)
gate_outputs
=
gate_output
.
transpose
(
0
,
1
)
alignments
=
attention_weights
first_iter
=
False
else
:
mel_specgrams
=
torch
.
cat
((
mel_specgrams
,
mel_specgram
.
unsqueeze
(
0
)),
dim
=
0
)
gate_outputs
=
torch
.
cat
((
gate_outputs
,
gate_output
.
transpose
(
0
,
1
)),
dim
=
0
)
alignments
=
torch
.
cat
((
alignments
,
attention_weights
),
dim
=
0
)
mel_specgrams
.
append
(
mel_specgram
.
unsqueeze
(
0
))
gate_outputs
.
append
(
gate_output
.
transpose
(
0
,
1
))
alignments
.
append
(
attention_weights
)
dec
=
torch
.
le
(
torch
.
sigmoid
(
gate_output
),
self
.
gate_threshold
).
to
(
torch
.
int32
).
squeeze
(
1
)
...
...
@@ -980,6 +971,10 @@ class _Decoder(nn.Module):
mel_specgram_lengths
+=
not_finished
decoder_input
=
mel_specgram
mel_specgrams
=
torch
.
cat
(
mel_specgrams
,
dim
=
0
)
gate_outputs
=
torch
.
cat
(
gate_outputs
,
dim
=
0
)
alignments
=
torch
.
cat
(
alignments
,
dim
=
0
)
mel_specgrams
,
gate_outputs
,
alignments
=
self
.
_parse_decoder_outputs
(
mel_specgrams
,
gate_outputs
,
alignments
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment