From d6da8fc68b1a5e16465af7805e9efa1921ec9e20 Mon Sep 17 00:00:00 2001 From: Test User Date: Mon, 4 May 2026 21:39:44 +0800 Subject: [PATCH] Fix mutable default list argument in config classes Replace mutable default `encoder_ratios=[8,5,5,4,2,2]` with `None` and initialize inside the method body. Python evaluates default arguments once at class definition time, so all instances share the same list object. Mutating it on one instance would silently corrupt all others. Also use `list(encoder_ratios)` when assigning `decoder_ratios` from `encoder_ratios` to avoid shared references between encoder and decoder. Co-Authored-By: Claude Opus 4.7 --- vibevoice/modular/configuration_vibevoice.py | 22 ++++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/vibevoice/modular/configuration_vibevoice.py b/vibevoice/modular/configuration_vibevoice.py index 18451136..6d654d21 100644 --- a/vibevoice/modular/configuration_vibevoice.py +++ b/vibevoice/modular/configuration_vibevoice.py @@ -52,22 +52,24 @@ def __init__( weight_init_value: float = 1e-2, # encoder specific encoder_n_filters: int = 32, - encoder_ratios: Optional[List[int]] = [8,5,5,4,2,2], + encoder_ratios: Optional[List[int]] = None, encoder_depths: str = "3-3-3-3-3-3-8", # decoder specific decoder_n_filters: int = 32, - decoder_ratios: Optional[List[int]] = None, # if None, same as encoder + decoder_ratios: Optional[List[int]] = None, decoder_depths: Optional[str] = None, **kwargs ): super().__init__(**kwargs) + if encoder_ratios is None: + encoder_ratios = [8, 5, 5, 4, 2, 2] self.channels = channels self.corpus_normalize = corpus_normalize self.causal = causal self.vae_dim = vae_dim self.fix_std = fix_std self.std_dist_type = std_dist_type - + # common parameters self.conv_norm = conv_norm self.pad_mode = pad_mode @@ -84,16 +86,16 @@ def __init__( self.encoder_n_filters = encoder_n_filters self.encoder_ratios = encoder_ratios self.encoder_depths = encoder_depths - + # decoder specific parameters - self.decoder_ratios = decoder_ratios if decoder_ratios is not None else encoder_ratios + self.decoder_ratios = decoder_ratios if decoder_ratios is not None else list(encoder_ratios) self.decoder_n_filters = decoder_n_filters self.decoder_depths = decoder_depths class VibeVoiceSemanticTokenizerConfig(PretrainedConfig): model_type = "vibevoice_semantic_tokenizer" - + def __init__( self, channels: int = 1, @@ -102,7 +104,7 @@ def __init__( vae_dim: int = 64, fix_std: float = 0, std_dist_type: str = 'none', - # common + # common mixer_layer: str = 'depthwise_conv', conv_norm: str = 'none', pad_mode: str = 'constant', @@ -115,18 +117,20 @@ def __init__( weight_init_value: float = 1e-2, # encoder specific encoder_n_filters: int = 32, - encoder_ratios: Optional[List[int]] = [8,5,5,4,2,2], + encoder_ratios: Optional[List[int]] = None, encoder_depths: str = "3-3-3-3-3-3-8", **kwargs ): super().__init__(**kwargs) + if encoder_ratios is None: + encoder_ratios = [8, 5, 5, 4, 2, 2] self.channels = channels self.corpus_normalize = corpus_normalize self.causal = causal self.vae_dim = vae_dim self.fix_std = fix_std self.std_dist_type = std_dist_type - + # common parameters self.conv_norm = conv_norm self.pad_mode = pad_mode