instruct-MusicGen / src /models /instructmusicgenadapter_module.py
Vansh Chugh
ask user only for the edit part, use non-deprecated autocast api
55cbfca
Raw
History Blame Contribute Delete
981 Bytes
"""PyTorch Lightning module for InstructMusicGen model with adapter-based instruction tuning.
Trimmed to the inference path only i.e. removed training_step/ validation_step/test_step, torchmetrics/wandb
logging bcs not needed for inference; only kept what load_from_checkpoint() needs.
"""
import torch
from lightning import LightningModule
from .components.model import Instructor
class InstructMusicGenAdapterLitModule(LightningModule):
def __init__(
self,
optimizer: torch.optim.Optimizer,
scheduler: torch.optim.lr_scheduler,
tmp_dir: str,
compile: bool,
instructor: Instructor,
audio_regularization: float,
) -> None:
super().__init__()
# this line allows to access init params with 'self.hparams' attribute
# also ensures init params will be stored in ckpt
self.save_hyperparameters(logger=False)
self.model = self.hparams.instructor()