Skip to content

Commit c6432fe

Browse files
committed
Add CFZ CUDNN Toggle feature and fix build issues
1 parent c7ccc59 commit c6432fe

9 files changed

Lines changed: 329 additions & 8 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Styles xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:controls="using:StabilityMatrix.Avalonia.Controls"
4+
xmlns:mocks="clr-namespace:StabilityMatrix.Avalonia.DesignData"
5+
xmlns:vmInference="clr-namespace:StabilityMatrix.Avalonia.ViewModels.Inference"
6+
x:DataType="vmInference:CfzCudnnToggleCardViewModel">
7+
<Design.PreviewWith>
8+
<controls:CfzCudnnToggleCard Width="400" />
9+
</Design.PreviewWith>
10+
11+
<Style Selector="controls|CfzCudnnToggleCard">
12+
<Setter Property="Template">
13+
<ControlTemplate>
14+
<controls:Card x:Name="PART_Card">
15+
<StackPanel Spacing="8" Margin="8">
16+
<TextBlock
17+
Text="CUDNN Settings (ComfyUI-Zluda)"
18+
FontWeight="SemiBold"
19+
Margin="0,0,0,4" />
20+
21+
<CheckBox
22+
Content="Enable CUDNN"
23+
IsChecked="{Binding EnableCudnn}"
24+
ToolTip.Tip="Enable or disable CUDA Deep Neural Network library acceleration" />
25+
26+
<CheckBox
27+
Content="CUDNN Benchmark"
28+
IsChecked="{Binding CudnnBenchmark}"
29+
ToolTip.Tip="Enable CUDNN benchmark mode for potential performance improvements" />
30+
</StackPanel>
31+
</controls:Card>
32+
</ControlTemplate>
33+
</Setter>
34+
</Style>
35+
</Styles>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace StabilityMatrix.Avalonia.Controls;
2+
3+
public class CfzCudnnToggleCard : TemplatedControlBase;

StabilityMatrix.Avalonia/StabilityMatrix.Avalonia.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<ApplicationIcon>./Assets/Icon.ico</ApplicationIcon>
1010
<Version>2.16.0-dev.999</Version>
1111
<InformationalVersion>$(Version)</InformationalVersion>
12-
<EnableWindowsTargeting>true</EnableWindowsTargeting>
1312
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
13+
<EnableWindowsTargeting>true</EnableWindowsTargeting>
1414
</PropertyGroup>
1515

1616
<PropertyGroup Condition=" '$(RuntimeIdentifier)' == 'win-x64' ">
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using Injectio.Attributes;
3+
using StabilityMatrix.Avalonia.Controls;
4+
using StabilityMatrix.Avalonia.ViewModels.Base;
5+
using StabilityMatrix.Core.Attributes;
6+
7+
namespace StabilityMatrix.Avalonia.ViewModels.Inference;
8+
9+
[View(typeof(CfzCudnnToggleCard))]
10+
[ManagedService]
11+
[RegisterTransient<CfzCudnnToggleCardViewModel>]
12+
public partial class CfzCudnnToggleCardViewModel : LoadableViewModelBase
13+
{
14+
public const string ModuleKey = "CfzCudnnToggle";
15+
16+
[ObservableProperty]
17+
private bool enableCudnn = false;
18+
19+
[ObservableProperty]
20+
private bool cudnnBenchmark;
21+
}

StabilityMatrix.Avalonia/ViewModels/Inference/InferenceFluxTextToImageViewModel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ RunningPackageService runningPackageService
9696
typeof(FluxHiresFixModule),
9797
typeof(UpscalerModule),
9898
typeof(SaveImageModule),
99-
typeof(FaceDetailerModule)
99+
typeof(FaceDetailerModule),
100+
typeof(CfzCudnnToggleModule),
100101
};
101102
modulesCard.DefaultModules = new[] { typeof(FluxHiresFixModule), typeof(UpscalerModule) };
102103
modulesCard.InitializeDefaults();
@@ -121,7 +122,7 @@ protected override void BuildPrompt(BuildPromptEventArgs args)
121122
builder.Connections.Seed = args.SeedOverride switch
122123
{
123124
{ } seed => Convert.ToUInt64(seed),
124-
_ => Convert.ToUInt64(SeedCardViewModel.Seed)
125+
_ => Convert.ToUInt64(SeedCardViewModel.Seed),
125126
};
126127

127128
var applyArgs = args.ToModuleApplyStepEventArgs();
@@ -217,7 +218,7 @@ CancellationToken cancellationToken
217218
FilesToTransfer = buildPromptArgs.FilesToTransfer,
218219
BatchIndex = i,
219220
// Only clear output images on the first batch
220-
ClearOutputImages = i == 0
221+
ClearOutputImages = i == 0,
221222
};
222223

223224
batchArgs.Add(generationArgs);

StabilityMatrix.Avalonia/ViewModels/Inference/InferenceTextToImageViewModel.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ TabContext tabContext
103103
typeof(HiresFixModule),
104104
typeof(UpscalerModule),
105105
typeof(SaveImageModule),
106-
typeof(FaceDetailerModule)
106+
typeof(FaceDetailerModule),
107+
typeof(CfzCudnnToggleModule),
107108
};
108109
modulesCard.DefaultModules = new[] { typeof(HiresFixModule), typeof(UpscalerModule) };
109110
modulesCard.InitializeDefaults();
@@ -158,7 +159,7 @@ protected override void BuildPrompt(BuildPromptEventArgs args)
158159
builder.Connections.Seed = args.SeedOverride switch
159160
{
160161
{ } seed => Convert.ToUInt64(seed),
161-
_ => Convert.ToUInt64(SeedCardViewModel.Seed)
162+
_ => Convert.ToUInt64(SeedCardViewModel.Seed),
162163
};
163164

