Skip to content

Commit 138da14

Browse files
authored
apg: normalize diff_norm calculation by tensor size (leejet#1620)
1 parent 17a2b4a commit 138da14

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/runtime/guidance.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ namespace sd::guidance {
173173
}
174174

175175
float diff_norm = 0.0f;
176+
const int standard_res = 2 * 1024 / 8; // Use SDXL as the standard resolution (1024x1024, 8x8 patches, 4=2x2 channels)
176177
if (params_.norm_threshold > 0.0f) {
177-
diff_norm = std::sqrt((deltas * deltas).sum());
178+
diff_norm = std::sqrt((deltas * deltas).sum()) * standard_res / std::sqrt(static_cast<float>(deltas.numel()));
178179
}
179180

180181
float apg_scale_factor = 1.0f;

0 commit comments

Comments
 (0)