Skip to content

fix: add missing n_frames attribute in StandardDiffusionLoss#471

Open
Mr-Neutr0n wants to merge 1 commit intoStability-AI:mainfrom
Mr-Neutr0n:fix/standard-diffusion-loss-n-frames
Open

fix: add missing n_frames attribute in StandardDiffusionLoss#471
Mr-Neutr0n wants to merge 1 commit intoStability-AI:mainfrom
Mr-Neutr0n:fix/standard-diffusion-loss-n-frames

Conversation

@Mr-Neutr0n
Copy link

Summary

  • StandardDiffusionLoss._forward() references self.n_frames to determine the offset noise shape, but this attribute is never initialized in __init__(), causing an AttributeError when offset_noise_level > 0.0.
  • Added n_frames as an optional parameter to __init__() (defaulting to None) and assigned it to self.n_frames, preserving the existing behavior where None selects the 2D (image) offset noise shape.

Details

In sgm/modules/diffusionmodules/loss.py, the _forward method contains:

if self.offset_noise_level > 0.0:
    offset_shape = (
        (input.shape[0], 1, input.shape[2])
        if self.n_frames is not None
        else (input.shape[0], input.shape[1])
    )

self.n_frames is checked but never defined anywhere in the class, so any use of offset_noise_level > 0.0 raises:

AttributeError: 'StandardDiffusionLoss' object has no attribute 'n_frames'

This fix adds n_frames: Optional[int] = None to the constructor and stores it as self.n_frames. The default of None means existing configs and image-based training are unaffected, while video-based training can pass n_frames to get the correct 3D offset noise shape.

Test plan

  • Verified that existing configs (which do not pass n_frames) continue to work unchanged since the default is None
  • Confirmed the offset noise code path no longer raises AttributeError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant