{"record":{"id":"762913339ecbe34a","repo":"sgl-project/sglang","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":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/vaes/autoencoder.py","lineNumber":270,"sourceCode":"            fn_recursive_attn_processor(name, module, processor)\n\n    # Copied from diffusers.models.unets.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(\n            proc.__class__ in ADDED_KV_ATTENTION_PROCESSORS\n            for proc in self.attn_processors.values()\n        ):\n            processor = AttnAddedKVProcessor()\n        elif all(\n            proc.__class__ in CROSS_ATTENTION_PROCESSORS\n            for proc in self.attn_processors.values()\n        ):\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)\n\n    def _encode(self, x: torch.Tensor) -> torch.Tensor:\n        batch_size, num_channels, height, width = x.shape\n\n        if self.use_tiling and (\n            width > self.tile_sample_min_size or height > self.tile_sample_min_size\n        ):\n            return self._tiled_encode(x)\n\n        enc = self.encoder(x)\n        if self.quant_conv is not None:\n            enc = self.quant_conv(enc)\n\n        return enc","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/vaes/autoencoder.py#L252-L288","documentation":"set_default_attn_processor picks the default processor class based on the current processors' class family (attention vs cross-attention). If the installed processors are neither in the known attention-processor set nor the cross-attention set (e.g. a fused or custom processor), it refuses to guess which default to restore.","triggerScenarios":"Calling set_default_attn_processor() after fuse_qkv_projections() installed fused processors, or after setting a custom/XFormers/Flash processor class not registered in either processor-class set.","commonSituations":"Trying to undo fusion or a custom processor by 'resetting to default'; using a processor from a newer diffusers version whose class isn't in the local CROSS_ATTENTION_PROCESSORS set; diffusers version change altering processor class hierarchy.","solutions":["Explicitly restore with set_attn_processor(self.original_attn_processors) (saved by fuse_qkv_projections) instead of set_default_attn_processor","Or explicitly set the exact processor class: model.set_attn_processor(AttnProcessor())","Upgrade/align the library version so the processor classes you installed are recognized"],"exampleFix":"# before\nmodel.fuse_qkv_projections()\n...\nmodel.set_default_attn_processor()\n# after\nmodel.fuse_qkv_projections()\n...\nmodel.unfuse_qkv_projections()\n# or: model.set_attn_processor(model.original_attn_processors)","handlingStrategy":"fallback","validationCode":"known = (AttnProcessor,)\nif not all(type(p) in known_set for p in model.attn_processors.values()):\n    model.set_attn_processor(AttnProcessor())  # explicit reset instead of default","typeGuard":null,"tryCatchPattern":"try:\n    model.set_default_attn_processor()\nexcept ValueError:\n    model.set_attn_processor(AttnProcessor())","preventionTips":["Save processors before customizing: saved = dict(model.attn_processors)","Reset explicitly with the saved dict rather than relying on set_default_attn_processor"],"tags":["attention","processor","fusion","state-error"],"backgroundTag":"unsupported-processor-type","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}