Skip to content

Commit 8be563d

Browse files
committed
Add TiledVAEDecode backend integration (ComfyNodeBuilder + ComfyClient)
1 parent 0d69da1 commit 8be563d

4 files changed

Lines changed: 86 additions & 40 deletions

File tree

StabilityMatrix.Core/Inference/ComfyClient.cs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -326,22 +326,49 @@ public override async Task CloseAsync(CancellationToken cancellationToken = defa
326326
await webSocketClient.Stop(WebSocketCloseStatus.NormalClosure, string.Empty).ConfigureAwait(false);
327327
}
328328

329-
public async Task<ComfyTask> QueuePromptAsync(
330-
Dictionary<string, ComfyNode> nodes,
331-
CancellationToken cancellationToken = default
332-
)
329+
public async Task<ComfyTask> QueuePromptAsync(
330+
Dictionary<string, ComfyNode> nodes,
331+
CancellationToken cancellationToken = default
332+
)
333+
{
334+
var request = new ComfyPromptRequest { ClientId = ClientId, Prompt = nodes };
335+
336+
// DEBUG: dump final workflow JSON
337+
try
333338
{
334-
var request = new ComfyPromptRequest { ClientId = ClientId, Prompt = nodes };
335-
var result = await comfyApi.PostPrompt(request, cancellationToken).ConfigureAwait(false);
339+
var json = JsonSerializer.Serialize(request, jsonSerializerOptions);
336340

337-
// Add task to dictionary and set it as the current task
338-
var task = new ComfyTask(result.PromptId);
339-
PromptTasks.TryAdd(result.PromptId, task);
340-
currentPromptTask = task;
341+
var debugDir = Path.Combine(
342+
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
343+
"StabilityMatrix",
344+
"Debug"
345+
);
346+
347+
Directory.CreateDirectory(debugDir);
348+
349+
var path = Path.Combine(
350+
debugDir,
351+
$"wan_workflow_debug_request.json"
352+
);
341353

342-
return task;
354+
File.WriteAllText(path, json);
355+
356+
Logger.Warn("WAN DEBUG: Dumped final request JSON to {0}", path);
357+
}
358+
catch (Exception ex)
359+
{
360+
Logger.Error(ex, "WAN DEBUG: Failed to dump final request JSON");
343361
}
344362

363+
var result = await comfyApi.PostPrompt(request, cancellationToken).ConfigureAwait(false);
364+
365+
var task = new ComfyTask(result.PromptId);
366+
PromptTasks.TryAdd(result.PromptId, task);
367+
currentPromptTask = task;
368+
369+
return task;
370+
}
371+
345372
public async Task InterruptPromptAsync(CancellationToken cancellationToken = default)
346373
{
347374
await comfyApi.PostInterrupt(cancellationToken).ConfigureAwait(false);

StabilityMatrix.Core/Models/Api/Comfy/Nodes/ComfyNodeBuilder.cs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.ComponentModel;
1+
using System.ComponentModel;
22
using System.ComponentModel.DataAnnotations;
33
using System.Diagnostics.CodeAnalysis;
44
using System.Drawing;
@@ -1097,7 +1097,34 @@ public record NRS : ComfyTypedNodeBase<ModelNodeConnection>
10971097
public required double Squash { get; set; }
10981098
}
10991099

1100-
public ImageNodeConnection Lambda_LatentToImage(LatentNodeConnection latent, VAENodeConnection vae)
1100+
public ImageNodeConnection Lambda_LatentToImage(
1101+
LatentNodeConnection latent,
1102+
VAENodeConnection vae,
1103+
bool useTiledVAE = false,
1104+
int tileSize = 512,
1105+
int overlap = 64,
1106+
int temporalSize = 64,
1107+
int temporalOverlap = 8)
1108+
{
1109+
if (useTiledVAE)
1110+
{
1111+
var name = GetUniqueName("VAEDecodeTiled");
1112+
return Nodes
1113+
.AddTypedNode(
1114+
new TiledVAEDecode
1115+
{
1116+
Name = name,
1117+
Samples = latent,
1118+
Vae = vae,
1119+
TileSize = tileSize,
1120+
Overlap = overlap,
1121+
TemporalSize = temporalSize,
1122+
TemporalOverlap = temporalOverlap
1123+
}
1124+
)
1125+
.Output;
1126+
}
1127+
else
11011128
{
11021129
var name = GetUniqueName("VAEDecode");
11031130
return Nodes
@@ -1111,6 +1138,7 @@ public ImageNodeConnection Lambda_LatentToImage(LatentNodeConnection latent, VAE
11111138
)
11121139
.Output;
11131140
}
1141+
}
11141142

11151143
public LatentNodeConnection Lambda_ImageToLatent(ImageNodeConnection pixels, VAENodeConnection vae)
11161144
{
@@ -1519,11 +1547,28 @@ public ImageNodeConnection GetPrimaryAsImage()
15191547
/// <summary>
15201548
/// Get or convert latest primary connection to image
15211549
/// </summary>
1550+
<<<<<<< HEAD
15221551
public ImageNodeConnection GetPrimaryAsImage(PrimaryNodeConnection primary, VAENodeConnection vae)
15231552
{
15241553
return primary.Match(latent => Lambda_LatentToImage(latent, vae), image => image);
15251554
}
15261555

1556+
=======
1557+
public ImageNodeConnection GetPrimaryAsImage(
1558+
PrimaryNodeConnection primary,
1559+
VAENodeConnection vae,
1560+
bool useTiledVAE = false,
1561+
int tileSize = 512,
1562+
int overlap = 64,
1563+
int temporalSize = 64,
1564+
int temporalOverlap = 8)
1565+
{
1566+
return primary.Match(
1567+
latent => Lambda_LatentToImage(latent, vae, useTiledVAE, tileSize, overlap, temporalSize, temporalOverlap),
1568+
image => image
1569+
);
1570+
}
1571+
>>>>>>> 27accf16 (Update ComfyNodeBuilder.cs)
15271572
/// <summary>
15281573
/// Get or convert latest primary connection to image
15291574
/// </summary>
@@ -1640,4 +1685,4 @@ public VAENodeConnection GetDefaultVAE()
16401685
}
16411686

16421687
public NodeBuilderConnections Connections { get; } = new();
1643-
}
1688+
}

StabilityMatrix.Core/Models/Api/Comfy/Nodes/TiledVAEDecodeVideoNode.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

StabilityMatrix.Core/Settings/Inference/WanSettings.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)