Stability-AI/generative-models · error · NotImplementedError

NotImplementedError

Error message

NotImplementedError

What it means

The video-block attention-mask helper (get_alpha-like function in util.py) supports only specific image_only_indicator layouts: 'b t' when is_attn, else 'b t' rearranged for 5D spatial. Reaching the final else raises a bare NotImplementedError — the input shape does not match either expected layout.

Source

Thrown at sgm/modules/diffusionmodules/util.py:46

        alpha = mix_factor
    elif merge_strategy == "learned_with_images":
        alpha = torch.where(
            image_only_indicator.bool(),
            torch.ones(1, 1, device=image_only_indicator.device),
            rearrange(mix_factor, "... -> ... 1"),
        )
        if is_attn:
            alpha = rearrange(alpha, "b t -> (b t) 1 1")
        else:
            alpha = rearrange(alpha, "b t -> b 1 t 1 1")
    elif merge_strategy == "fixed_with_images":
        alpha = image_only_indicator
        if is_attn:
            alpha = rearrange(alpha, "b t -> (b t) 1 1")
        else:
            alpha = rearrange(alpha, "b t -> b 1 t 1 1")
    else:
        raise NotImplementedError
    return torch.sigmoid(alpha) if apply_sigmoid else alpha

    
def make_beta_schedule(
    schedule,
    n_timestep,
    linear_start=1e-4,
    linear_end=2e-2,
):
    if schedule == "linear":
        betas = (
            torch.linspace(
                linear_start**0.5, linear_end**0.5, n_timestep, dtype=torch.float64
            )
            ** 2
        )
    return betas.numpy()

View on GitHub (pinned to e8cd657656)

Solutions

  1. Pass image_only_indicator with shape (batch, num_frames) ('b t')
  2. Squeeze/reshape the mask to (b,t) before calling
  3. Add an explicit branch for your input layout if a spatial mask is genuinely needed

Example fix

// before
alpha = get_alpha(mask_4d, is_attn=True)  # mask_4d: (b,1,h,w)
// after
frame_flags = mask_4d.mean(dim=(1,2,3))  # (b,) -> then expand per frame as (b,t)
alpha = get_alpha(frame_flags.unsqueeze(-1).expand(-1, t), is_attn=True)
Defensive patterns

Strategy: validation

Validate before calling

def validate_frame_indicator(img_ind, is_attn):
    if img_ind.dim() != 2 or img_ind.shape[0] == 0:
        raise ValueError(f"image_only_indicator must be (b,t), got shape {tuple(img_ind.shape)}")
validate_frame_indicator(image_only_indicator, is_attn=True)

Type guard

def is_frame_indicator(t, num_frames=None) -> bool:
    return t.dim() == 2 and (num_frames is None or t.shape[1] == num_frames)

Try / catch

try:
    alpha = get_alpha(image_only_indicator, is_attn=is_attn)
except NotImplementedError as e:
    raise RuntimeError("image_only_indicator must be a (b,t) per-frame tensor, not a spatial mask") from e

Prevention

When it happens

Trigger: Calling the function with image_only_indicator whose shape is not (b,) or (b,t) — e.g. passing a per-pixel mask (b,1,h,w) or None — while apply_sigmoid handling expects the two supported cases.

Common situations: Wiring a spatial segmentation mask where a per-frame indicator is expected; passing wrong-shape conditioning tensors in video diffusion training.

Related errors


AI-assisted analysis of Stability-AI/generative-models@e8cd657656 (2026-08-29). Data as JSON: /api/errors/3333ee6c963682de. Report an issue: GitHub.