Skip to content

refactor: apg: normalize diff_norm calculation by tensor size#1620

Merged
leejet merged 1 commit into
leejet:masterfrom
stduhpf:apg
Jun 8, 2026
Merged

refactor: apg: normalize diff_norm calculation by tensor size#1620
leejet merged 1 commit into
leejet:masterfrom
stduhpf:apg

Conversation

@stduhpf

@stduhpf stduhpf commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Summary

I've noticed a small flaw in the APG paper (that was implemented in #593).

The norm threshold for the APG update uses the L2 norm of the whole latent image diff, but since this norm scales with the square root of the size, the effect of the norm threshold will depend on the image resolution and number of latent channels.

This PR re-normalizes the L2 norm so the effect of the norm_threshold always match the effect it would have on a standard SDXL 1024x1024 generation.

Related Issue / Discussion

N/A

Additional Information

Technically, this is no longer a proper implementation of the original APG paper, but it is an overall improvement.

It's also technically a breaking change, the effect of apg_norm_threshold is changed, except in the specific case of images that have exactly 128x128x4 elements in their latent representations.

Checklist

@stduhpf stduhpf changed the title apg: normalize diff_norm calculation by tensor size refactor: apg: normalize diff_norm calculation by tensor size Jun 7, 2026
@leejet leejet merged commit 138da14 into leejet:master Jun 8, 2026
15 checks passed
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.

2 participants