{"record":{"id":"b8f9931426712bfe","repo":"Comfy-Org/ComfyUI","slug":"vocoder-is-missing-upsample-factor-cannot-infer-o","errorCode":null,"errorMessage":"Vocoder is missing upsample_factor; cannot infer output sample rate","messagePattern":"Vocoder is missing upsample_factor; cannot infer output sample rate","errorType":"validation","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/lightricks/vae/audio_vae.py","lineNumber":232,"sourceCode":"    def latent_channels(self) -> int:\n        return int(self.autoencoder.decoder.z_channels)\n\n    @property\n    def latent_frequency_bins(self) -> int:\n        return int(self.mel_bins // LATENT_DOWNSAMPLE_FACTOR)\n\n    @property\n    def latents_per_second(self) -> float:\n        return self.sample_rate / self.mel_hop_length / LATENT_DOWNSAMPLE_FACTOR\n\n    @property\n    def output_sample_rate(self) -> int:\n        output_rate = getattr(self.vocoder, \"output_sample_rate\", None)\n        if output_rate is not None:\n            return int(output_rate)\n        upsample_factor = getattr(self.vocoder, \"upsample_factor\", None)\n        if upsample_factor is None:\n            raise AttributeError(\n                \"Vocoder is missing upsample_factor; cannot infer output sample rate\"\n            )\n        return int(self.sample_rate * upsample_factor / self.mel_hop_length)\n\n    def memory_required(self, input_shape):\n        return self.device_manager.patcher.model_size()\n","sourceCodeStart":214,"sourceCodeEnd":239,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/lightricks/vae/audio_vae.py#L214-L239","documentation":"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.","triggerScenarios":"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.","commonSituations":"Swapping in custom vocoders, exporting to TorchScript (attribute lookups fail), or wrapping the vocoder in a container that does not forward getattr.","solutions":["Expose upsample_factor (int) or output_sample_rate on your custom vocoder class","Set the attribute after loading: vocoder.upsample_factor = hop_ratio","Access the property only through the repo's own vocoder loading path"],"exampleFix":"# before\nclass MyVocoder(nn.Module): ...\nrate = audio_vae.output_sample_rate  # AttributeError\n# after\nclass MyVocoder(nn.Module):\n    upsample_factor = 256\nrate = audio_vae.output_sample_rate","handlingStrategy":"type-guard","validationCode":"if not hasattr(vocoder, 'output_sample_rate') and not hasattr(vocoder, 'upsample_factor'):\n    vocoder.upsample_factor = DEFAULT_HOP_RATIO  # set before use","typeGuard":"def vocoder_rate_inferable(vocoder) -> bool:\n    return hasattr(vocoder, 'output_sample_rate') or hasattr(vocoder, 'upsample_factor')","tryCatchPattern":null,"preventionTips":["Custom vocoders must declare upsample_factor or output_sample_rate","Check attribute presence right after loading, before any decode call"],"tags":["ltx","audio-vae","vocoder","attribute-missing"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}