|
|
@ -11,11 +11,9 @@
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
# limitations under the License.
|
|
|
|
import random
|
|
|
|
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
from pathlib import Path
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
import paddle
|
|
|
|
import paddle
|
|
|
|
from paddle import distributed as dist
|
|
|
|
from paddle import distributed as dist
|
|
|
|
from tensorboardX import SummaryWriter
|
|
|
|
from tensorboardX import SummaryWriter
|
|
|
@ -23,6 +21,7 @@ from tensorboardX import SummaryWriter
|
|
|
|
from deepspeech.utils import mp_tools
|
|
|
|
from deepspeech.utils import mp_tools
|
|
|
|
from deepspeech.utils.checkpoint import Checkpoint
|
|
|
|
from deepspeech.utils.checkpoint import Checkpoint
|
|
|
|
from deepspeech.utils.log import Log
|
|
|
|
from deepspeech.utils.log import Log
|
|
|
|
|
|
|
|
from deepspeech.utils.utility import seed_all
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = ["Trainer"]
|
|
|
|
__all__ = ["Trainer"]
|
|
|
|
|
|
|
|
|
|
|
@ -95,13 +94,10 @@ class Trainer():
|
|
|
|
self.checkpoint_dir = None
|
|
|
|
self.checkpoint_dir = None
|
|
|
|
self.iteration = 0
|
|
|
|
self.iteration = 0
|
|
|
|
self.epoch = 0
|
|
|
|
self.epoch = 0
|
|
|
|
if args.seed is not None:
|
|
|
|
|
|
|
|
self.set_seed(args.seed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_seed(self, seed):
|
|
|
|
if args.seed:
|
|
|
|
np.random.seed(seed)
|
|
|
|
seed_all(args.seed)
|
|
|
|
random.seed(seed)
|
|
|
|
logger.info(f"Set seed {args.seed}")
|
|
|
|
paddle.seed(seed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setup(self):
|
|
|
|
def setup(self):
|
|
|
|
"""Setup the experiment.
|
|
|
|
"""Setup the experiment.
|
|
|
@ -181,8 +177,10 @@ class Trainer():
|
|
|
|
"""Reset the train loader seed and increment `epoch`.
|
|
|
|
"""Reset the train loader seed and increment `epoch`.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
self.epoch += 1
|
|
|
|
self.epoch += 1
|
|
|
|
if self.parallel:
|
|
|
|
if self.parallel and hasattr(self.train_loader, "batch_sampler"):
|
|
|
|
self.train_loader.batch_sampler.set_epoch(self.epoch)
|
|
|
|
batch_sampler = self.train_loader.batch_sampler
|
|
|
|
|
|
|
|
if isinstance(batch_sampler, paddle.io.DistributedBatchSampler):
|
|
|
|
|
|
|
|
batch_sampler.set_epoch(self.epoch)
|
|
|
|
|
|
|
|
|
|
|
|
def train(self):
|
|
|
|
def train(self):
|
|
|
|
"""The training process control by epoch."""
|
|
|
|
"""The training process control by epoch."""
|
|
|
@ -191,7 +189,7 @@ class Trainer():
|
|
|
|
# save init model, i.e. 0 epoch
|
|
|
|
# save init model, i.e. 0 epoch
|
|
|
|
self.save(tag='init', infos=None)
|
|
|
|
self.save(tag='init', infos=None)
|
|
|
|
self.lr_scheduler.step(self.epoch)
|
|
|
|
self.lr_scheduler.step(self.epoch)
|
|
|
|
if self.parallel:
|
|
|
|
if self.parallel and hasattr(self.train_loader, "batch_sampler"):
|
|
|
|
self.train_loader.batch_sampler.set_epoch(self.epoch)
|
|
|
|
self.train_loader.batch_sampler.set_epoch(self.epoch)
|
|
|
|
|
|
|
|
|
|
|
|
logger.info(f"Train Total Examples: {len(self.train_loader.dataset)}")
|
|
|
|
logger.info(f"Train Total Examples: {len(self.train_loader.dataset)}")
|
|
|
|