{"record":{"id":"55e7082ca7d12305","repo":"sgl-project/sglang","slug":"cannot-call-set-default-attn-processor-when-atte-55e708","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_kl_flux2.py","lineNumber":221,"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":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/vaes/autoencoder_kl_flux2.py#L203-L239","documentation":"set_default_attn_processor on the Flux2 autoencoder chooses a default processor class by inspecting the currently installed processors. If they are neither recognized attention processors nor cross-attention processors (e.g. fused or custom classes), it cannot determine the correct default and raises, naming the offending class.","triggerScenarios":"Calling set_default_attn_processor() while fused or third-party (Flash/XFormers/custom) processors are installed, or after a version change moved processor classes out of the recognized sets.","commonSituations":"Attempting to reset state after experiments with custom processors; library upgrade changing class identity so `proc.__class__ in CROSS_ATTENTION_PROCESSORS` fails; mixing diffusers processor classes with local re-implementations.","solutions":["Restore explicitly: model.set_attn_processor(model.original_attn_processors) if fusion saved them, or set_attn_processor(AttnProcessor()) directly","Match library versions between where processors were set and where you reset them","Register/alias your custom processor class in the recognized processor sets if it is semantically compatible"],"exampleFix":"# before\nmodel.set_default_attn_processor()\n# after\nmodel.set_attn_processor(AttnProcessor())","handlingStrategy":"fallback","validationCode":"# snapshot before changing processors\nsnapshot = dict(model.attn_processors)\n# to restore later: model.set_attn_processor(snapshot)","typeGuard":null,"tryCatchPattern":"try:\n    model.set_default_attn_processor()\nexcept ValueError as e:\n    model.set_attn_processor(AttnProcessor())","preventionTips":["Snapshot processors before installing custom/fused ones and restore explicitly","Pin library versions so processor class identity stays stable"],"tags":["attention","processor","flux2","state-error"],"backgroundTag":"unsupported-processor-type","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}