sgl-project/sglang · error · RuntimeError
Multiview attention was not initialized.
Error message
Multiview attention was not initialized.
What it means
When more than one view is generated (num_views > 1) and use_multiview_attention is enabled, the block needs self.attn_multiview. If it is None because multiview attention was never initialized for this block, forward raises this RuntimeError.
Source
Thrown at python/sglang/multimodal_gen/runtime/models/dits/hunyuan3d_paint.py:131
if mode is not None and "r" in mode and self.use_reference_attention:
if self.attn_refview is None:
raise RuntimeError("Reference attention was not initialized.")
reference = condition_embeddings[self.layer_name]
reference = reference.unsqueeze(1).repeat(1, num_views, 1, 1)
reference = rearrange(reference, "b n l c -> (b n) l c")
reference_output = self.attn_refview(
normalized, encoder_hidden_states=reference
)
reference_scale = self._broadcast_scale(
1.0 if self.is_turbo else options.get("ref_scale", 1.0),
reference_output,
num_views,
)
hidden_states = hidden_states + reference_scale * reference_output
if num_views > 1 and self.use_multiview_attention:
if self.attn_multiview is None:
raise RuntimeError("Multiview attention was not initialized.")
multiview = rearrange(normalized, "(b n) l c -> b (n l) c", n=num_views)
position_masks = options.get("position_attn_mask")
position_mask = None
if isinstance(position_masks, dict):
position_mask = position_masks.get(multiview.shape[1])
multiview_output = self.attn_multiview(
multiview,
encoder_hidden_states=multiview,
attention_mask=position_mask,
)
multiview_output = rearrange(
multiview_output, "b (n l) c -> (b n) l c", n=num_views
)
multiview_scale = 1.0 if self.is_turbo else options.get("mva_scale", 1.0)
hidden_states = hidden_states + multiview_scale * multiview_output
hidden_states = hidden_states + self.transformer.attn2(
self.transformer.norm2(hidden_states),View on GitHub (pinned to 0132848349)
Solutions
- Replace transformer blocks with use_multiview_attention=True before running multiview inference
- Set num_in_batch=1 in cross_attention_kwargs if you genuinely only need one view
- Confirm every block that sees num_views>1 was covered by _replace_transformer_blocks
Example fix
# before
_replace_transformer_blocks(unet, use_multiview_attention=False)
out = block(x, cross_attention_kwargs={"num_in_batch": 4, ...})
# after
_replace_transformer_blocks(unet, use_multiview_attention=True)
out = block(x, cross_attention_kwargs={"num_in_batch": 4, ...}) Defensive patterns
Strategy: validation
Validate before calling
num_views = int(opts.get('num_in_batch', 1))
if num_views > 1 and getattr(block, 'use_multiview_attention', False):
assert block.attn_multiview is not None, 'attn_multiview not initialized' Type guard
def block_has_multiview_attn(block) -> bool:
return getattr(block, 'use_multiview_attention', False) and block.attn_multiview is not None Try / catch
try:
out = block(x, cross_attention_kwargs=opts)
except RuntimeError as e:
if 'Multiview attention was not initialized' in str(e) and int(opts.get('num_in_batch', 1)) == 1:
out = block(x, cross_attention_kwargs=opts)
else:
raise Prevention
- Match use_multiview_attention to your num_in_batch at build time
- Verify all blocks were replaced by checking a sample block's attrs
When it happens
Trigger: Calling the paint block forward with num_in_batch > 1 and use_multiview_attention=True on a block whose attn_multiview is None (built with multiview attention disabled or not replaced).
Common situations: Generating multiview images with a model whose blocks were replaced with use_multiview_attention=False; using a single-view checkpoint/pipeline path for a multiview request.
Related errors
- Reference attention was not initialized.
- Hunyuan3D Paint expects square latents and a matching view c
- encoder_hidden_states is required when encoder_key_value is
- Didn't get guidance strength for guidance distilled model.
- Hunyuan3D reference attention requires a shared cache.
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/5e49eccf0118d7d9.
Report an issue: GitHub.