Comfy-Org/ComfyUI · error · AttributeError

Vocoder is missing upsample_factor; cannot infer output samp

Error message

Vocoder is missing upsample_factor; cannot infer output sample rate

What it means

output_sample_rate first tries vocoder.output_sample_rate; otherwise it infers rate = sample_rate * upsample_factor / mel_hop_length. If the vocoder exposes neither attribute, the rate is unknowable and the property raises AttributeError (note: not ValueError) with this message.

Source

Thrown at comfy/ldm/lightricks/vae/audio_vae.py:232

    def latent_channels(self) -> int:
        return int(self.autoencoder.decoder.z_channels)

    @property
    def latent_frequency_bins(self) -> int:
        return int(self.mel_bins // LATENT_DOWNSAMPLE_FACTOR)

    @property
    def latents_per_second(self) -> float:
        return self.sample_rate / self.mel_hop_length / LATENT_DOWNSAMPLE_FACTOR

    @property
    def output_sample_rate(self) -> int:
        output_rate = getattr(self.vocoder, "output_sample_rate", None)
        if output_rate is not None:
            return int(output_rate)
        upsample_factor = getattr(self.vocoder, "upsample_factor", None)
        if upsample_factor is None:
            raise AttributeError(
                "Vocoder is missing upsample_factor; cannot infer output sample rate"
            )
        return int(self.sample_rate * upsample_factor / self.mel_hop_length)

    def memory_required(self, input_shape):
        return self.device_manager.patcher.model_size()

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Expose upsample_factor (int) or output_sample_rate on your custom vocoder class
  2. Set the attribute after loading: vocoder.upsample_factor = hop_ratio
  3. Access the property only through the repo's own vocoder loading path

Example fix

# before
class MyVocoder(nn.Module): ...
rate = audio_vae.output_sample_rate  # AttributeError
# after
class MyVocoder(nn.Module):
    upsample_factor = 256
rate = audio_vae.output_sample_rate
Defensive patterns

Strategy: type-guard

Validate before calling

if not hasattr(vocoder, 'output_sample_rate') and not hasattr(vocoder, 'upsample_factor'):
    vocoder.upsample_factor = DEFAULT_HOP_RATIO  # set before use

Type guard

def vocoder_rate_inferable(vocoder) -> bool:
    return hasattr(vocoder, 'output_sample_rate') or hasattr(vocoder, 'upsample_factor')

Prevention

When it happens

Trigger: Calling audio_vae.output_sample_rate on a vocoder wrapper that is a plain module without output_sample_rate or upsample_factor attributes — e.g. a custom vocoder, a torch.compile'd/scripted wrapper that hides attributes, or a partial checkpoint load.

Common situations: Swapping in custom vocoders, exporting to TorchScript (attribute lookups fail), or wrapping the vocoder in a container that does not forward getattr.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/b8f9931426712bfe. Report an issue: GitHub.