Skip to content

Commit 05a418d

Browse files
committed
Implementation of Tiled VAE Decode in Wan inference workflows and UI via addons for sampler
1 parent 895b247 commit 05a418d

4 files changed

Lines changed: 44 additions & 23 deletions

File tree

StabilityMatrix.Avalonia/ViewModels/Inference/InferenceWanImageToVideoViewModel.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@ RunningPackageService runningPackageService
3939
/// <inheritdoc />
4040
protected override void BuildPrompt(BuildPromptEventArgs args)
4141
{
42+
var applyArgs = args.ToModuleApplyStepEventArgs();
4243
var builder = args.Builder;
4344

4445
builder.Connections.Seed = args.SeedOverride switch
4546
{
4647
{ } seed => Convert.ToUInt64(seed),
47-
_ => Convert.ToUInt64(SeedCardViewModel.Seed)
48+
_ => Convert.ToUInt64(SeedCardViewModel.Seed),
4849
};
4950

5051
// Load models
51-
ModelCardViewModel.ApplyStep(args);
52+
ModelCardViewModel.ApplyStep(applyArgs);
5253

5354
// Setup latent from image
5455
var imageLoad = builder.Nodes.AddTypedNode(
@@ -57,22 +58,24 @@ protected override void BuildPrompt(BuildPromptEventArgs args)
5758
Name = builder.Nodes.GetUniqueName("ControlNet_LoadImage"),
5859
Image =
5960
SelectImageCardViewModel.ImageSource?.GetHashGuidFileNameCached("Inference")
60-
?? throw new ValidationException()
61+
?? throw new ValidationException(),
6162
}
6263
);
6364
builder.Connections.Primary = imageLoad.Output1;
6465
builder.Connections.PrimarySize = SelectImageCardViewModel.CurrentBitmapSize;
6566

66-
BatchSizeCardViewModel.ApplyStep(args);
67+
BatchSizeCardViewModel.ApplyStep(applyArgs);
6768

68-
SelectImageCardViewModel.ApplyStep(args);
69+
SelectImageCardViewModel.ApplyStep(applyArgs);
6970

70-
PromptCardViewModel.ApplyStep(args);
71+
PromptCardViewModel.ApplyStep(applyArgs);
7172

72-
SamplerCardViewModel.ApplyStep(args);
73+
SamplerCardViewModel.ApplyStep(applyArgs);
74+
75+
applyArgs.InvokeAllPreOutputActions();
7376

7477
// Animated webp output
75-
VideoOutputSettingsCardViewModel.ApplyStep(args);
78+
VideoOutputSettingsCardViewModel.ApplyStep(applyArgs);
7679
}
7780

7881
/// <inheritdoc />

StabilityMatrix.Avalonia/ViewModels/Inference/InferenceWanTextToVideoViewModel.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ RunningPackageService runningPackageService
5959
samplerCard.IsSamplerSelectionEnabled = true;
6060
samplerCard.IsSchedulerSelectionEnabled = true;
6161
samplerCard.DenoiseStrength = 1.0d;
62-
samplerCard.EnableAddons = false;
62+
samplerCard.EnableAddons = true;
6363
samplerCard.IsLengthEnabled = true;
6464
samplerCard.Width = 832;
6565
samplerCard.Height = 480;
@@ -70,8 +70,8 @@ RunningPackageService runningPackageService
7070

7171
BatchSizeCardViewModel = vmFactory.Get<BatchSizeCardViewModel>();
7272

73-
VideoOutputSettingsCardViewModel = vmFactory.Get<VideoOutputSettingsCardViewModel>(
74-
vm => vm.Fps = 16.0d
73+
VideoOutputSettingsCardViewModel = vmFactory.Get<VideoOutputSettingsCardViewModel>(vm =>
74+
vm.Fps = 16.0d
7575
);
7676

7777
StackCardViewModel = vmFactory.Get<StackCardViewModel>();
@@ -89,16 +89,17 @@ protected override void BuildPrompt(BuildPromptEventArgs args)
8989
{
9090
base.BuildPrompt(args);
9191

92+
var applyArgs = args.ToModuleApplyStepEventArgs();
9293
var builder = args.Builder;
9394

9495
builder.Connections.Seed = args.SeedOverride switch
9596
{
9697
{ } seed => Convert.ToUInt64(seed),
97-
_ => Convert.ToUInt64(SeedCardViewModel.Seed)
98+
_ => Convert.ToUInt64(SeedCardViewModel.Seed),
9899
};
99100

100101
// Load models
101-
ModelCardViewModel.ApplyStep(args);
102+
ModelCardViewModel.ApplyStep(applyArgs);
102103

103104
builder.SetupEmptyLatentSource(
104105
SamplerCardViewModel.Width,
@@ -109,14 +110,16 @@ protected override void BuildPrompt(BuildPromptEventArgs args)
109110
LatentType.Hunyuan
110111
);
111112

112-
BatchSizeCardViewModel.ApplyStep(args);
113+
BatchSizeCardViewModel.ApplyStep(applyArgs);
113114

114-
PromptCardViewModel.ApplyStep(args);
115+
PromptCardViewModel.ApplyStep(applyArgs);
115116

116-
SamplerCardViewModel.ApplyStep(args);
117+
SamplerCardViewModel.ApplyStep(applyArgs);
118+
119+
applyArgs.InvokeAllPreOutputActions();
117120

118121
// Animated webp output
119-
VideoOutputSettingsCardViewModel.ApplyStep(args);
122+
VideoOutputSettingsCardViewModel.ApplyStep(applyArgs);
120123
}
121124

122125
/// <inheritdoc />
@@ -165,13 +168,13 @@ CancellationToken cancellationToken
165168
OutputNodeNames = buildPromptArgs.Builder.Connections.OutputNodeNames.ToArray(),
166169
Parameters = SaveStateToParameters(new GenerationParameters()) with
167170
{
168-
Seed = Convert.ToUInt64(seed)
171+
Seed = Convert.ToUInt64(seed),
169172
},
170173
Project = inferenceProject,
171174
FilesToTransfer = buildPromptArgs.FilesToTransfer,
172175
BatchIndex = i,
173176
// Only clear output images on the first batch
174-
ClearOutputImages = i == 0
177+
ClearOutputImages = i == 0,
175178
};
176179

177180
batchArgs.Add(generationArgs);

StabilityMatrix.Avalonia/ViewModels/Inference/WanSamplerCardViewModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System.ComponentModel.DataAnnotations;
2+
using System.Linq;
23
using Injectio.Attributes;
34
using StabilityMatrix.Avalonia.Controls;
45
using StabilityMatrix.Avalonia.Models.Inference;
56
using StabilityMatrix.Avalonia.Services;
67
using StabilityMatrix.Avalonia.ViewModels.Base;
8+
using StabilityMatrix.Avalonia.ViewModels.Inference.Modules;
79
using StabilityMatrix.Core.Attributes;
810
using StabilityMatrix.Core.Extensions;
911
using StabilityMatrix.Core.Models.Api.Comfy;
@@ -34,6 +36,14 @@ TabContext tabContext
3436

3537
public override void ApplyStep(ModuleApplyStepEventArgs e)
3638
{
39+
if (EnableAddons)
40+
{
41+
foreach (var module in ModulesCardViewModel.Cards.OfType<ModuleBase>())
42+
{
43+
module.ApplyStep(e);
44+
}
45+
}
46+
3747
// Set primary sampler and scheduler
3848
var primarySampler = SelectedSampler ?? throw new ValidationException("Sampler not selected");
3949
e.Builder.Connections.PrimarySampler = primarySampler;

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.ComponentModel.DataAnnotations;
33
using System.Diagnostics.CodeAnalysis;
44
using System.Drawing;
5+
using System.Text.Json.Serialization;
56
using OneOf;
67
using StabilityMatrix.Core.Attributes;
78
using StabilityMatrix.Core.Extensions;
@@ -67,17 +68,21 @@ public record TiledVAEDecode : ComfyTypedNodeBase<ImageNodeConnection>
6768
{
6869
public required LatentNodeConnection Samples { get; init; }
6970
public required VAENodeConnection Vae { get; init; }
70-
71+
7172
[Range(64, 4096)]
73+
[JsonPropertyName("tile_size")]
7274
public int TileSize { get; init; } = 512;
73-
75+
7476
[Range(0, 4096)]
77+
[JsonPropertyName("overlap")]
7578
public int Overlap { get; init; } = 64;
76-
79+
7780
[Range(8, 4096)]
81+
[JsonPropertyName("temporal_size")]
7882
public int TemporalSize { get; init; } = 64;
79-
83+
8084
[Range(4, 4096)]
85+
[JsonPropertyName("temporal_overlap")]
8186
public int TemporalOverlap { get; init; } = 8;
8287
}
8388

0 commit comments

Comments
 (0)