From 138da14cc3437deb94cc0b8ce4a2d81a973d5a6b Mon Sep 17 00:00:00 2001 From: stduhpf Date: Mon, 8 Jun 2026 15:56:15 +0200 Subject: [PATCH] apg: normalize diff_norm calculation by tensor size (#1620) --- src/runtime/guidance.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/runtime/guidance.cpp b/src/runtime/guidance.cpp index f945c3cd..a83680cd 100644 --- a/src/runtime/guidance.cpp +++ b/src/runtime/guidance.cpp @@ -173,8 +173,9 @@ namespace sd::guidance { } float diff_norm = 0.0f; + const int standard_res = 2 * 1024 / 8; // Use SDXL as the standard resolution (1024x1024, 8x8 patches, 4=2x2 channels) if (params_.norm_threshold > 0.0f) { - diff_norm = std::sqrt((deltas * deltas).sum()); + diff_norm = std::sqrt((deltas * deltas).sum()) * standard_res / std::sqrt(static_cast(deltas.numel())); } float apg_scale_factor = 1.0f;