Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: property overrides in EncodecModel #322

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions audiocraft/models/encodec.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ class EncodecModel(CompressionModel):
causal (bool): Whether to use a causal version of the model.
renormalize (bool): Whether to renormalize the audio before running the model.
"""
# we need assignment to override the property in the abstract class,
# I couldn't find a better way...
frame_rate: float = 0
sample_rate: int = 0
channels: int = 0

def __init__(self,
encoder: nn.Module,
Expand All @@ -153,16 +148,28 @@ def __init__(self,
self.encoder = encoder
self.decoder = decoder
self.quantizer = quantizer
self.frame_rate = frame_rate
self.sample_rate = sample_rate
self.channels = channels
self._frame_rate = frame_rate
self._sample_rate = sample_rate
self._channels = channels
self.renormalize = renormalize
self.causal = causal
if self.causal:
# we force disabling here to avoid handling linear overlap of segments
# as supported in original EnCodec codebase.
assert not self.renormalize, 'Causal model does not support renormalize'

@property
def frame_rate(self) -> float:
return self._frame_rate

@property
def sample_rate(self) -> int:
return self._sample_rate

@property
def channels(self) -> int:
return self._channels

@property
def total_codebooks(self):
"""Total number of quantizer codebooks available."""
Expand Down
Loading