Skip to content

apg update#9

Open
wbruna wants to merge 19 commits intostduhpf:nucleusfrom
wbruna:sd_apg_update_202604
Open

apg update#9
wbruna wants to merge 19 commits intostduhpf:nucleusfrom
wbruna:sd_apg_update_202604

Conversation

@wbruna
Copy link
Copy Markdown

@wbruna wbruna commented Apr 23, 2026

@stduhpf , here is my last attempt to update the APG branch.

The original branch became very hard to merge: it would have to cross the src/ rename, the Tensor changes, and the result would be "merge"in name only.... So I ported it by LLM-assisted hand to the new interfaces, reimplemented the command line, and added server API support. I've also replaced the env var with a debug log line, to avoid that specific barrier to merging.

I chose a somewhat random base branch to send it to you just because it was less distant from upstream than the others on your repo.

At least plain text-to-image with an LCM model seems to work. I noticed something that looks like a bug on this chunk (original diff):

Details
@@ -1322,18 +1414,18 @@ public:
                 float latent_result = positive_data[i];
                 if (has_unconditioned) {
                     // out_uncond + cfg_scale * (out_cond - out_uncond)
-                    if (has_img_cond) {
-                        // out_uncond + text_cfg_scale * (out_cond - out_img_cond) + image_cfg_scale * (out_img_cond - out_uncond)
-                        latent_result = negative_data[i] + img_cfg_scale * (img_cond_data[i] - negative_data[i]) + cfg_scale * (positive_data[i] - img_cond_data[i]);
-                    } else {
-                        // img_cfg_scale == cfg_scale
-                        latent_result = negative_data[i] + cfg_scale * (positive_data[i] - negative_data[i]);
+                    float delta = deltas[i];
+
+                    if (cfg_scale != 1) {
+                        latent_result = positive_data[i] + (cfg_scale - 1) * delta;
+                    } else if (has_img_cond) {
+                        latent_result = positive_data[i] + (img_cfg_scale - 1) * delta;
                     }
                 } else if (has_img_cond) {
                     // img_cfg_scale == 1
                     latent_result = img_cond_data[i] + cfg_scale * (positive_data[i] - img_cond_data[i]);
                 }
-                if (is_skiplayer_step) {
+                if (is_skiplayer_step && slg_scale != 0.0) {
                     latent_result = latent_result + (positive_data[i] - skip_layer_data[i]) * slg_scale;
                 }
                 // v = latent_result, eps = latent_result

The line latent_result = img_cond_data[i] + cfg_scale * (positive_data[i] - img_cond_data[i]); should be latent_result = img_cond_data[i] + cfg_scale * delta;?

And a few LLM reviewers suggested other changes that could be reasonable; I've kept them in a separate commit.

If you still want to move this forward (and I'd understand if you didn't...), I'd suggest just starting over the branch like this. And feel free to take ownership if you wish; I did add you as co-author, but you did most of the hard work.

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.

5 participants