Skip to content

Commit a62b6c0

Browse files
committed
CUDNN Disable module for SM Inference to fix CUDNN error with ComfyUI-Zluda
1 parent c6432fe commit a62b6c0

13 files changed

Lines changed: 44 additions & 227 deletions

File tree

-p:PublishSingleFile=true

Whitespace-only changes.

.DS_Store

12 KB
Binary file not shown.

StabilityMatrix.Avalonia/.DS_Store

10 KB
Binary file not shown.

StabilityMatrix.Avalonia/Controls/Inference/CfzCudnnToggleCard.axaml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,18 @@
1212
<Setter Property="Template">
1313
<ControlTemplate>
1414
<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"
15+
<StackPanel Spacing="8">
16+
<TextBlock Text="Enable CUDNN" FontSize="14" FontWeight="Bold" />
17+
<ToggleSwitch
2318
IsChecked="{Binding EnableCudnn}"
24-
ToolTip.Tip="Enable or disable CUDA Deep Neural Network library acceleration" />
19+
Margin="8,0,4,0"
20+
HorizontalAlignment="Stretch" />
2521

26-
<CheckBox
27-
Content="CUDNN Benchmark"
22+
<TextBlock Text="CUDNN Benchmark" FontSize="14" FontWeight="Bold" />
23+
<ToggleSwitch
2824
IsChecked="{Binding CudnnBenchmark}"
29-
ToolTip.Tip="Enable CUDNN benchmark mode for potential performance improvements" />
25+
Margin="8,0,4,0"
26+
HorizontalAlignment="Stretch" />
3027
</StackPanel>
3128
</controls:Card>
3229
</ControlTemplate>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using Injectio.Attributes;
2+
13
namespace StabilityMatrix.Avalonia.Controls;
24

5+
[RegisterTransient<CfzCudnnToggleCard>]
36
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-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1312
<EnableWindowsTargeting>true</EnableWindowsTargeting>
13+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1414
</PropertyGroup>
1515

1616
<PropertyGroup Condition=" '$(RuntimeIdentifier)' == 'win-x64' ">

StabilityMatrix.Avalonia/ViewModels/Base/LoadableViewModelBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace StabilityMatrix.Avalonia.ViewModels.Base;
2626
[JsonDerivedType(typeof(RescaleCfgCardViewModel), RescaleCfgCardViewModel.ModuleKey)]
2727
[JsonDerivedType(typeof(PlasmaNoiseCardViewModel), PlasmaNoiseCardViewModel.ModuleKey)]
2828
[JsonDerivedType(typeof(NrsCardViewModel), NrsCardViewModel.ModuleKey)]
29+
[JsonDerivedType(typeof(CfzCudnnToggleCardViewModel), CfzCudnnToggleCardViewModel.ModuleKey)]
2930
[JsonDerivedType(typeof(FreeUModule))]
3031
[JsonDerivedType(typeof(HiresFixModule))]
3132
[JsonDerivedType(typeof(FluxHiresFixModule))]
@@ -41,6 +42,7 @@ namespace StabilityMatrix.Avalonia.ViewModels.Base;
4142
[JsonDerivedType(typeof(RescaleCfgModule))]
4243
[JsonDerivedType(typeof(PlasmaNoiseModule))]
4344
[JsonDerivedType(typeof(NRSModule))]
45+
[JsonDerivedType(typeof(CfzCudnnToggleModule))]
4446
public abstract class LoadableViewModelBase : ViewModelBase, IJsonLoadableState
4547
{
4648
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

StabilityMatrix.Avalonia/ViewModels/Inference/InferenceFluxTextToImageViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ RunningPackageService runningPackageService
9595
{
9696
typeof(FluxHiresFixModule),
9797
typeof(UpscalerModule),
98+
typeof(CfzCudnnToggleModule),
9899
typeof(SaveImageModule),
99100
typeof(FaceDetailerModule),
100-
typeof(CfzCudnnToggleModule),
101101
};
102102
modulesCard.DefaultModules = new[] { typeof(FluxHiresFixModule), typeof(UpscalerModule) };
103103
modulesCard.InitializeDefaults();

StabilityMatrix.Avalonia/ViewModels/Inference/InferenceTextToImageViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ TabContext tabContext
102102
{
103103
typeof(HiresFixModule),
104104
typeof(UpscalerModule),
105+
typeof(CfzCudnnToggleModule),
105106
typeof(SaveImageModule),
106107
typeof(FaceDetailerModule),
107-
typeof(CfzCudnnToggleModule),
108108
};
109109
modulesCard.DefaultModules = new[] { typeof(HiresFixModule), typeof(UpscalerModule) };
110110
modulesCard.InitializeDefaults();

StabilityMatrix.Avalonia/ViewModels/Inference/Modules/CfzCudnnToggleModule.cs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using StabilityMatrix.Avalonia.Models.Inference;
44
using StabilityMatrix.Avalonia.Services;
55
using StabilityMatrix.Avalonia.ViewModels.Base;
6+
using StabilityMatrix.Avalonia.ViewModels.Inference;
67
using StabilityMatrix.Core.Attributes;
78
using StabilityMatrix.Core.Models.Api.Comfy.Nodes;
89
using StabilityMatrix.Core.Models.Api.Comfy.NodeTypes;
@@ -18,43 +19,43 @@ public class CfzCudnnToggleModule : ModuleBase
1819
public CfzCudnnToggleModule(IServiceManager<ViewModelBase> vmFactory)
1920
: base(vmFactory)
2021
{
21-
Title = "CFZ CUDNN Toggle";
22-
AddCards(vmFactory.Get<CfzCudnnToggleCardViewModel>());
22+
Title = "Disable CUDNN (ComfyUI-Zluda)";
2323
}
2424

2525
/// <summary>
26-
/// Applies CUDNN Toggle to the Model and Conditioning connections
26+
/// Applies CUDNN Toggle node between sampler latent output and VAE decode
27+
/// This prevents "GET was unable to find an engine" errors on AMD cards with Zluda
2728
/// </summary>
2829
protected override void OnApplyStep(ModuleApplyStepEventArgs e)
2930
{
30-
var card = GetCard<CfzCudnnToggleCardViewModel>();
31+
// Get the primary connection (can be latent or image)
32+
var primary = e.Builder.Connections.Primary;
33+
if (primary == null)
34+
{
35+
return; // No primary connection to process
36+
}
3137

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))
38+
// Check if primary is a latent (from sampler output)
39+
if (primary.IsT0) // T0 is LatentNodeConnection
3440
{
41+
var latentConnection = primary.AsT0;
42+
43+
// Insert CUDNN toggle node between sampler and VAE decode
3544
var cudnnToggleOutput = e.Nodes.AddTypedNode(
3645
new ComfyNodeBuilder.CUDNNToggleAutoPassthrough
3746
{
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,
47+
Name = e.Nodes.GetUniqueName("CUDNNToggle"),
48+
Model = null,
49+
Conditioning = null,
50+
Latent = latentConnection, // Pass through the latent from sampler
51+
enable_cudnn = false,
52+
cudnn_benchmark = false,
4453
}
4554
);
4655

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-
}
56+
// Update the primary connection to use the CUDNN toggle latent output (Output3)
57+
// This ensures VAE decode receives latent from CUDNN toggle instead of directly from sampler
58+
e.Builder.Connections.Primary = cudnnToggleOutput.Output3;
5859
}
5960
}
6061
}

0 commit comments

Comments
 (0)