Skip to content

Commit

Permalink
feat: handling wrong model type
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelLarkin committed Sep 24, 2024
1 parent 409e757 commit b92868a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion hfgl/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
dynamic_range_compression_torch,
get_spectral_transform,
)
from loguru import logger
from torch.nn import AvgPool1d, Conv1d, Conv2d, ConvTranspose1d
from torch.nn.utils import spectral_norm
from torch.nn.utils.parametrizations import weight_norm
Expand Down Expand Up @@ -454,8 +455,21 @@ class HiFiGANGenerator(pl.LightningModule):

def __init__(self, config: dict | VocoderConfig):
super().__init__()

if not isinstance(config, VocoderConfig):
config = VocoderConfig(**config)
from pydantic import ValidationError

try:
config = VocoderConfig(**config)
except ValidationError:
# TODO: should we print the following message only if there are more than X validation errors?
# e.error_count() > X
error = TypeError(
"Unable to load config. Are you certain it is a VocoderConfig config?"
)
logger.error(error.args)
raise error

self.config = config
self.generator = Generator(self.config)

Expand Down

0 comments on commit b92868a

Please sign in to comment.