6bc3fd6443
Pure PyTorch SelVA source for SelvaModelLoader/FeatureExtractor/Sampler nodes. Imports rewritten from selva.* to selva_core.*. mel_converter.py: replaced librosa.filters.mel with pure-numpy implementation to avoid librosa→numba→NumPy version incompatibility in some ComfyUI environments. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
33 lines
989 B
Python
33 lines
989 B
Python
from pathlib import Path
|
|
|
|
import torch
|
|
import torch.nn as nn
|
|
from omegaconf import OmegaConf
|
|
|
|
from selva_core.ext.bigvgan.models import BigVGANVocoder
|
|
|
|
_bigvgan_vocoder_path = Path(__file__).parent / 'bigvgan_vocoder.yml'
|
|
|
|
|
|
class BigVGAN(nn.Module):
|
|
|
|
def __init__(self, ckpt_path, config_path=_bigvgan_vocoder_path):
|
|
super().__init__()
|
|
vocoder_cfg = OmegaConf.load(config_path)
|
|
self.vocoder = BigVGANVocoder(vocoder_cfg).eval()
|
|
vocoder_ckpt = torch.load(ckpt_path, map_location='cpu', weights_only=True)['generator']
|
|
self.vocoder.load_state_dict(vocoder_ckpt)
|
|
|
|
self.weight_norm_removed = False
|
|
self.remove_weight_norm()
|
|
|
|
@torch.inference_mode()
|
|
def forward(self, x):
|
|
assert self.weight_norm_removed, 'call remove_weight_norm() before inference'
|
|
return self.vocoder(x)
|
|
|
|
def remove_weight_norm(self):
|
|
self.vocoder.remove_weight_norm()
|
|
self.weight_norm_removed = True
|
|
return self
|