164165
var applyArgs = args.ToModuleApplyStepEventArgs();
@@ -319,13 +320,13 @@ CancellationToken cancellationToken
319320
OutputNodeNames = buildPromptArgs.Builder.Connections.OutputNodeNames.ToArray(),
320321
Parameters = SaveStateToParameters(new GenerationParameters()) with
321322
{
322-
Seed = Convert.ToUInt64(seed)
323+
Seed = Convert.ToUInt64(seed),
323324
},
324325
Project = inferenceProject,
325326
FilesToTransfer = buildPromptArgs.FilesToTransfer,
326327
BatchIndex = i,
327328
// Only clear output images on the first batch
328-
ClearOutputImages = i == 0
329+
ClearOutputImages = i == 0,
329330
};
330331

331332
batchArgs.Add(generationArgs);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.Linq;
2+
using Injectio.Attributes;
3+
using StabilityMatrix.Avalonia.Models.Inference;
4+
using StabilityMatrix.Avalonia.Services;
5+
using StabilityMatrix.Avalonia.ViewModels.Base;
6+
using StabilityMatrix.Core.Attributes;
7+
using StabilityMatrix.Core.Models.Api.Comfy.Nodes;
8+
using StabilityMatrix.Core.Models.Api.Comfy.NodeTypes;
9+
using StabilityMatrix.Core.Models.Inference;
10+
11+
namespace StabilityMatrix.Avalonia.ViewModels.Inference.Modules;
12+
13+
[ManagedService]
14+
[RegisterTransient<CfzCudnnToggleModule>]
15+
public class CfzCudnnToggleModule : ModuleBase
16+
{
17+
/// <inheritdoc />
18+
public CfzCudnnToggleModule(IServiceManager<ViewModelBase> vmFactory)
19+
: base(vmFactory)
20+
{
21+
Title = "CFZ CUDNN Toggle";
22+
AddCards(vmFactory.Get<CfzCudnnToggleCardViewModel>());
23+
}
24+
25+
/// <summary>
26+
/// Applies CUDNN Toggle to the Model and Conditioning connections
27+
/// </summary>
28+
protected override void OnApplyStep(ModuleApplyStepEventArgs e)
29+
{
30+
var card = GetCard<CfzCudnnToggleCardViewModel>();
31+
32+
// Apply to all models in the pipeline
33+
foreach (var modelConnections in e.Builder.Connections.Models.Values.Where(m => m.Model is not null))
34+
{
35+
var cudnnToggleOutput = e.Nodes.AddTypedNode(
36+
new ComfyNodeBuilder.CUDNNToggleAutoPassthrough
37+
{
38+
Name = e.Nodes.GetUniqueName($"CUDNNToggle_{modelConnections.Name}"),
39+
Model = modelConnections.Model,
40+
Conditioning = modelConnections.Conditioning?.Positive,
41+
Latent = null, // Optional, we're not using latent passthrough here
42+
EnableCudnn = card.EnableCudnn,
43+
CudnnBenchmark = card.CudnnBenchmark,
44+
}
45+
);
46+
47+
// Update the model connection with the output from CUDNN toggle
48+
modelConnections.Model = cudnnToggleOutput.Output1;
49+
50+
// Update conditioning if it was provided
51+
if (modelConnections.Conditioning is not null)
52+
{
53+
modelConnections.Conditioning = new ConditioningConnections(
54+
cudnnToggleOutput.Output2,
55+
modelConnections.Conditioning.Negative
56+
);
57+
}
58+
}
59+
}
60+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,23 @@ public record BrownNoise : ComfyTypedNodeBase<ImageNodeConnection>
997997
public required ulong Seed { get; init; } = 0;
998998
}
999999

1000+
/// <summary>
1001+
/// CUDNN Toggle node for controlling CUDA Deep Neural Network library settings (CUDNNToggleAutoPassthrough)
1002+
/// </summary>
1003+
[TypedNodeOptions(
1004+
Name = "CUDNNToggleAutoPassthrough",
1005+
RequiredExtensions = ["https://github.com/patientx/ComfyUI-Zluda"]
1006+
)]
1007+
public record CUDNNToggleAutoPassthrough
1008+
: ComfyTypedNodeBase<ModelNodeConnection, ConditioningNodeConnection, LatentNodeConnection>
1009+
{
1010+
public ModelNodeConnection? Model { get; init; }
1011+
public ConditioningNodeConnection? Conditioning { get; init; }
1012+
public LatentNodeConnection? Latent { get; init; }
1013+
public required bool EnableCudnn { get; init; } = false;
1014+
public required bool CudnnBenchmark { get; init; } = false;
1015+
}
1016+
10001017
/// <summary>
10011018
/// Custom KSampler node using alternative noise distribution (Lykos_JDC_PlasmaSampler)
10021019
/// </summary>

0 commit comments

Comments
 (0)