sgl-project/sglang · error · ValueError
Cannot call `set_default_attn_processor` when attention proc
Error message
Cannot call `set_default_attn_processor` when attention processors are of type {next(iter(self.attn_processors.values()))} What it means
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.
Source
Thrown at python/sglang/multimodal_gen/runtime/models/vaes/autoencoder.py:270
fn_recursive_attn_processor(name, module, processor)
# Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.set_default_attn_processor
def set_default_attn_processor(self):
"""
Disables custom attention processors and sets the default attention implementation.
"""
if all(
proc.__class__ in ADDED_KV_ATTENTION_PROCESSORS
for proc in self.attn_processors.values()
):
processor = AttnAddedKVProcessor()
elif all(
proc.__class__ in CROSS_ATTENTION_PROCESSORS
for proc in self.attn_processors.values()
):
processor = AttnProcessor()
else:
raise ValueError(
f"Cannot call `set_default_attn_processor` when attention processors are of type {next(iter(self.attn_processors.values()))}"
)
self.set_attn_processor(processor)
def _encode(self, x: torch.Tensor) -> torch.Tensor:
batch_size, num_channels, height, width = x.shape
if self.use_tiling and (
width > self.tile_sample_min_size or height > self.tile_sample_min_size
):
return self._tiled_encode(x)
enc = self.encoder(x)
if self.quant_conv is not None:
enc = self.quant_conv(enc)
return encView on GitHub (pinned to 0132848349)
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
Example fix
# before model.fuse_qkv_projections() ... model.set_default_attn_processor() # after model.fuse_qkv_projections() ... model.unfuse_qkv_projections() # or: model.set_attn_processor(model.original_attn_processors)
Defensive patterns
Strategy: fallback
Validate before calling
known = (AttnProcessor,)
if not all(type(p) in known_set for p in model.attn_processors.values()):
model.set_attn_processor(AttnProcessor()) # explicit reset instead of default Try / catch
try:
model.set_default_attn_processor()
except ValueError:
model.set_attn_processor(AttnProcessor()) Prevention
- Save processors before customizing: saved = dict(model.attn_processors)
- Reset explicitly with the saved dict rather than relying on set_default_attn_processor
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot call `set_default_attn_processor` when attention proc
- A dict of processors was passed, but the number of processor
- `fuse_qkv_projections()` is not supported for models having
- A dict of processors was passed, but the number of processor
- num_heads must be divisible by num_epi_subtiles
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/762913339ecbe34a.
Report an issue: GitHub.