Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
diffwave
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maria Guaranda-Cabezas
diffwave
Commits
d872c448
Commit
d872c448
authored
1 year ago
by
Maria Guaranda-Cabezas
Browse files
Options
Downloads
Patches
Plain Diff
adds comments to code
parent
4b64fcec
No related branches found
Branches containing commit
No related tags found
1 merge request
!5
Inference
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/data/lagrangian_datatools.py
+1
-0
1 addition, 0 deletions
src/data/lagrangian_datatools.py
src/diffwave/learner.py
+13
-0
13 additions, 0 deletions
src/diffwave/learner.py
src/diffwave/model.py
+5
-1
5 additions, 1 deletion
src/diffwave/model.py
with
19 additions
and
1 deletion
src/data/lagrangian_datatools.py
+
1
−
0
View file @
d872c448
...
@@ -75,6 +75,7 @@ class CollatorForDiffwave:
...
@@ -75,6 +75,7 @@ class CollatorForDiffwave:
pass
pass
def
collate
(
self
,
minibatch
):
def
collate
(
self
,
minibatch
):
# shape is (batch_size, trajectory_length)
trajectories
=
np
.
stack
([
record
[
'
audio
'
]
for
record
in
minibatch
])
trajectories
=
np
.
stack
([
record
[
'
audio
'
]
for
record
in
minibatch
])
return
{
return
{
'
audio
'
:
torch
.
from_numpy
(
trajectories
),
'
audio
'
:
torch
.
from_numpy
(
trajectories
),
...
...
This diff is collapsed.
Click to expand it.
src/diffwave/learner.py
+
13
−
0
View file @
d872c448
...
@@ -28,6 +28,17 @@ from params import AttrDict
...
@@ -28,6 +28,17 @@ from params import AttrDict
def
_nested_map
(
struct
,
map_fn
):
def
_nested_map
(
struct
,
map_fn
):
'''
This function will dive into an structure until it finds a tensor, and then
send it to a device.
Example:
if struct is a dict like:
x = {
"
audio
"
: Tensor(64,22000),
"
spectrogram
"
: Tensor(64,1024,128)}
and map_fn is a function that sends a tensor to a device, then the result is
x = {
"
audio
"
: Tensor(64,22000).to(device),
"
spectrogram
"
: Tensor(64,1024,128).to(device)}
'''
if
isinstance
(
struct
,
tuple
):
if
isinstance
(
struct
,
tuple
):
return
tuple
(
_nested_map
(
x
,
map_fn
)
for
x
in
struct
)
return
tuple
(
_nested_map
(
x
,
map_fn
)
for
x
in
struct
)
if
isinstance
(
struct
,
list
):
if
isinstance
(
struct
,
list
):
...
@@ -101,6 +112,8 @@ class DiffWaveLearner:
...
@@ -101,6 +112,8 @@ class DiffWaveLearner:
def
train
(
self
,
max_steps
=
None
):
def
train
(
self
,
max_steps
=
None
):
device
=
next
(
self
.
model
.
parameters
()).
device
device
=
next
(
self
.
model
.
parameters
()).
device
while
True
:
while
True
:
# number of epochs = max_steps / num_batches
# e.g. for max_steps = 100000 and num_batches = 1000, we have 100 epochs
for
features
in
tqdm
(
self
.
dataset
,
desc
=
f
'
Epoch
{
self
.
step
//
len
(
self
.
dataset
)
}
'
)
if
self
.
is_master
else
self
.
dataset
:
for
features
in
tqdm
(
self
.
dataset
,
desc
=
f
'
Epoch
{
self
.
step
//
len
(
self
.
dataset
)
}
'
)
if
self
.
is_master
else
self
.
dataset
:
if
max_steps
is
not
None
and
self
.
step
>=
max_steps
:
if
max_steps
is
not
None
and
self
.
step
>=
max_steps
:
# Save final checkpoint.
# Save final checkpoint.
...
...
This diff is collapsed.
Click to expand it.
src/diffwave/model.py
+
5
−
1
View file @
d872c448
...
@@ -37,6 +37,9 @@ def silu(x):
...
@@ -37,6 +37,9 @@ def silu(x):
class
DiffusionEmbedding
(
nn
.
Module
):
class
DiffusionEmbedding
(
nn
.
Module
):
'''
Sinusoidal embedding for diffusion step.
'''
def
__init__
(
self
,
max_steps
):
def
__init__
(
self
,
max_steps
):
super
().
__init__
()
super
().
__init__
()
self
.
register_buffer
(
'
embedding
'
,
self
.
_build_embedding
(
max_steps
),
persistent
=
False
)
self
.
register_buffer
(
'
embedding
'
,
self
.
_build_embedding
(
max_steps
),
persistent
=
False
)
...
@@ -147,7 +150,8 @@ class DiffWave(nn.Module):
...
@@ -147,7 +150,8 @@ class DiffWave(nn.Module):
def
forward
(
self
,
audio
,
diffusion_step
,
spectrogram
=
None
):
def
forward
(
self
,
audio
,
diffusion_step
,
spectrogram
=
None
):
assert
(
spectrogram
is
None
and
self
.
spectrogram_upsampler
is
None
)
or
\
assert
(
spectrogram
is
None
and
self
.
spectrogram_upsampler
is
None
)
or
\
(
spectrogram
is
not
None
and
self
.
spectrogram_upsampler
is
not
None
)
(
spectrogram
is
not
None
and
self
.
spectrogram_upsampler
is
not
None
)
x
=
audio
.
unsqueeze
(
1
)
# watch out for this, we can leave this to the dataloader actually
# watch out for this, we can leave this to the dataloader actually
x
=
audio
.
unsqueeze
(
1
)
# shape is (batch_size, 1, trajectory_length)
x
=
self
.
input_projection
(
x
)
x
=
self
.
input_projection
(
x
)
x
=
F
.
relu
(
x
)
x
=
F
.
relu
(
x
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment