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
5e893d6f
Unverified
Commit
5e893d6f
authored
Sep 08, 2023
by
Pingchuan Ma
Committed by
GitHub
Sep 08, 2023
Browse files
Simplify trainining step in av-asr recipe (#3598)
* Simplify trainining step in av-asr recipe * Run pre-commit
parent
3e1d8f3c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1 addition
and
24 deletions
+1
-24
examples/avsr/lightning.py
examples/avsr/lightning.py
+0
-12
examples/avsr/lightning_av.py
examples/avsr/lightning_av.py
+0
-12
examples/avsr/train.py
examples/avsr/train.py
+1
-0
No files found.
examples/avsr/lightning.py
View file @
5e893d6f
...
...
@@ -84,8 +84,6 @@ class ConformerRNNTModule(LightningModule):
betas
=
(
0.9
,
0.98
),
)
self
.
automatic_optimization
=
False
def
_step
(
self
,
batch
,
_
,
step_type
):
if
batch
is
None
:
return
None
...
...
@@ -123,20 +121,10 @@ class ConformerRNNTModule(LightningModule):
return
post_process_hypos
(
hypotheses
,
self
.
sp_model
)[
0
][
0
]
def
training_step
(
self
,
batch
,
batch_idx
):
opt
=
self
.
optimizers
()
opt
.
zero_grad
()
loss
=
self
.
_step
(
batch
,
batch_idx
,
"train"
)
batch_size
=
batch
.
inputs
.
size
(
0
)
batch_sizes
=
self
.
all_gather
(
batch_size
)
loss
*=
batch_sizes
.
size
(
0
)
/
batch_sizes
.
sum
()
# world size / batch size
self
.
manual_backward
(
loss
)
torch
.
nn
.
utils
.
clip_grad_norm_
(
self
.
model
.
parameters
(),
10
)
opt
.
step
()
sch
=
self
.
lr_schedulers
()
sch
.
step
()
self
.
log
(
"monitoring_step"
,
torch
.
tensor
(
self
.
global_step
,
dtype
=
torch
.
float32
))
return
loss
...
...
examples/avsr/lightning_av.py
View file @
5e893d6f
...
...
@@ -80,8 +80,6 @@ class AVConformerRNNTModule(LightningModule):
betas
=
(
0.9
,
0.98
),
)
self
.
automatic_optimization
=
False
def
_step
(
self
,
batch
,
_
,
step_type
):
if
batch
is
None
:
return
None
...
...
@@ -128,20 +126,10 @@ class AVConformerRNNTModule(LightningModule):
return
post_process_hypos
(
hypotheses
,
self
.
sp_model
)[
0
][
0
]
def
training_step
(
self
,
batch
,
batch_idx
):
opt
=
self
.
optimizers
()
opt
.
zero_grad
()
loss
=
self
.
_step
(
batch
,
batch_idx
,
"train"
)
batch_size
=
batch
.
videos
.
size
(
0
)
batch_sizes
=
self
.
all_gather
(
batch_size
)
loss
*=
batch_sizes
.
size
(
0
)
/
batch_sizes
.
sum
()
# world size / batch size
self
.
manual_backward
(
loss
)
torch
.
nn
.
utils
.
clip_grad_norm_
(
self
.
model
.
parameters
(),
10
)
opt
.
step
()
sch
=
self
.
lr_schedulers
()
sch
.
step
()
self
.
log
(
"monitoring_step"
,
torch
.
tensor
(
self
.
global_step
,
dtype
=
torch
.
float32
))
return
loss
...
...
examples/avsr/train.py
View file @
5e893d6f
...
...
@@ -36,6 +36,7 @@ def get_trainer(args):
strategy
=
DDPStrategy
(
find_unused_parameters
=
False
),
callbacks
=
callbacks
,
reload_dataloaders_every_n_epochs
=
1
,
gradient_clip_val
=
10.0
,
)
...
...
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