CoolFace
Modelpublic

RASMUS/Finnish-ASR-Canary-v2

sourceHugging Facemitupdated 7mo agoView on Hugging Face
0likes2.2kdownloads
salm_asr_decoder_train.py49 linesDownload Raw Back to speechlm2
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, SALMDataset21from nemo.collections.speechlm2.models.salm_asr_decoder import SALMWithAsrDecoder22from nemo.core.config import hydra_runner23from nemo.utils.exp_manager import exp_manager24from nemo.utils.trainer_utils import resolve_trainer_cfg25 26torch.cuda.set_device(int(os.environ["LOCAL_RANK"]))27 28 29@hydra_runner(config_path="conf", config_name="salm")30def train(cfg):31    OmegaConf.resolve(cfg)32    torch.distributed.init_process_group(backend="nccl")33    torch.set_float32_matmul_precision("medium")34    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 = SALMWithAsrDecoder(OmegaConf.to_container(cfg.model, resolve=True))40 41    dataset = SALMDataset(tokenizer=model.tokenizer)42    datamodule = DataModule(cfg.data, tokenizer=model.tokenizer, dataset=dataset)43 44    trainer.fit(model, datamodule)45 46 47if __name__ == "__main__":48    train()49