RASMUS/Finnish-ASR-Canary-v2
02.2k
1# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14import os15 16import torch17from lightning.pytorch import Trainer18from omegaconf import OmegaConf19 20from nemo.collections.speechlm2 import DataModule, DuplexS2SDataset, DuplexS2SModel21from nemo.core.config import hydra_runner22from nemo.utils.exp_manager import exp_manager23from nemo.utils.trainer_utils import resolve_trainer_cfg24 25torch.cuda.set_device(int(os.environ["LOCAL_RANK"]))26 27 28@hydra_runner(config_path="conf", config_name="s2s_duplex")29def train(cfg):30 OmegaConf.resolve(cfg)31 torch.distributed.init_process_group(backend="nccl")32 torch.set_float32_matmul_precision("medium")33 torch.backends.cudnn.allow_tf32 = True34 trainer = Trainer(**resolve_trainer_cfg(cfg.trainer))35 log_dir = exp_manager(trainer, cfg.get("exp_manager", None))36 OmegaConf.save(cfg, log_dir / "exp_config.yaml")37 38 with trainer.init_module():39 model = DuplexS2SModel(OmegaConf.to_container(cfg.model, resolve=True))40 41 dataset = DuplexS2SDataset(42 tokenizer=model.tokenizer,43 frame_length=cfg.data.frame_length,44 source_sample_rate=cfg.data.source_sample_rate,45 target_sample_rate=cfg.data.target_sample_rate,46 input_roles=cfg.data.input_roles,47 output_roles=cfg.data.output_roles,48 )49 datamodule = DataModule(cfg.data, tokenizer=model.tokenizer, dataset=dataset)50 51 trainer.fit(model, datamodule)52 53 54if __name__ == "__main__":55 train()56 