{"record":{"id":"0608f74ca74c2b35","repo":"hpcaitech/Open-Sora","slug":"cannot-call-set-default-attn-processor-when-atte","errorCode":null,"errorMessage":"Cannot call `set_default_attn_processor` when attention processors are of type {next(iter(self.attn_processors.values()))}","messagePattern":"Cannot call `set_default_attn_processor` when attention processors are of type (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"opensora/models/hunyuan_vae/autoencoder_kl_causal_3d.py","lineNumber":263,"sourceCode":"                    module.set_processor(processor.pop(f\"{name}.processor\"), _remove_lora=_remove_lora)\n\n            for sub_name, child in module.named_children():\n                fn_recursive_attn_processor(f\"{name}.{sub_name}\", child, processor)\n\n        for name, module in self.named_children():\n            fn_recursive_attn_processor(name, module, processor)\n\n    # Copied from diffusers.models.unet_2d_condition.UNet2DConditionModel.set_default_attn_processor\n    def set_default_attn_processor(self):\n        \"\"\"\n        Disables custom attention processors and sets the default attention implementation.\n        \"\"\"\n        if all(proc.__class__ in ADDED_KV_ATTENTION_PROCESSORS for proc in self.attn_processors.values()):\n            processor = AttnAddedKVProcessor()\n        elif all(proc.__class__ in CROSS_ATTENTION_PROCESSORS for proc in self.attn_processors.values()):\n            processor = AttnProcessor()\n        else:\n            raise ValueError(\n                f\"Cannot call `set_default_attn_processor` when attention processors are of type {next(iter(self.attn_processors.values()))}\"\n            )\n\n        self.set_attn_processor(processor, _remove_lora=True)\n\n    @apply_forward_hook\n    def encode(\n        self,\n        x: torch.FloatTensor,\n        sample_posterior: bool = True,\n        return_posterior: bool = False,\n        generator: Optional[torch.Generator] = None,\n    ) -> Union[torch.FloatTensor, Tuple[DiagonalGaussianDistribution]]:\n        \"\"\"\n        Encode a batch of images/videos into latents.\n\n        Args:\n            x (`torch.FloatTensor`): Input batch of images/videos.","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/hpcaitech/Open-Sora/blob/7ad6a96a135feb81f755c84fb391818718f6beb2/opensora/models/hunyuan_vae/autoencoder_kl_causal_3d.py#L245-L281","documentation":"set_default_attn_processor restores the stock processor by checking whether ALL current processors are in ADDED_KV_ATTENTION_PROCESSORS or all in CROSS_ATTENTION_PROCESSORS. If the current processors are a mix, or of a custom/unknown class (e.g. fused or LoRA-patched processors not in either tuple), it refuses to guess and raises.","triggerScenarios":"Calling set_default_attn_processor after setting custom attention processor classes, or when a mixture of added-KV and cross-attention processors is installed, or after LoRA fusion left nonstandard processor types.","commonSituations":"Cleanup code after attention experiments (ring/context-parallel processors from distributed.py, LoRA processors) tries to reset to defaults without un-doing the custom classes first.","solutions":["Manually set a concrete processor: model.set_attn_processor(AttnProcessor()) (or AttnAddedKVProcessor() as appropriate)","Ensure all layers use one consistent processor family before calling set_default_attn_processor","Unfuse/unload LoRA modifications first so processors are back in the known sets"],"exampleFix":"# before\nmodel.set_default_attn_processor()\n# after\nfrom diffusers.models.attention_processor import AttnProcessor\nmodel.set_attn_processor(AttnProcessor())","handlingStrategy":"fallback","validationCode":"known = lambda p: all(proc.__class__ in ADDED_KV_ATTENTION_PROCESSORS or proc.__class__ in CROSS_ATTENTION_PROCESSORS for proc in model.attn_processors.values())","typeGuard":null,"tryCatchPattern":"try:\n    model.set_default_attn_processor()\nexcept ValueError:\n    model.set_attn_processor(AttnProcessor())","preventionTips":["Keep processors in one consistent family","Reset processors explicitly rather than relying on defaults","Unfuse LoRA before restoring defaults"],"tags":["diffusers","attention","vae"],"backgroundTag":"unsupported-processor-type","analyzedSha":"7ad6a96a135feb81f755c84fb391818718f6beb2","analyzedAt":"2026-08-28T16:58:37.171Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}