You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.5 KiB
75 lines
2.5 KiB
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
"""DAC model distributed training implementation.
|
|
|
|
This module contains the distributed training implementation for the DAC model.
|
|
"""
|
|
|
|
import os
|
|
import time
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
import paddle
|
|
import paddle.nn as nn
|
|
import paddle.distributed as dist
|
|
from paddle.io import DataLoader, DistributedBatchSampler
|
|
from visualdl import LogWriter
|
|
|
|
from paddlespeech.audio.codec.dac.model import DACModel
|
|
from paddlespeech.s2t.training.extensions.evaluator import StandardEvaluator
|
|
from paddlespeech.s2t.training.trainer import Trainer
|
|
|
|
|
|
class DACTrainer(Trainer):
|
|
"""Trainer for DAC model implementing distributed training.
|
|
|
|
Extends paddlespeech.s2t.training.trainer.Trainer with DAC-specific functionality.
|
|
"""
|
|
|
|
def __init__(self,
|
|
model,
|
|
optimizer,
|
|
dataloader,
|
|
output_dir,
|
|
config=None,
|
|
max_epoch=100,
|
|
**kwargs):
|
|
"""Initialize the DAC trainer.
|
|
|
|
Args:
|
|
model (nn.Layer): DAC model instance
|
|
optimizer (Optimizer): Optimizer instance
|
|
dataloader (DataLoader): Training data loader
|
|
output_dir (str): Output directory for saving models and logs
|
|
config (CfgNode, optional): Training config. Defaults to None.
|
|
max_epoch (int, optional): Maximum number of training epochs. Defaults to 100.
|
|
"""
|
|
super().__init__(model, optimizer, dataloader, output_dir, **kwargs)
|
|
self.config = config
|
|
self.max_epoch = max_epoch
|
|
|
|
# Setup distributed training
|
|
# TODO: Implement distributed training setup
|
|
|
|
def train_batch(self):
|
|
"""Train on one mini-batch data."""
|
|
# TODO: Implement batch training logic with distributed support
|
|
pass
|
|
|
|
def run(self):
|
|
"""Run training with distributed optimization."""
|
|
# TODO: Implement distributed training loop
|
|
pass
|