add warning in Conv1DCell and synthesis.py for wavenet and deepvoice 3(auto-regressive models)

This commit is contained in:
chenfeiyu 2020-03-21 15:08:51 +00:00
parent 67613951d5
commit 2a1819a19c
3 changed files with 10 additions and 0 deletions

View File

@ -101,6 +101,8 @@ if __name__ == "__main__":
state, _ = dg.load_dygraph(args.checkpoint)
dv3.set_dict(state)
# WARNING: don't forget to remove weight norm to re-compute each wrapped layer's weight
# removing weight norm also speeds up computation
for layer in dv3.sublayers():
if isinstance(layer, WeightNormWrapper):
layer.remove_weight_norm()

View File

@ -115,6 +115,8 @@ if __name__ == "__main__":
print("Loading from {}.pdparams".format(args.checkpoint))
model.set_dict(model_dict)
# WARNING: don't forget to remove weight norm to re-compute each wrapped layer's weight
# removing weight norm also speeds up computation
for layer in model.sublayers():
if isinstance(layer, WeightNormWrapper):
layer.remove_weight_norm()

View File

@ -225,6 +225,12 @@ class Conv1DCell(Conv1D):
def start_sequence(self):
"""Prepare the Conv1DCell to generate a new sequence, this method should be called before calling add_input multiple times.
WARNING:
This method accesses `self.weight` directly. If a `Conv1DCell` object is wrapped in a `WeightNormWrapper`, make sure this method is called only after the `WeightNormWrapper`'s hook is called.
`WeightNormWrapper` removes the wrapped layer's `weight`, add has a `weight_v` and `weight_g` to re-compute the wrapped layer's weight as $weight = weight_g * weight_v / ||weight_v||$. (Recomputing the `weight` is a hook before calling the wrapped layer's `forward` method.)
Whenever a `WeightNormWrapper`'s `forward` method is called, the wrapped layer's weight is updated. But when loading from a checkpoint, `weight_v` and `weight_g` are updated but the wrapped layer's weight is not, since it is no longer a `Parameter`. You should manually call `remove_weight_norm` or `hook` to re-compute the wrapped layer's weight before calling this method if you don't call `forward` first.
So when loading a model which uses `Conv1DCell` objects wrapped in `WeightNormWrapper`s, remember to call `remove_weight_norm` for all `WeightNormWrapper`s before synthesizing. Also, removing weight norm speeds up computation.
"""
if not self.causal:
raise ValueError(